update to godot v4

This commit is contained in:
Fabien Freling 2024-09-02 13:26:07 +02:00
parent 371af850ae
commit 18b8ba71f8
9 changed files with 86 additions and 95 deletions

View file

@ -2,7 +2,7 @@ extends Node2D
const CardValue = preload("res://CardValue.gd")
onready var cards = [
@onready var cards = [
CardValue.new(Enums.Month.JANUARY, Enums.Type.LIGHT),
CardValue.new(Enums.Month.JANUARY, Enums.Type.RIBBON),
CardValue.new(Enums.Month.JANUARY, Enums.Type.SCRAP_1),

View file

@ -1,16 +1,16 @@
tool
@tool
class_name HanafudaCard
extends Node2D
const CardValue = preload("res://CardValue.gd")
export var revealed: bool = true setget reveal
export(Enums.Month) var month: int setget _set_card_month
export(Enums.Type) var type: int setget _set_card_type
@export var revealed: bool = true: set = reveal
@export var month: int: set = _set_card_month
@export var type: int: set = _set_card_type
var value: CardValue = CardValue.new(Enums.Month.JANUARY, Enums.Type.LIGHT)
onready var _is_ready := true
@onready var _is_ready := true
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
@ -55,7 +55,7 @@ func reveal(new_reveal: bool) -> void:
revealed = new_reveal
if not _is_ready:
yield(self, "ready")
await self.ready
if revealed:
$Frontside.show()
@ -72,7 +72,7 @@ func _set_card_type(new_type: int) -> void:
func set_size(new_size: Vector2) -> void:
if not _is_ready:
yield(self, "ready")
await self.ready
var texture_size = $Frontside.texture.get_size()
var scale = new_size / texture_size
@ -80,7 +80,7 @@ func set_size(new_size: Vector2) -> void:
func set_min_dimension(dim: int) -> void:
if not _is_ready:
yield(self, "ready")
await self.ready
var texture_size = $Frontside.texture.get_size()
var scale = Vector2(dim, dim) / texture_size
@ -89,7 +89,7 @@ func set_min_dimension(dim: int) -> void:
func set_max_dimension(dim: int) -> void:
if not _is_ready:
yield(self, "ready")
await self.ready
var texture_size = $Frontside.texture.get_size()
var scale = Vector2(dim, dim) / texture_size
@ -98,7 +98,7 @@ func set_max_dimension(dim: int) -> void:
func get_size() -> Vector2:
if not _is_ready:
yield(self, "ready")
await self.ready
var texture_size = $Frontside.texture.get_size()
return texture_size * self.scale

View file

@ -1,30 +1,30 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://HanafudaCard.gd" type="Script" id=1]
[ext_resource path="res://assets/png/Hanafuda_January_Hikari.png" type="Texture" id=2]
[ext_resource path="res://assets/png/Hanafuda_border.png" type="Texture" id=3]
[ext_resource path="res://assets/japanese_pattern_01.png" type="Texture" id=4]
[ext_resource path="res://assets/png/Hanafuda_January_Hikari.png" type="Texture2D" id=2]
[ext_resource path="res://assets/png/Hanafuda_border.png" type="Texture2D" id=3]
[ext_resource path="res://assets/japanese_pattern_01.png" type="Texture2D" id=4]
[node name="HanafudaCard" type="Node2D"]
script = ExtResource( 1 )
[node name="Frontside" type="Sprite" parent="."]
[node name="Frontside" type="Sprite2D" parent="."]
texture = ExtResource( 2 )
[node name="Backside" type="Node2D" parent="."]
visible = false
[node name="TextureRect" type="TextureRect" parent="Backside"]
margin_left = -110.0
margin_top = -193.0
margin_right = 1000.0
margin_bottom = 1722.0
rect_scale = Vector2( 0.2, 0.2 )
offset_left = -110.0
offset_top = -193.0
offset_right = 1000.0
offset_bottom = 1722.0
scale = Vector2( 0.2, 0.2 )
texture = ExtResource( 4 )
stretch_mode = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Border sprite" type="Sprite" parent="Backside"]
[node name="Border sprite" type="Sprite2D" parent="Backside"]
texture = ExtResource( 3 )

12
Main.gd
View file

@ -1,9 +1,9 @@
extends Node
onready var HanafudaCard = preload("res://HanafudaCard.tscn")
@onready var HanafudaCard = preload("res://HanafudaCard.tscn")
onready var deck = $Deck
onready var tween = $Tween
@onready var deck = $Deck
@onready var tween = $Tween
func _ready():
var dealer = oya()
@ -14,7 +14,7 @@ func oya():
var card_reveal_duration = 0.5
var card_dim = 150
var card_1 = HanafudaCard.instance().init_card($Deck.draw_card())
var card_1 = HanafudaCard.instantiate().init_card($Deck.draw_card())
card_1.set_min_dimension(card_dim)
add_child(card_1)
@ -27,7 +27,7 @@ func oya():
card_reveal_duration,
Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
var card_2 = HanafudaCard.instance().init_card($Deck.draw_card())
var card_2 = HanafudaCard.instantiate().init_card($Deck.draw_card())
card_2.set_min_dimension(card_dim)
add_child(card_2)
tween.interpolate_property(card_2, "position",
@ -35,7 +35,7 @@ func oya():
card_reveal_duration,
Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
yield(tween, "tween_all_completed")
await tween.tween_all_completed
print("Player 1: {c}".format({"c": card_1.value.desc()}))
print("Player 2: {c}".format({"c": card_2.value.desc()}))

View file

@ -1,26 +1,34 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=4 format=3 uid="uid://bb31qjmt5sk6i"]
[ext_resource path="res://HanafudaCard.tscn" type="PackedScene" id=1]
[ext_resource path="res://Main.gd" type="Script" id=2]
[ext_resource path="res://Deck.gd" type="Script" id=3]
[ext_resource type="PackedScene" path="res://HanafudaCard.tscn" id="1"]
[ext_resource type="Script" path="res://Main.gd" id="2"]
[ext_resource type="Script" path="res://Deck.gd" id="3"]
[node name="Node" type="Node"]
script = ExtResource( 2 )
script = ExtResource("2")
[node name="Background" type="ColorRect" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.0941176, 0.423529, 0.27451, 1 )
__meta__ = {
"_edit_use_anchors_": false
}
color = Color(0.0941176, 0.423529, 0.27451, 1)
[node name="HanafudaCard" parent="." instance=ExtResource( 1 )]
[node name="HanafudaCard" parent="." instance=ExtResource("1")]
visible = false
position = Vector2( 205, 447 )
position = Vector2(205, 447)
[node name="Deck" type="Node2D" parent="."]
position = Vector2( 293, 412 )
script = ExtResource( 3 )
position = Vector2(293, 412)
script = ExtResource("3")
[node name="Tween" type="Tween" parent="."]
_import_path = NodePath("")
unique_name_in_owner = false
process_mode = 0
process_priority = 0
process_physics_priority = 0
process_thread_group = 0
physics_interpolation_mode = 0
auto_translate_mode = 0
editor_description = ""
script = null

View file

@ -1,8 +1,9 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/japanese_pattern_01.png-f5786b9777fdcad19c4be71085ddc93d.stex"
type="CompressedTexture2D"
uid="uid://cortgeafdhh2v"
path="res://.godot/imported/japanese_pattern_01.png-f5786b9777fdcad19c4be71085ddc93d.ctex"
metadata={
"vram_texture": false
}
@ -10,26 +11,24 @@ metadata={
[deps]
source_file="res://assets/japanese_pattern_01.png"
dest_files=[ "res://.import/japanese_pattern_01.png-f5786b9777fdcad19c4be71085ddc93d.stex" ]
dest_files=["res://.godot/imported/japanese_pattern_01.png-f5786b9777fdcad19c4be71085ddc93d.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/hdr_compression=1
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -1,7 +1,7 @@
[gd_resource type="Environment" load_steps=2 format=2]
[gd_resource type="Environment" load_steps=2 format=3 uid="uid://t70a0g8ack6a"]
[sub_resource type="ProceduralSky" id=1]
[sub_resource type="Sky" id="1"]
[resource]
background_mode = 2
background_sky = SubResource( 1 )
sky = SubResource("1")

View file

@ -1,8 +1,9 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
type="CompressedTexture2D"
uid="uid://b7icomn0rprn"
path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"
metadata={
"vram_texture": false
}
@ -10,26 +11,24 @@ metadata={
[deps]
source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/hdr_compression=1
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -6,28 +6,13 @@
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=4
_global_script_classes=[ {
"base": "Node",
"class": "CardValue",
"language": "GDScript",
"path": "res://CardValue.gd"
}, {
"base": "Node2D",
"class": "HanafudaCard",
"language": "GDScript",
"path": "res://HanafudaCard.gd"
} ]
_global_script_class_icons={
"CardValue": "",
"HanafudaCard": ""
}
config_version=5
[application]
config/name="Hanafuda"
run/main_scene="res://Main.tscn"
config/features=PackedStringArray("4.3")
config/icon="res://icon.png"
[autoload]
@ -36,8 +21,8 @@ Enums="*res://Enums.gd"
[display]
window/size/width=600
window/size/height=900
window/size/viewport_width=600
window/size/viewport_height=900
[physics]
@ -45,4 +30,4 @@ common/enable_pause_aware_picking=true
[rendering]
environment/default_environment="res://default_env.tres"
environment/defaults/default_environment="res://default_env.tres"