Card cast
This commit is contained in:
parent
7df936cd01
commit
52572f8c37
17 changed files with 124 additions and 30 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
|
@abstract
|
||||||
extends Resource
|
extends Resource
|
||||||
|
|
||||||
class_name CardResource
|
class_name CardResource
|
||||||
|
|
||||||
@export_group("Gameplay")
|
@export_group("Gameplay")
|
||||||
@export_range(0,1,1,"or_greater","prefer_slider") var cost: int
|
@export_range(0,1,1,"or_greater","prefer_slider") var cost: int
|
||||||
@export var spawned_unit: PackedScene
|
|
||||||
|
|
||||||
@export_group("Visual")
|
@export_group("Visual")
|
||||||
@export var preview: Texture2D
|
@export var preview: Texture2D
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,17 @@ const ROTATION = PI/6.
|
||||||
@export var card_resource: CardResource
|
@export var card_resource: CardResource
|
||||||
var dragged: bool = false
|
var dragged: bool = false
|
||||||
|
|
||||||
|
var spawned_unit: Unit
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
$UnitPreview.texture = card_resource.preview
|
$Preview.texture = card_resource.preview
|
||||||
texture = card_resource.background
|
texture = card_resource.background
|
||||||
$CostBubble/Cost.text = str(card_resource.cost)
|
$CostBubble/Cost.text = str(card_resource.cost)
|
||||||
$ExperimentalBadge.visible = card_resource.experimental
|
$ExperimentalBadge.visible = card_resource.experimental
|
||||||
$Name.text = tr(card_resource.name_key)
|
$Name.text = tr(card_resource.name_key)
|
||||||
$Description.text = tr(card_resource.description_key)
|
$Description.text = tr(card_resource.description_key)
|
||||||
|
|
||||||
|
GameplaySignalBus.unit_spawn_cancelled.connect(on_unit_spawn_cancelled)
|
||||||
|
|
||||||
func _gui_input(event: InputEvent) -> void:
|
func _gui_input(event: InputEvent) -> void:
|
||||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
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
|
var pos = global_position
|
||||||
top_level = false
|
top_level = false
|
||||||
global_position = pos
|
global_position = pos
|
||||||
|
|
||||||
|
cast()
|
||||||
|
|
||||||
accept_event()
|
accept_event()
|
||||||
|
|
||||||
func _process(_delta: float) -> void:
|
func _process(_delta: float) -> void:
|
||||||
|
|
@ -42,3 +49,24 @@ func _process(_delta: float) -> void:
|
||||||
global_position = lerp(global_position,mouse_pos,0.25)
|
global_position = lerp(global_position,mouse_pos,0.25)
|
||||||
var relative_x = mouse_pos.x - global_position.x
|
var relative_x = mouse_pos.x - global_position.x
|
||||||
rotation = lerp(rotation,clamp(relative_x/PIXEL_PER_ROTATION*ROTATION,-ROTATION,ROTATION),0.25)
|
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()
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ pivot_offset_ratio = Vector2(0.5, 0.5)
|
||||||
texture = ExtResource("1_ivai2")
|
texture = ExtResource("1_ivai2")
|
||||||
script = ExtResource("2_jsqqk")
|
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
|
layout_mode = 0
|
||||||
offset_left = 12.0
|
offset_left = 12.0
|
||||||
offset_top = 17.0
|
offset_top = 17.0
|
||||||
|
|
|
||||||
|
|
@ -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="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="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]
|
[resource]
|
||||||
script = ExtResource("2_61y7x")
|
script = ExtResource("3_m3011")
|
||||||
|
spawned_unit = ExtResource("4_m3011")
|
||||||
preview = ExtResource("2_m3011")
|
preview = ExtResource("2_m3011")
|
||||||
name_key = &"doh"
|
name_key = &"doh"
|
||||||
description_key = &"doh_desc"
|
description_key = &"doh_desc"
|
||||||
|
|
|
||||||
|
|
@ -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="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="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]
|
[resource]
|
||||||
script = ExtResource("2_r84ts")
|
script = ExtResource("3_uc1ms")
|
||||||
|
spawned_unit = ExtResource("4_uc1ms")
|
||||||
cost = 1
|
cost = 1
|
||||||
preview = ExtResource("2_uc1ms")
|
preview = ExtResource("2_uc1ms")
|
||||||
name_key = &"fosma"
|
name_key = &"fosma"
|
||||||
|
|
|
||||||
|
|
@ -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="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="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]
|
[resource]
|
||||||
script = ExtResource("2_ongak")
|
script = ExtResource("3_xu3vf")
|
||||||
|
spawned_unit = ExtResource("4_xu3vf")
|
||||||
preview = ExtResource("2_xu3vf")
|
preview = ExtResource("2_xu3vf")
|
||||||
experimental = true
|
experimental = true
|
||||||
background = ExtResource("1_ongak")
|
background = ExtResource("1_ongak")
|
||||||
|
|
|
||||||
5
cards/unit_card.gd
Normal file
5
cards/unit_card.gd
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
extends CardResource
|
||||||
|
|
||||||
|
class_name UnitCard
|
||||||
|
|
||||||
|
@export var spawned_unit: PackedScene
|
||||||
1
cards/unit_card.gd.uid
Normal file
1
cards/unit_card.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://raoiry1l1tr8
|
||||||
|
|
@ -8,23 +8,19 @@
|
||||||
[ext_resource type="Resource" uid="uid://b6kiwb0marpng" path="res://cards/resources/zlosma.tres" id="5_0tnpc"]
|
[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://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://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="Script" uid="uid://dgd30yiw5q368" path="res://systems/grid_reciever.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://bkh50fstwbb6s" path="res://systems/grid_arranger.gd" id="10_vtaks"]
|
||||||
|
|
||||||
[node name="Game" type="Node2D" unique_id=619820575]
|
[node name="Game" type="Node2D" unique_id=619820575]
|
||||||
|
|
||||||
[node name="Field" type="Sprite2D" parent="." unique_id=1104378711]
|
[node name="Field" type="Sprite2D" parent="." unique_id=1104378711]
|
||||||
texture = ExtResource("1_iywne")
|
texture = ExtResource("1_iywne")
|
||||||
centered = false
|
centered = false
|
||||||
|
metadata/_edit_lock_ = true
|
||||||
[node name="Fosma" type="Sprite2D" parent="." unique_id=128278442]
|
|
||||||
position = Vector2(511, 278)
|
|
||||||
texture = ExtResource("10_vtaks")
|
|
||||||
|
|
||||||
[node name="PlayerInterface" type="CanvasLayer" parent="." unique_id=269857956]
|
[node name="PlayerInterface" type="CanvasLayer" parent="." unique_id=269857956]
|
||||||
|
|
||||||
[node name="Hand" type="Control" parent="PlayerInterface" unique_id=403305026]
|
[node name="Hand" type="Control" parent="PlayerInterface" unique_id=403305026]
|
||||||
visible = false
|
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
anchors_preset = 12
|
anchors_preset = 12
|
||||||
anchor_top = 1.0
|
anchor_top = 1.0
|
||||||
|
|
@ -90,6 +86,12 @@ metadata/_custom_type_script = "uid://rt6mxr30u8tp"
|
||||||
[node name="Highlighter" type="Node2D" parent="Grid" unique_id=69750982]
|
[node name="Highlighter" type="Node2D" parent="Grid" unique_id=69750982]
|
||||||
script = ExtResource("8_gee14")
|
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]
|
[node name="GridMarker" type="Marker2D" parent="." unique_id=1656515901]
|
||||||
position = Vector2(801, 567)
|
position = Vector2(801, 567)
|
||||||
|
|
||||||
|
|
@ -97,14 +99,3 @@ position = Vector2(801, 567)
|
||||||
position = Vector2(0, 142)
|
position = Vector2(0, 142)
|
||||||
anchor_mode = 0
|
anchor_mode = 0
|
||||||
zoom = Vector2(1.5, 1.5)
|
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"]
|
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,7 @@ extends Node
|
||||||
|
|
||||||
signal highlight_empty(empty: Array[int])
|
signal highlight_empty(empty: Array[int])
|
||||||
signal highlight_units(unit: Array[int])
|
signal highlight_units(unit: Array[int])
|
||||||
|
|
||||||
|
signal spawn_unit(unit: Unit)
|
||||||
|
signal unit_spawn_confirmed
|
||||||
|
signal unit_spawn_cancelled
|
||||||
|
|
|
||||||
12
systems/grid_arranger.gd
Normal file
12
systems/grid_arranger.gd
Normal file
|
|
@ -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)
|
||||||
1
systems/grid_arranger.gd.uid
Normal file
1
systems/grid_arranger.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bkh50fstwbb6s
|
||||||
12
systems/grid_reciever.gd
Normal file
12
systems/grid_reciever.gd
Normal file
|
|
@ -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()
|
||||||
1
systems/grid_reciever.gd.uid
Normal file
1
systems/grid_reciever.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://dgd30yiw5q368
|
||||||
11
units/doh/doh.tscn
Normal file
11
units/doh/doh.tscn
Normal file
|
|
@ -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")
|
||||||
11
units/fosma/fosma.tscn
Normal file
11
units/fosma/fosma.tscn
Normal file
|
|
@ -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")
|
||||||
11
units/zlosma/zlosma.tscn
Normal file
11
units/zlosma/zlosma.tscn
Normal file
|
|
@ -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")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue