diff --git a/godot/Game.gd b/godot/Game.gd index d08d77367bc22a4dbbdc41f8ca6c494a4228e658..ba9359a0fd1d0a384ec747d9df50702c57f8275a 100644 --- a/godot/Game.gd +++ b/godot/Game.gd @@ -13,6 +13,7 @@ var transitioning = false func _ready(): local_map.visible = true + local_map.spawn_party(party) func enter_battle(formation: Formation): """ diff --git a/godot/local_map/LocalMap.gd b/godot/local_map/LocalMap.gd index bd58e114baa95e3bca3260d5f009f6bef5d11d9b..c5a4e0691dc69428b8a7b79628a11e4e3c28d47d 100644 --- a/godot/local_map/LocalMap.gd +++ b/godot/local_map/LocalMap.gd @@ -1,7 +1,6 @@ extends Node signal enemies_encountered(formation) - signal dialogue(dialogue) func _ready(): @@ -9,3 +8,6 @@ func _ready(): func _on_Grid_enemies_encountered(formation) -> void: emit_signal("enemies_encountered", formation) + +func spawn_party(party) -> void: + $Grid/Pawns.spawn_party(party, $Grid.map_to_world(Vector2(2,2))) \ No newline at end of file diff --git a/godot/local_map/LocalMap.tscn b/godot/local_map/LocalMap.tscn index 107061d9e0cec028bb82d9612e8d6cf4324ea91f..780c194e8cf4ad945272d85a306968a846f11ddb 100644 --- a/godot/local_map/LocalMap.tscn +++ b/godot/local_map/LocalMap.tscn @@ -1,18 +1,17 @@ -[gd_scene load_steps=14 format=2] +[gd_scene load_steps=13 format=2] [ext_resource path="res://local_map/LocalMap.gd" type="Script" id=1] [ext_resource path="res://local_map/tilesets/grid_lines/grid_lines_tileset.tres" type="TileSet" id=2] [ext_resource path="res://local_map/tilesets/grid/grid_tileset.tres" type="TileSet" id=3] [ext_resource path="res://local_map/grid/Grid.gd" type="Script" id=4] [ext_resource path="res://local_map/grid/PawnContainer.gd" type="Script" id=5] -[ext_resource path="res://local_map/pawns/Actor.tscn" type="PackedScene" id=6] -[ext_resource path="res://local_map/pawns/Follower.tscn" type="PackedScene" id=7] -[ext_resource path="res://local_map/pawns/Pawn.gd" type="Script" id=8] -[ext_resource path="res://combat/battlers/formations/PorcupineFormation001.tscn" type="PackedScene" id=9] -[ext_resource path="res://local_map/pawns/sprites/character_grey.png" type="Texture" id=10] -[ext_resource path="res://local_map/pawns/sprites/star.png" type="Texture" id=11] -[ext_resource path="res://dialogue/Dialogue.tscn" type="PackedScene" id=12] -[ext_resource path="res://interface/gui/DialogueBox.tscn" type="PackedScene" id=13] +[ext_resource path="res://party/Party.tscn" type="PackedScene" id=6] +[ext_resource path="res://local_map/pawns/Pawn.gd" type="Script" id=7] +[ext_resource path="res://combat/battlers/formations/PorcupineFormation001.tscn" type="PackedScene" id=8] +[ext_resource path="res://local_map/pawns/sprites/character_grey.png" type="Texture" id=9] +[ext_resource path="res://local_map/pawns/sprites/star.png" type="Texture" id=10] +[ext_resource path="res://dialogue/Dialogue.tscn" type="PackedScene" id=11] +[ext_resource path="res://interface/gui/DialogueBox.tscn" type="PackedScene" id=12] [node name="LocalMap" type="Node2D"] script = ExtResource( 1 ) @@ -68,38 +67,32 @@ __meta__ = { [node name="Pawns" type="YSort" parent="Grid"] sort_enabled = true script = ExtResource( 5 ) - -[node name="Leader" parent="Grid/Pawns" instance=ExtResource( 6 )] -position = Vector2( 670, 290 ) - -[node name="Follower" parent="Grid/Pawns" instance=ExtResource( 7 )] -position = Vector2( 356, 290 ) - -[node name="Follower2" parent="Grid/Pawns" instance=ExtResource( 7 )] -position = Vector2( 293, 290 ) +party_scene = ExtResource( 6 ) [node name="Actor2" type="Node2D" parent="Grid/Pawns" groups=[ "enemy", ]] +editor/display_folded = true position = Vector2( 480, 480 ) z_index = 1 -script = ExtResource( 8 ) +script = ExtResource( 7 ) type = 0 -formation = ExtResource( 9 ) +formation = ExtResource( 8 ) [node name="Sprite" type="Sprite" parent="Grid/Pawns/Actor2"] -texture = ExtResource( 10 ) +texture = ExtResource( 9 ) [node name="Object" type="Node2D" parent="Grid/Pawns"] +editor/display_folded = true position = Vector2( 544, 288 ) -script = ExtResource( 8 ) +script = ExtResource( 7 ) type = 2 -formation = ExtResource( 9 ) +formation = ExtResource( 8 ) [node name="Sprite" type="Sprite" parent="Grid/Pawns/Object"] -texture = ExtResource( 11 ) +texture = ExtResource( 10 ) -[node name="Dialogue" parent="Grid/Pawns/Object" instance=ExtResource( 12 )] +[node name="Dialogue" parent="Grid/Pawns/Object" instance=ExtResource( 11 )] file_path = "res://dialogue/data/test_conversation.json" [node name="MapInterface" type="CanvasLayer" parent="."] @@ -110,10 +103,8 @@ rotation = 0.0 scale = Vector2( 1, 1 ) transform = Transform2D( 1, 0, 0, 1, 0, 0 ) -[node name="DialogueBox" parent="MapInterface" instance=ExtResource( 13 )] +[node name="DialogueBox" parent="MapInterface" instance=ExtResource( 12 )] visible = false [connection signal="dialogue" from="." to="MapInterface/DialogueBox" method="initialize"] [connection signal="enemies_encountered" from="Grid" to="." method="_on_Grid_enemies_encountered"] -[connection signal="moved" from="Grid/Pawns/Leader" to="Grid/Pawns/Follower" method="_on_target_Pawn_moved"] -[connection signal="moved" from="Grid/Pawns/Follower" to="Grid/Pawns/Follower2" method="_on_target_Pawn_moved"] diff --git a/godot/local_map/grid/Grid.gd b/godot/local_map/grid/Grid.gd index a5140b4fbfc62dc6df0e6c046d550343bab83073..99f870c166bb6087e879bd13a94eec8026ffa697 100644 --- a/godot/local_map/grid/Grid.gd +++ b/godot/local_map/grid/Grid.gd @@ -2,7 +2,7 @@ extends TileMap signal enemies_encountered(formation) -enum CELL_TYPES {EMPTY = -1, ACTOR, OBSTACLE, OBJECT} +enum CELL_TYPES { EMPTY = -1, ACTOR, OBSTACLE, OBJECT } onready var pawns = get_node("Pawns") diff --git a/godot/local_map/grid/PawnContainer.gd b/godot/local_map/grid/PawnContainer.gd index 5a2d00fcf49b25168cca65197ed91016b8af188b..f531945a6d8b74fb777f101859efb31fbf6a2be2 100644 --- a/godot/local_map/grid/PawnContainer.gd +++ b/godot/local_map/grid/PawnContainer.gd @@ -1,9 +1,35 @@ extends Node2D -func _ready() -> void: - for child in get_children(): - if "Follower" in child.name: - child.position = $Leader.position +export var party_scene : PackedScene + +const LEADER = preload("res://local_map/pawns/Actor.tscn") +const FOLLOWER = preload("res://local_map/pawns/Follower.tscn") + +var party_members : = [] +var party + +func spawn_party(party : Object, spawn_position : Vector2) -> void: + self.party = party + var last_spawned_pawn = null + for index in range(party.get_child_count()): + last_spawned_pawn = spawn_new_pawn(spawn_position, last_spawned_pawn, party.get_child(index).name, index == 0) + party_members.append(last_spawned_pawn) + +func spawn_new_pawn(pos : Vector2, last_spawned : Object, name : String, is_leader : bool = false) -> Object: + var new_pawn = LEADER.instance() if is_leader else FOLLOWER.instance() + new_pawn.name = name + if last_spawned != null: + last_spawned.connect("moved", new_pawn, "_on_target_Pawn_moved") + new_pawn.position = pos + add_child(new_pawn) + return new_pawn func request_move(pawn, direction): return get_parent().request_move(pawn, direction) + +func rebuild_party() -> void: + var leader_pos = party_members[0].position + for member in party_members: + member.queue_free() + party_members.clear() + spawn_party(party, leader_pos)