diff --git a/card.gd b/card.gd index bd5c62b..866dcbf 100644 --- a/card.gd +++ b/card.gd @@ -1,4 +1,5 @@ extends TextureRect +#extends Sprite2D ## The card class ## ## Represents an instance of a card to be displayed on the tabletop. @@ -12,6 +13,31 @@ var card_name: String var card_type: String var oracle_text: String +var is_dragging = false +var delay = 5.0 # TODO find the best value for this +var mouse_offset: Vector2 + +func _physics_process(delta: float) -> void: + if is_dragging == true: + var tween = get_tree().create_tween() + tween.tween_property(self, "position", get_global_mouse_position() - mouse_offset, delay * delta) + + +func _gui_input(event: InputEvent) -> void: + if event is not InputEventMouseButton: + return + match event.button_index: + MOUSE_BUTTON_LEFT: + if event.pressed: + print("down!") + is_dragging = true + mouse_offset = get_global_mouse_position() - global_position + else: + print("up!") + is_dragging = false + MOUSE_BUTTON_RIGHT: + pass + func _card_error(error_type: String) -> String: return "ERROR::CARD::%s::%s::%s::\n" % [card_id, card_name, error_type] @@ -75,12 +101,16 @@ func _load_image() -> Error: push_error("%sCard on-board image failed to load correctly" % _card_error("IMAGE")) return FAILED + # TODO: Get the size from the node or some constant variable. image.resize(int(size.x), int(size.y), Image.INTERPOLATE_LANCZOS) + + var image_texture = ImageTexture.new() image_texture.set_image(image) + #expand_mode = TextureRect.EXPAND_FIT_WIDTH texture = image_texture return OK diff --git a/field.gd b/field.gd index 3a41998..5ad1a16 100644 --- a/field.gd +++ b/field.gd @@ -15,7 +15,7 @@ func _ready() -> void: # TODO: Currently working with an already-cached card with a known ID to load this. # Later on, the cards should be pulling the IDs directly from the library's list of IDs. - card.init("d3f10f07-7cfe-4a6f-8de6-373e367a731b") + card.init("d3f10f07-7cfe-4a6f-8de6-373e367a731b", _screen_size) add_child(card) diff --git a/library.gd b/library.gd index 00d0542..cd5c50a 100644 --- a/library.gd +++ b/library.gd @@ -3,7 +3,7 @@ extends Node2D var _card_class = preload("res://card.gd") # Library cards are represented as an array of card IDs. -var lib_cards: Array[String] = [] +var lib_cards: Array[String] var num_cards: int = 0 @@ -11,20 +11,13 @@ func _load_card_callback(card) -> void: card.load_card() -func _init(card_ids: Array) -> void: +func _init(_decklist: Dictionary) -> void: lib_cards = Array() - var temp_card - for id in card_ids: - temp_card = _card_class.new() - temp_card.cache_done.connect(_load_card_callback.bind(temp_card)) - lib_cards.push_back(temp_card) - num_cards += 1 - - -func init(card_ids: Array[String]) -> void: - for id in card_ids: - pass - + for card in _decklist: + var _num = _decklist[card] + num_cards += _num + for i in _num: + lib_cards.push_back(card) func add_cards(cards: Array, top: bool) -> void: for card in cards: diff --git a/player.gd b/player.gd index 731ad1c..4f52f77 100644 --- a/player.gd +++ b/player.gd @@ -1,19 +1,36 @@ extends Node2D -# var _card_class = preload("res://card.gd") +var _card_class = preload("res://card.tscn") var field_scene = preload("res://field.tscn") var fields: Array[Node] = [] +var decks: Array[Dictionary] +func _load_decks(): + if !FileAccess.file_exists("user://decks.json"): + return # no loaded decks + var file = FileAccess.open("user://decks.json", FileAccess.READ) + decks = JSON.parse_string(file.get_as_text()) + file = null + # Called when the node enters the scene tree for the first time. func _ready() -> void: # The first field in the array will be the player's own field. # Might be a better idea to have that in a seperate variable? idk - fields.append(field_scene.instantiate()) - var colors: Array[Color] = [Color(1, 0, 1)] - fields[0].set_colors(colors) - add_child(fields[0]) + + var card = _card_class.instantiate() + + # TODO: Currently working with an already-cached card with a known ID to load this. + # Later on, the cards should be pulling the IDs directly from the library's list of IDs. + card.init("d3f10f07-7cfe-4a6f-8de6-373e367a731b") + + add_child(card) + + #fields.append(field_scene.instantiate()) + #var colors: Array[Color] = [Color(1, 0, 1)] + #fields[0].set_colors(colors) + #add_child(fields[0]) # Called every frame. 'delta' is the elapsed time since the previous frame. diff --git a/tabletop.gd b/tabletop.gd index 4ee33ed..30df792 100644 --- a/tabletop.gd +++ b/tabletop.gd @@ -16,7 +16,7 @@ func _ready() -> void: add_child(player) move_child(player, 0) - # cache.get_card_data_from_name("1996 World Champion") + cache.get_card_data_from_name("1996 World Champion") var deck = deck_input.new() add_child(deck)