From f2326e28ac0ec85a5ec9469838e9f89992f951f8 Mon Sep 17 00:00:00 2001 From: Nathan Lovato Date: Thu, 27 Dec 2018 20:28:40 +0900 Subject: [PATCH] Close #148: Change the Pawns' animated character based on the party members --- godot/animation/GodettePawnAnim.tscn | 5 +++-- godot/animation/RobiPawnAnim.tscn | 8 +++++++- godot/local_map/grid/PawnContainer.gd | 24 +++++++++++++--------- godot/local_map/pawns/PawnActor.gd | 11 +++++++++- godot/party/Party.tscn | 29 ++++++++++++++++++--------- godot/party/PartyMember.gd | 5 +++++ 6 files changed, 59 insertions(+), 23 deletions(-) diff --git a/godot/animation/GodettePawnAnim.tscn b/godot/animation/GodettePawnAnim.tscn index dfed9421..ea8052d7 100644 --- a/godot/animation/GodettePawnAnim.tscn +++ b/godot/animation/GodettePawnAnim.tscn @@ -3,9 +3,10 @@ [ext_resource path="res://animation/PawnAnim.tscn" type="PackedScene" id=1] [ext_resource path="res://assets/sprites/local_map/characters/godette_pawn.png" type="Texture" id=2] -[node name="GodettePawnAnim" index="0" instance=ExtResource( 1 )] +[node name="GodettePawnAnim" instance=ExtResource( 1 )] [node name="Body" parent="Root" index="0"] -position = Vector2( 0, -188.656 ) +scale = Vector2( 1, 1 ) texture = ExtResource( 2 ) +offset = Vector2( 0, -179.527 ) diff --git a/godot/animation/RobiPawnAnim.tscn b/godot/animation/RobiPawnAnim.tscn index 740844b9..63e49be3 100644 --- a/godot/animation/RobiPawnAnim.tscn +++ b/godot/animation/RobiPawnAnim.tscn @@ -1,6 +1,12 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://animation/PawnAnim.tscn" type="PackedScene" id=1] +[ext_resource path="res://assets/sprites/local_map/characters/robi_pawn.png" type="Texture" id=2] [node name="RobiPawnAnim" index="0" instance=ExtResource( 1 )] +[node name="Body" parent="Root" index="0"] +scale = Vector2( 1, 1 ) +texture = ExtResource( 2 ) +offset = Vector2( 0, -171.413 ) + diff --git a/godot/local_map/grid/PawnContainer.gd b/godot/local_map/grid/PawnContainer.gd index d8022b65..1eb16f2a 100644 --- a/godot/local_map/grid/PawnContainer.gd +++ b/godot/local_map/grid/PawnContainer.gd @@ -1,4 +1,9 @@ -extends Node2D +""" +Container for all pawns on the map. +Sorts pawns by their Y position, +Spawns and rebuilds the player's party +""" +extends YSort export var party_scene : PackedScene @@ -14,20 +19,21 @@ func spawn_party(game_board, party : Object) -> void: var party_size = min(get_child_count(), party.PARTY_SIZE) - 1 for index in range(party_size): pawn_previous = spawn_pawn( - game_board.spawning_point.position, - pawn_previous, - party.get_child(index).name, + party.get_child(index), + game_board, + pawn_previous, index == 0) - pawn_previous.initialize(game_board) party_members.append(pawn_previous) -func spawn_pawn(pos : Vector2, pawn_previous : Object, pawn_name : String, is_leader : bool = false) -> Object: - var new_pawn = Leader.instance() if is_leader else Follower.instance() - new_pawn.name = pawn_name - new_pawn.position = pos +func spawn_pawn(party_member : PartyMember, game_board : GameBoard, pawn_previous : Object, is_leader : bool = false) -> Object: + var new_pawn : PawnActor = Leader.instance() if is_leader else Follower.instance() + new_pawn.name = party_member.name + new_pawn.position = game_board.spawning_point.position + new_pawn.initialize(game_board) if pawn_previous: pawn_previous.connect("moved", new_pawn, "_on_target_Pawn_moved") add_child(new_pawn) + new_pawn.change_skin(party_member.get_pawn_anim()) return new_pawn func rebuild_party() -> void: diff --git a/godot/local_map/pawns/PawnActor.gd b/godot/local_map/pawns/PawnActor.gd index 05189ef3..f6a8e5c6 100644 --- a/godot/local_map/pawns/PawnActor.gd +++ b/godot/local_map/pawns/PawnActor.gd @@ -6,8 +6,8 @@ var game_board signal moved(last_position, current_position) onready var pivot = $Pivot -onready var anim : PawnAnim = $Pivot/PawnAnim onready var tween = $Tween +onready var anim : PawnAnim = pivot.get_node("PawnAnim") func _ready(): update_look_direction(Vector2(1, 0)) @@ -36,3 +36,12 @@ func bump(): set_process(false) yield(anim.play_bump(), "completed") set_process(true) + +func change_skin(pawn_anim : PawnAnim): + """ + Replaces the pawn's animated character with another + """ + if anim: + anim.queue_free() + anim = pawn_anim + pivot.add_child(pawn_anim) diff --git a/godot/party/Party.tscn b/godot/party/Party.tscn index 1b5b9483..1d35a689 100644 --- a/godot/party/Party.tscn +++ b/godot/party/Party.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=2] +[gd_scene load_steps=15 format=2] [ext_resource path="res://party/Party.gd" type="Script" id=1] [ext_resource path="res://party/PartyMember.tscn" type="PackedScene" id=2] @@ -8,18 +8,21 @@ [ext_resource path="res://combat/battlers/skills/LearnedSkill.tscn" type="PackedScene" id=6] [ext_resource path="res://combat/battlers/skills/Lollislash.tres" type="Resource" id=7] [ext_resource path="res://combat/battlers/ai/PlayerInput.gd" type="Script" id=8] -[ext_resource path="res://combat/battlers/jobs/RobiJob.tres" type="Resource" id=9] -[ext_resource path="res://assets/sprites/battlers/robi_portrait_256.png" type="Texture" id=10] -[ext_resource path="res://animation/RobiAnim.tscn" type="PackedScene" id=11] -[ext_resource path="res://combat/battlers/skills/Slash.tres" type="Resource" id=12] +[ext_resource path="res://animation/GodettePawnAnim.tscn" type="PackedScene" id=9] +[ext_resource path="res://combat/battlers/jobs/RobiJob.tres" type="Resource" id=10] +[ext_resource path="res://assets/sprites/battlers/robi_portrait_256.png" type="Texture" id=11] +[ext_resource path="res://animation/RobiAnim.tscn" type="PackedScene" id=12] +[ext_resource path="res://combat/battlers/skills/Slash.tres" type="Resource" id=13] +[ext_resource path="res://animation/RobiPawnAnim.tscn" type="PackedScene" id=14] [node name="Party" type="Node2D"] script = ExtResource( 1 ) -PARTY_SIZE = null [node name="Godette" parent="." instance=ExtResource( 2 )] +pawn_anim_path = NodePath("GodettePawnAnim") [node name="Battler" parent="Godette" index="0"] +editor/display_folded = true stats = ExtResource( 3 ) party_member = true turn_order_icon = ExtResource( 4 ) @@ -32,22 +35,28 @@ skill = ExtResource( 7 ) [node name="AI" parent="Godette/Battler" index="6"] script = ExtResource( 8 ) +[node name="GodettePawnAnim" parent="Godette" instance=ExtResource( 9 )] + [node name="Robi" parent="." instance=ExtResource( 2 )] +pawn_anim_path = NodePath("RobiPawnAnim") [node name="Battler" parent="Robi" index="0"] -stats = ExtResource( 9 ) +editor/display_folded = true +stats = ExtResource( 10 ) party_member = true -turn_order_icon = ExtResource( 10 ) +turn_order_icon = ExtResource( 11 ) -[node name="RobiAnim" parent="Robi/Battler/Skin" index="2" instance=ExtResource( 11 )] +[node name="RobiAnim" parent="Robi/Battler/Skin" index="2" instance=ExtResource( 12 )] [node name="Slash" parent="Robi/Battler/Skills" index="0" instance=ExtResource( 6 )] -skill = ExtResource( 12 ) +skill = ExtResource( 13 ) level = 0 [node name="AI" parent="Robi/Battler" index="6"] script = ExtResource( 8 ) +[node name="RobiPawnAnim" parent="Robi" instance=ExtResource( 14 )] + [editable path="Godette"] diff --git a/godot/party/PartyMember.gd b/godot/party/PartyMember.gd index ea60b890..00c8c70f 100644 --- a/godot/party/PartyMember.gd +++ b/godot/party/PartyMember.gd @@ -2,9 +2,11 @@ extends Node2D class_name PartyMember +export var pawn_anim_path : NodePath onready var battler = $Battler func _ready(): + assert pawn_anim_path battler.stats.reset() func update_stats(stats : CharacterStats): @@ -20,3 +22,6 @@ func ready_for_combat(): at the start of a battle """ return battler.duplicate() + +func get_pawn_anim(): + return get_node(pawn_anim_path).duplicate()