Compare commits
4 Commits
349a1bf0d3
...
7040c0e09d
Author | SHA1 | Date | |
---|---|---|---|
7040c0e09d | |||
4f89e06066 | |||
5002893113 | |||
40ccd28fb9 |
@ -11,10 +11,20 @@ var map_position : Vector2 = Vector2.ZERO
|
|||||||
onready var target_position : Vector2 = position
|
onready var target_position : Vector2 = position
|
||||||
var moving : bool = false
|
var moving : bool = false
|
||||||
|
|
||||||
|
var cards = [] setget ,get_cards
|
||||||
|
|
||||||
|
func get_cards():
|
||||||
|
for child in get_children():
|
||||||
|
if "Card" in child.name:
|
||||||
|
cards.append(child)
|
||||||
|
|
||||||
|
return cards
|
||||||
|
|
||||||
|
|
||||||
func level_change(new_level):
|
func level_change(new_level):
|
||||||
# when leveing up restore health
|
# when leveing up restore health
|
||||||
health = base_max_health * pow(level, 1.5)
|
health = base_max_health * pow(level, 1.5)
|
||||||
|
level = new_level
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
@ -27,11 +37,13 @@ func _physics_process(delta):
|
|||||||
#TODO: Replace with tween magic
|
#TODO: Replace with tween magic
|
||||||
position += (target_position - position)/2.5
|
position += (target_position - position)/2.5
|
||||||
|
|
||||||
|
|
||||||
func take_damage(damage):
|
func take_damage(damage):
|
||||||
health -= damage
|
health -= damage
|
||||||
if health <= 0:
|
if health <= 0:
|
||||||
die()
|
die()
|
||||||
|
|
||||||
|
|
||||||
func die():
|
func die():
|
||||||
#Animation here
|
#Animation here
|
||||||
queue_free()
|
queue_free()
|
||||||
|
@ -5,7 +5,7 @@ signal return_dice(dice_number)
|
|||||||
signal do_movement(movement_range)
|
signal do_movement(movement_range)
|
||||||
signal do_damage(damage, damage_range)
|
signal do_damage(damage, damage_range)
|
||||||
signal do_effect(effect, effect_range)
|
signal do_effect(effect, effect_range)
|
||||||
signal card_removed(card_self)
|
signal card_removed()
|
||||||
|
|
||||||
export (Resource) var card_info = preload("res://Assets/CardDB/Default.tres")
|
export (Resource) var card_info = preload("res://Assets/CardDB/Default.tres")
|
||||||
|
|
||||||
@ -138,6 +138,6 @@ func run_card():
|
|||||||
input_dice = []
|
input_dice = []
|
||||||
|
|
||||||
#card is used, disappear
|
#card is used, disappear
|
||||||
emit_signal("card_removed", self)
|
emit_signal("card_removed")
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|
||||||
|
@ -1,106 +1,32 @@
|
|||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
signal return_dice(dice_number)
|
const card_view_scene = preload("res://UI/CardView.tscn")
|
||||||
signal do_movement(movement_range)
|
|
||||||
signal do_damage(damage, damage_range)
|
|
||||||
signal do_effect(effect, effect_range)
|
|
||||||
|
|
||||||
const card = preload("res://UI/Card.tscn")
|
var character : Character = Character.new() setget update_cards_shown
|
||||||
const card_db_string = "res://Assets/CardDB/%s.tres"
|
var card_views = []
|
||||||
|
|
||||||
|
|
||||||
var selected : bool = false
|
func update_cards_shown(new_character = null):
|
||||||
var hovering_card = null
|
|
||||||
|
|
||||||
var current_cards = []
|
|
||||||
|
|
||||||
var currently_holding_dice = null
|
|
||||||
|
|
||||||
|
|
||||||
func emit_return_dice(dice_number):
|
|
||||||
emit_signal("return_dice", dice_number)
|
|
||||||
func emit_do_movement(movement_range):
|
|
||||||
emit_signal("do_movement", movement_range)
|
|
||||||
func emit_do_damage(damage, damage_range):
|
|
||||||
emit_signal("do_damage", damage, damage_range)
|
|
||||||
func emit_do_effect(effect, effect_range):
|
|
||||||
emit_signal("do_effect", effect, effect_range)
|
|
||||||
|
|
||||||
|
|
||||||
func set_currently_holding_dice(dice_number : int):
|
|
||||||
currently_holding_dice = dice_number
|
|
||||||
|
|
||||||
|
|
||||||
func remove_card(card):
|
|
||||||
var card_index = current_cards.find(card)
|
|
||||||
current_cards.remove(card_index)
|
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
|
||||||
|
|
||||||
# no keyboard input if not selected
|
# allow the update card shown function to work with and without setget
|
||||||
if not selected:
|
if new_character != null:
|
||||||
hovering_card = null
|
character = new_character
|
||||||
return
|
|
||||||
|
|
||||||
# if selected card is null, add a value
|
# remove the old cards
|
||||||
if not hovering_card:
|
for card_view in card_views:
|
||||||
hovering_card = 0
|
yield(card_view.card_view_remove(false), "completed")
|
||||||
|
card_views = []
|
||||||
|
|
||||||
# move the selection forward or backward the list depending on input
|
# add cards the new cards from the character
|
||||||
if (Input.is_action_just_pressed("ui_down") or
|
for card in character.cards:
|
||||||
Input.is_action_just_pressed("ui_right")):
|
var new_card_view = card_view_scene.instance()
|
||||||
|
new_card_view.card = card
|
||||||
current_cards[hovering_card].hovering_dice = null
|
$Margin/HBox.add_child(new_card_view)
|
||||||
|
card_views.append(new_card_view)
|
||||||
hovering_card += 1
|
new_card_view.connect("card_view_removed", self, "remove_from_card_views")
|
||||||
if hovering_card >= len(current_cards):
|
|
||||||
hovering_card = 0
|
|
||||||
|
|
||||||
if (Input.is_action_just_pressed("ui_up") or
|
|
||||||
Input.is_action_just_pressed("ui_left")):
|
|
||||||
|
|
||||||
current_cards[hovering_card].hovering_dice = null
|
|
||||||
|
|
||||||
hovering_card -= 1
|
|
||||||
if hovering_card < 0:
|
|
||||||
hovering_card = len(current_cards) -1
|
|
||||||
|
|
||||||
# show the dice over the card if hovering
|
|
||||||
current_cards[hovering_card].hovering_dice = currently_holding_dice
|
|
||||||
|
|
||||||
#if the enter key is pressed, input the dice into the card
|
|
||||||
if Input.is_action_just_pressed("ui_accept"):
|
|
||||||
current_cards[hovering_card].hovering_dice = null
|
|
||||||
current_cards[hovering_card].dice_inputted(currently_holding_dice)
|
|
||||||
hovering_card = 0
|
|
||||||
selected = false
|
|
||||||
|
|
||||||
|
|
||||||
func draw_card(specific_card : String = ""):
|
func remove_from_card_views(card_view):
|
||||||
# make a new card instance and add it to the grid container
|
var to_remove : int = card_views.find(card_view)
|
||||||
var new_card = card.instance()
|
if to_remove != -1:
|
||||||
|
card_views.remove(to_remove)
|
||||||
# check if a specific card data exists
|
|
||||||
var card_data_check = File.new()
|
|
||||||
var card_data_exists : bool = card_data_check.file_exists(card_db_string % specific_card)
|
|
||||||
|
|
||||||
# if a specifc card choosen, make new card that type
|
|
||||||
if card_data_exists:
|
|
||||||
new_card.card_info = load(card_db_string % specific_card)
|
|
||||||
else: #no card choosen, pick default
|
|
||||||
new_card.card_info = load(card_db_string % "Default")
|
|
||||||
|
|
||||||
$Margin/HBox.add_child(new_card)
|
|
||||||
|
|
||||||
# connect new_card.x signal to self.x
|
|
||||||
new_card.connect("return_dice", self, "emit_return_dice")
|
|
||||||
new_card.connect("do_movement", self, "emit_do_movement")
|
|
||||||
new_card.connect("do_damage", self, "emit_do_damage")
|
|
||||||
new_card.connect("do_effect", self, "emit_do_effect")
|
|
||||||
|
|
||||||
# connect the signal remove card signal
|
|
||||||
new_card.connect("card_removed", self, "remove_card")
|
|
||||||
|
|
||||||
# add the current card to the list of card
|
|
||||||
current_cards.append(new_card)
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
tool
|
tool
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
|
signal card_view_removed(card_view)
|
||||||
|
|
||||||
const TYPE_COLORS = [
|
const TYPE_COLORS = [
|
||||||
Color("#db4758"), # DAMAGE
|
Color("#db4758"), # DAMAGE
|
||||||
Color("#3cc361"), # UTILITY
|
Color("#3cc361"), # UTILITY
|
||||||
@ -15,15 +17,11 @@ var input_dice_views = []
|
|||||||
var card : Card = Card.new() setget update_cardview
|
var card : Card = Card.new() setget update_cardview
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
|
||||||
update_cardview()
|
|
||||||
connect_signals()
|
|
||||||
|
|
||||||
|
|
||||||
func update_cardview(new_card = null):
|
func update_cardview(new_card = null):
|
||||||
|
|
||||||
# allow the update card function to work with and without setget
|
# allow the update card function to work with and without setget
|
||||||
if new_card != null:
|
if new_card != null and new_card != card:
|
||||||
|
disconnect_signals()
|
||||||
card = new_card
|
card = new_card
|
||||||
connect_signals()
|
connect_signals()
|
||||||
|
|
||||||
@ -36,6 +34,11 @@ func update_cardview(new_card = null):
|
|||||||
$"%Name".text = card.card_info.name
|
$"%Name".text = card.card_info.name
|
||||||
$"%Description".text = card.card_info.description
|
$"%Description".text = card.card_info.description
|
||||||
|
|
||||||
|
# remove the old input dice views
|
||||||
|
for i in input_dice_views:
|
||||||
|
i.queue_free()
|
||||||
|
input_dice_views = []
|
||||||
|
|
||||||
# add the correct number of input dice views
|
# add the correct number of input dice views
|
||||||
for i in card.card_info.number_of_dice:
|
for i in card.card_info.number_of_dice:
|
||||||
add_input_dice_view()
|
add_input_dice_view()
|
||||||
@ -73,7 +76,9 @@ func add_input_dice_view():
|
|||||||
|
|
||||||
|
|
||||||
# this is run once the card emits card_removed
|
# this is run once the card emits card_removed
|
||||||
func card_view_run():
|
func card_view_run(do_emit_signal : bool = true):
|
||||||
|
# emit card_view_removed signal
|
||||||
|
if do_emit_signal: emit_signal("card_view_removed", self)
|
||||||
|
|
||||||
# play the disappearing input dice animation
|
# play the disappearing input dice animation
|
||||||
for i in input_dice_views:
|
for i in input_dice_views:
|
||||||
@ -87,7 +92,10 @@ func card_view_run():
|
|||||||
queue_free()
|
queue_free()
|
||||||
|
|
||||||
|
|
||||||
func card_view_remove():
|
func card_view_remove(do_emit_signal : bool = true):
|
||||||
|
# emit card_view_removed signal
|
||||||
|
if do_emit_signal: emit_signal("card_view_removed", self)
|
||||||
|
|
||||||
# play the remove animation
|
# play the remove animation
|
||||||
$AnimationPlayer.play("Drop Off")
|
$AnimationPlayer.play("Drop Off")
|
||||||
yield($AnimationPlayer, "animation_finished")
|
yield($AnimationPlayer, "animation_finished")
|
||||||
@ -96,5 +104,12 @@ func card_view_remove():
|
|||||||
queue_free()
|
queue_free()
|
||||||
|
|
||||||
|
|
||||||
|
func disconnect_signals():
|
||||||
|
if card.get_signal_connection_list("card_removed") == []:
|
||||||
|
return
|
||||||
|
|
||||||
|
card.disconnect("card_removed", self, "card_view_run")
|
||||||
|
|
||||||
|
|
||||||
func connect_signals():
|
func connect_signals():
|
||||||
card.connect("card_removed", self, "card_view_run")
|
card.connect("card_removed", self, "card_view_run")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user