Refactored unit spawning
This commit is contained in:
parent
c31a4740ae
commit
e0d56c91a9
|
@ -68,9 +68,7 @@ func play(anchor):
|
|||
var unit
|
||||
|
||||
if spawned_unit:
|
||||
unit = spawned_unit.instance()
|
||||
unit.attacker = hero.attacker if hero else false
|
||||
anchor.set_content(unit)
|
||||
unit = BattleHelper.spawn_unit(spawned_unit, anchor, hero.attacker if hero else false)
|
||||
|
||||
emit_signal("played", self, anchor, unit)
|
||||
|
||||
|
|
|
@ -19,11 +19,10 @@ static func update_anchors(tree: SceneTree, position, acceptability) -> Anchor:
|
|||
|
||||
return selected_anchor
|
||||
|
||||
static func spawn_unit(name: String, anchor: Anchor, attacker: bool) -> Node:
|
||||
static func spawn_unit(unit: PackedScene, anchor: Anchor, attacker: bool) -> Node:
|
||||
""" Spawn a unit on an empty anchor
|
||||
"""
|
||||
var scene = load("res://units/" + name + ".tscn")
|
||||
var node = scene.instance()
|
||||
var node = unit.instance()
|
||||
anchor.set_content(node)
|
||||
node.attacker = attacker
|
||||
return node
|
||||
|
|
|
@ -4,6 +4,8 @@ const BattleHelper = preload("res://helpers/battle.gd")
|
|||
|
||||
export(PackedScene) var deck_attack
|
||||
export(PackedScene) var deck_defend
|
||||
export(PackedScene) var hero_unit_attack
|
||||
export(PackedScene) var hero_unit_defend
|
||||
export(Script) var defend_ai
|
||||
|
||||
onready var deck_attack_cards = deck_attack.instance()
|
||||
|
@ -13,8 +15,8 @@ var hero_defend
|
|||
var turn_attack = true
|
||||
|
||||
func _ready():
|
||||
hero_attack = create_hero_unit("tomahawk", "attack_start", true)
|
||||
hero_defend = create_hero_unit("rhino", "defend_start", false)
|
||||
hero_attack = create_hero_unit(hero_unit_attack, "attack_start", true)
|
||||
hero_defend = create_hero_unit(hero_unit_defend, "defend_start", false)
|
||||
|
||||
$hand_attack.connect("turn_end", self, "end_turn")
|
||||
$hand_defend.connect("turn_end", self, "end_turn")
|
||||
|
@ -32,12 +34,12 @@ func find_free_anchor(anchor_type: String):
|
|||
return anchor
|
||||
return null
|
||||
|
||||
func create_hero_unit(name: String, anchor_type: String, attacker: bool):
|
||||
func create_hero_unit(unit: PackedScene, anchor_type: String, attacker: bool):
|
||||
var anchor = find_free_anchor(anchor_type)
|
||||
if anchor:
|
||||
var unit = BattleHelper.spawn_unit("heroes/" + name, anchor, attacker)
|
||||
unit.connect("combat_simulation", self, "_on_combat_simulation")
|
||||
return unit
|
||||
var hero = BattleHelper.spawn_unit(unit, anchor, attacker)
|
||||
_on_unit_created(hero)
|
||||
return hero
|
||||
else:
|
||||
return null
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=10 format=2]
|
||||
[gd_scene load_steps=12 format=2]
|
||||
|
||||
[ext_resource path="res://screens/battle/mechanolith.ogg" type="AudioStream" id=1]
|
||||
[ext_resource path="res://theme/ui.tres" type="Theme" id=2]
|
||||
|
@ -9,6 +9,8 @@
|
|||
[ext_resource path="res://units/points.tscn" type="PackedScene" id=7]
|
||||
[ext_resource path="res://ai/dumb.gd" type="Script" id=8]
|
||||
[ext_resource path="res://decks/all.tscn" type="PackedScene" id=9]
|
||||
[ext_resource path="res://units/heroes/tomahawk.tscn" type="PackedScene" id=10]
|
||||
[ext_resource path="res://units/heroes/rhino.tscn" type="PackedScene" id=11]
|
||||
|
||||
[node name="view" type="Panel"]
|
||||
anchor_right = 1.0
|
||||
|
@ -21,6 +23,8 @@ __meta__ = {
|
|||
}
|
||||
deck_attack = ExtResource( 9 )
|
||||
deck_defend = ExtResource( 9 )
|
||||
hero_unit_attack = ExtResource( 10 )
|
||||
hero_unit_defend = ExtResource( 11 )
|
||||
defend_ai = ExtResource( 8 )
|
||||
|
||||
[node name="background" type="Sprite" parent="."]
|
||||
|
|
Loading…
Reference in New Issue