diff --git a/cards/card-resource.gd b/cards/card-resource.gd index d1da5cd..306fb17 100644 --- a/cards/card-resource.gd +++ b/cards/card-resource.gd @@ -1,10 +1,10 @@ +@abstract extends Resource class_name CardResource @export_group("Gameplay") @export_range(0,1,1,"or_greater","prefer_slider") var cost: int -@export var spawned_unit: PackedScene @export_group("Visual") @export var preview: Texture2D diff --git a/cards/card.gd b/cards/card.gd index 74188bd..2cfbc99 100644 --- a/cards/card.gd +++ b/cards/card.gd @@ -8,13 +8,17 @@ const ROTATION = PI/6. @export var card_resource: CardResource var dragged: bool = false +var spawned_unit: Unit + func _ready() -> void: - $UnitPreview.texture = card_resource.preview + $Preview.texture = card_resource.preview texture = card_resource.background $CostBubble/Cost.text = str(card_resource.cost) $ExperimentalBadge.visible = card_resource.experimental $Name.text = tr(card_resource.name_key) $Description.text = tr(card_resource.description_key) + + GameplaySignalBus.unit_spawn_cancelled.connect(on_unit_spawn_cancelled) func _gui_input(event: InputEvent) -> void: if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed: @@ -31,6 +35,9 @@ func _input(event: InputEvent) -> void: var pos = global_position top_level = false global_position = pos + + cast() + accept_event() func _process(_delta: float) -> void: @@ -42,3 +49,24 @@ func _process(_delta: float) -> void: global_position = lerp(global_position,mouse_pos,0.25) var relative_x = mouse_pos.x - global_position.x rotation = lerp(rotation,clamp(relative_x/PIXEL_PER_ROTATION*ROTATION,-ROTATION,ROTATION),0.25) + +func cast() -> void: + if card_resource is UnitCard: + spawned_unit = card_resource.spawned_unit.instantiate() + get_tree().current_scene.add_child(spawned_unit) + spawned_unit.global_position = get_tree().current_scene.get_global_mouse_position() + + GameplaySignalBus.unit_spawn_confirmed.connect(confirm_use) + GameplaySignalBus.spawn_unit.emit(spawned_unit) + +func on_unit_spawn_cancelled() -> void: + if GameplaySignalBus.unit_spawn_confirmed.is_connected(confirm_use): + GameplaySignalBus.unit_spawn_confirmed.disconnect(confirm_use) + + if spawned_unit != null: + spawned_unit.queue_free() + +func confirm_use() -> void: + GameplaySignalBus.unit_spawn_confirmed.disconnect(confirm_use) + + queue_free() diff --git a/cards/card.tscn b/cards/card.tscn index 2cc9690..dac2832 100644 --- a/cards/card.tscn +++ b/cards/card.tscn @@ -21,7 +21,7 @@ pivot_offset_ratio = Vector2(0.5, 0.5) texture = ExtResource("1_ivai2") script = ExtResource("2_jsqqk") -[node name="UnitPreview" type="TextureRect" parent="." unique_id=696212558] +[node name="Preview" type="TextureRect" parent="." unique_id=696212558] layout_mode = 0 offset_left = 12.0 offset_top = 17.0 diff --git a/cards/resources/doh.tres b/cards/resources/doh.tres index 5764db1..0b8b34b 100644 --- a/cards/resources/doh.tres +++ b/cards/resources/doh.tres @@ -1,11 +1,13 @@ -[gd_resource type="Resource" script_class="CardResource" format=3 uid="uid://djqlx7bmcs5gj"] +[gd_resource type="Resource" script_class="UnitCard" format=3 uid="uid://djqlx7bmcs5gj"] [ext_resource type="Texture2D" uid="uid://c6akwwb58fidc" path="res://cards/templates/card-background.png" id="1_mxvf2"] -[ext_resource type="Script" uid="uid://bmc0rqt8jb8vh" path="res://cards/card-resource.gd" id="2_61y7x"] [ext_resource type="Texture2D" uid="uid://bwggofu5iv0xt" path="res://units/doh/doh.png" id="2_m3011"] +[ext_resource type="Script" uid="uid://raoiry1l1tr8" path="res://cards/unit_card.gd" id="3_m3011"] +[ext_resource type="PackedScene" uid="uid://f6wx6xux4558" path="res://units/doh/doh.tscn" id="4_m3011"] [resource] -script = ExtResource("2_61y7x") +script = ExtResource("3_m3011") +spawned_unit = ExtResource("4_m3011") preview = ExtResource("2_m3011") name_key = &"doh" description_key = &"doh_desc" diff --git a/cards/resources/fosma.tres b/cards/resources/fosma.tres index c92033b..7c0612f 100644 --- a/cards/resources/fosma.tres +++ b/cards/resources/fosma.tres @@ -1,11 +1,13 @@ -[gd_resource type="Resource" script_class="CardResource" format=3 uid="uid://e7kiu3wcf0ff"] +[gd_resource type="Resource" script_class="UnitCard" format=3 uid="uid://e7kiu3wcf0ff"] [ext_resource type="Texture2D" uid="uid://c6akwwb58fidc" path="res://cards/templates/card-background.png" id="1_j3bxo"] -[ext_resource type="Script" uid="uid://bmc0rqt8jb8vh" path="res://cards/card-resource.gd" id="2_r84ts"] [ext_resource type="Texture2D" uid="uid://du3h8ou2sxh6s" path="res://units/fosma/fosma.png" id="2_uc1ms"] +[ext_resource type="Script" uid="uid://raoiry1l1tr8" path="res://cards/unit_card.gd" id="3_uc1ms"] +[ext_resource type="PackedScene" uid="uid://mjnfkoesyjni" path="res://units/fosma/fosma.tscn" id="4_uc1ms"] [resource] -script = ExtResource("2_r84ts") +script = ExtResource("3_uc1ms") +spawned_unit = ExtResource("4_uc1ms") cost = 1 preview = ExtResource("2_uc1ms") name_key = &"fosma" diff --git a/cards/resources/zlosma.tres b/cards/resources/zlosma.tres index f625633..3cbec83 100644 --- a/cards/resources/zlosma.tres +++ b/cards/resources/zlosma.tres @@ -1,11 +1,13 @@ -[gd_resource type="Resource" script_class="CardResource" format=3 uid="uid://b6kiwb0marpng"] +[gd_resource type="Resource" script_class="UnitCard" format=3 uid="uid://b6kiwb0marpng"] [ext_resource type="Texture2D" uid="uid://cke1t56bw70kq" path="res://cards/templates/dev-card-background.png" id="1_ongak"] -[ext_resource type="Script" uid="uid://bmc0rqt8jb8vh" path="res://cards/card-resource.gd" id="2_ongak"] [ext_resource type="Texture2D" uid="uid://ctc3mk7gm68ha" path="res://units/zlosma/zlosma.png" id="2_xu3vf"] +[ext_resource type="Script" uid="uid://raoiry1l1tr8" path="res://cards/unit_card.gd" id="3_xu3vf"] +[ext_resource type="PackedScene" uid="uid://c37cnfxui8boa" path="res://units/zlosma/zlosma.tscn" id="4_xu3vf"] [resource] -script = ExtResource("2_ongak") +script = ExtResource("3_xu3vf") +spawned_unit = ExtResource("4_xu3vf") preview = ExtResource("2_xu3vf") experimental = true background = ExtResource("1_ongak") diff --git a/cards/unit_card.gd b/cards/unit_card.gd new file mode 100644 index 0000000..8243b64 --- /dev/null +++ b/cards/unit_card.gd @@ -0,0 +1,5 @@ +extends CardResource + +class_name UnitCard + +@export var spawned_unit: PackedScene diff --git a/cards/unit_card.gd.uid b/cards/unit_card.gd.uid new file mode 100644 index 0000000..2fc37f2 --- /dev/null +++ b/cards/unit_card.gd.uid @@ -0,0 +1 @@ +uid://raoiry1l1tr8 diff --git a/scenes/game.tscn b/scenes/game.tscn index 5809808..7fee7ea 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -8,23 +8,19 @@ [ext_resource type="Resource" uid="uid://b6kiwb0marpng" path="res://cards/resources/zlosma.tres" id="5_0tnpc"] [ext_resource type="Script" uid="uid://rt6mxr30u8tp" path="res://systems/grid.gd" id="7_u5sy4"] [ext_resource type="Script" uid="uid://bmy5djjmiljhl" path="res://systems/grid_highlighter.gd" id="8_gee14"] -[ext_resource type="Script" uid="uid://c7i44ghoo4kqo" path="res://debug/debug_highlight_tester.gd" id="9_0tnpc"] -[ext_resource type="Texture2D" uid="uid://du3h8ou2sxh6s" path="res://units/fosma/fosma.png" id="10_vtaks"] +[ext_resource type="Script" uid="uid://dgd30yiw5q368" path="res://systems/grid_reciever.gd" id="9_0tnpc"] +[ext_resource type="Script" uid="uid://bkh50fstwbb6s" path="res://systems/grid_arranger.gd" id="10_vtaks"] [node name="Game" type="Node2D" unique_id=619820575] [node name="Field" type="Sprite2D" parent="." unique_id=1104378711] texture = ExtResource("1_iywne") centered = false - -[node name="Fosma" type="Sprite2D" parent="." unique_id=128278442] -position = Vector2(511, 278) -texture = ExtResource("10_vtaks") +metadata/_edit_lock_ = true [node name="PlayerInterface" type="CanvasLayer" parent="." unique_id=269857956] [node name="Hand" type="Control" parent="PlayerInterface" unique_id=403305026] -visible = false layout_mode = 3 anchors_preset = 12 anchor_top = 1.0 @@ -90,6 +86,12 @@ metadata/_custom_type_script = "uid://rt6mxr30u8tp" [node name="Highlighter" type="Node2D" parent="Grid" unique_id=69750982] script = ExtResource("8_gee14") +[node name="Reciever" type="Node" parent="Grid" unique_id=898766746] +script = ExtResource("9_0tnpc") + +[node name="Arranger" type="Node" parent="Grid" unique_id=1638122526] +script = ExtResource("10_vtaks") + [node name="GridMarker" type="Marker2D" parent="." unique_id=1656515901] position = Vector2(801, 567) @@ -97,14 +99,3 @@ position = Vector2(801, 567) position = Vector2(0, 142) anchor_mode = 0 zoom = Vector2(1.5, 1.5) - -[node name="HighlightTester" type="Node2D" parent="." unique_id=729091083 node_paths=PackedStringArray("grid")] -position = Vector2(602, 362) -script = ExtResource("9_0tnpc") -grid = NodePath("../Grid") - -[node name="Timer" type="Timer" parent="HighlightTester" unique_id=1589504194] -wait_time = 0.1 -autostart = true - -[connection signal="timeout" from="HighlightTester/Timer" to="HighlightTester" method="_on_timer_timeout"] diff --git a/systems/gameplay_signal_bus.gd b/systems/gameplay_signal_bus.gd index 716201d..ac685c6 100644 --- a/systems/gameplay_signal_bus.gd +++ b/systems/gameplay_signal_bus.gd @@ -4,3 +4,7 @@ extends Node signal highlight_empty(empty: Array[int]) signal highlight_units(unit: Array[int]) + +signal spawn_unit(unit: Unit) +signal unit_spawn_confirmed +signal unit_spawn_cancelled diff --git a/systems/grid_arranger.gd b/systems/grid_arranger.gd new file mode 100644 index 0000000..d8cdbe3 --- /dev/null +++ b/systems/grid_arranger.gd @@ -0,0 +1,12 @@ +extends Node + + +@onready var grid: Grid = get_parent() + +func _process(_delta: float) -> void: + for i in range(len(grid.grid)): + var unit: Unit = grid.grid[i] + if unit == null: + continue + + unit.global_position = lerp(unit.global_position,grid.global_position+grid.from_index(i,true),0.25) diff --git a/systems/grid_arranger.gd.uid b/systems/grid_arranger.gd.uid new file mode 100644 index 0000000..2304463 --- /dev/null +++ b/systems/grid_arranger.gd.uid @@ -0,0 +1 @@ +uid://bkh50fstwbb6s diff --git a/systems/grid_reciever.gd b/systems/grid_reciever.gd new file mode 100644 index 0000000..aec9e78 --- /dev/null +++ b/systems/grid_reciever.gd @@ -0,0 +1,12 @@ +extends Node + +@onready var grid: Grid = get_parent() + +func _ready() -> void: + GameplaySignalBus.spawn_unit.connect(on_unit_spawned) + +func on_unit_spawned(unit: Unit): + if grid.try_set_unit(unit.global_position,unit): + GameplaySignalBus.unit_spawn_confirmed.emit() + else: + GameplaySignalBus.unit_spawn_cancelled.emit() diff --git a/systems/grid_reciever.gd.uid b/systems/grid_reciever.gd.uid new file mode 100644 index 0000000..cbc4ba5 --- /dev/null +++ b/systems/grid_reciever.gd.uid @@ -0,0 +1 @@ +uid://dgd30yiw5q368 diff --git a/units/doh/doh.tscn b/units/doh/doh.tscn new file mode 100644 index 0000000..dde37ed --- /dev/null +++ b/units/doh/doh.tscn @@ -0,0 +1,11 @@ +[gd_scene format=3 uid="uid://f6wx6xux4558"] + +[ext_resource type="Script" uid="uid://db7simgenakts" path="res://units/unit.gd" id="1_jfbus"] +[ext_resource type="Texture2D" uid="uid://bwggofu5iv0xt" path="res://units/doh/doh.png" id="2_6ge01"] + +[node name="Doh" type="Node2D" unique_id=2114547969] +script = ExtResource("1_jfbus") +metadata/_custom_type_script = "uid://db7simgenakts" + +[node name="Doh" type="Sprite2D" parent="." unique_id=1785775524] +texture = ExtResource("2_6ge01") diff --git a/units/fosma/fosma.tscn b/units/fosma/fosma.tscn new file mode 100644 index 0000000..866b53f --- /dev/null +++ b/units/fosma/fosma.tscn @@ -0,0 +1,11 @@ +[gd_scene format=3 uid="uid://mjnfkoesyjni"] + +[ext_resource type="Script" uid="uid://db7simgenakts" path="res://units/unit.gd" id="1_rlbkj"] +[ext_resource type="Texture2D" uid="uid://du3h8ou2sxh6s" path="res://units/fosma/fosma.png" id="2_nfc7p"] + +[node name="Fosma" type="Node2D" unique_id=279205841] +script = ExtResource("1_rlbkj") +metadata/_custom_type_script = "uid://db7simgenakts" + +[node name="Fosma" type="Sprite2D" parent="." unique_id=615442119] +texture = ExtResource("2_nfc7p") diff --git a/units/zlosma/zlosma.tscn b/units/zlosma/zlosma.tscn new file mode 100644 index 0000000..e15a0ad --- /dev/null +++ b/units/zlosma/zlosma.tscn @@ -0,0 +1,11 @@ +[gd_scene format=3 uid="uid://c37cnfxui8boa"] + +[ext_resource type="Script" uid="uid://db7simgenakts" path="res://units/unit.gd" id="1_gn8wq"] +[ext_resource type="Texture2D" uid="uid://ctc3mk7gm68ha" path="res://units/zlosma/zlosma.png" id="2_ogo5x"] + +[node name="Zlosma" type="Node2D" unique_id=867192004] +script = ExtResource("1_gn8wq") +metadata/_custom_type_script = "uid://db7simgenakts" + +[node name="Zlosma" type="Sprite2D" parent="." unique_id=1801362192] +texture = ExtResource("2_ogo5x")