From 4489eb5f7606137e746f8588a5fbd51f7e023595 Mon Sep 17 00:00:00 2001 From: Nathan Singer Date: Wed, 23 Apr 2025 15:44:17 -0400 Subject: [PATCH] adds some library boilerplate --- card.gd | 6 +++++- library.gd | 37 +++++++++++++++++++++++++++++++++++++ library.gd.uid | 1 + player.tscn | 12 ++++++++++-- tabletop.tscn | 3 +-- 5 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 library.gd create mode 100644 library.gd.uid diff --git a/card.gd b/card.gd index 5c9ddca..354a5fe 100644 --- a/card.gd +++ b/card.gd @@ -1,4 +1,4 @@ -extends Node +extends TextureRect ## The card class [br][br] ## ## @@ -118,5 +118,9 @@ func load_card() -> bool: card_type = card_json["type_line"] oracle_text = card_json["oracle_text"] + var img = Image.new() + img.load("user://card_cache/" + card_id + "/card.jpg") + texture = ImageTexture.create_from_image(img) + ondisk_card = null return true diff --git a/library.gd b/library.gd new file mode 100644 index 0000000..8fd4328 --- /dev/null +++ b/library.gd @@ -0,0 +1,37 @@ +extends Node2D + +var _card_class = preload("res://card.gd") + +var lib_cards +var num_cards + +func _load_card_callback(card) -> void: + card.load_card() + +func _init(card_ids: Array) -> void: + lib_cards = Array() + var temp_card + for id in card_ids: + temp_card = _card_class.new(id) + temp_card.cache_done.connect(_load_card_callback.bind(temp_card)) + lib_cards.push_back(temp_card) + num_cards += 1 + +func add_cards(cards: Array, top: bool) -> void: + for card in cards: + add_card(card, top) + +func add_card(card, top: bool) -> void: + if top: + lib_cards.push_front(card) + else: + lib_cards.push_back(card) + +func shuffle() -> void: + lib_cards.shuffle() + +func draw_cards(num) -> Array: + var ret = Array() + for i in num: + ret.push_back(lib_cards.pop_front()) + return ret diff --git a/library.gd.uid b/library.gd.uid new file mode 100644 index 0000000..e46750f --- /dev/null +++ b/library.gd.uid @@ -0,0 +1 @@ +uid://bc51go8t8uvts diff --git a/player.tscn b/player.tscn index dc9a8c5..605f046 100644 --- a/player.tscn +++ b/player.tscn @@ -1,6 +1,8 @@ -[gd_scene load_steps=2 format=3 uid="uid://cx0vga81xwckh"] +[gd_scene load_steps=4 format=3 uid="uid://cx0vga81xwckh"] [ext_resource type="Script" uid="uid://w2rqm1u7p7im" path="res://player.gd" id="1_4flbx"] +[ext_resource type="Script" uid="uid://bc51go8t8uvts" path="res://library.gd" id="2_onrkg"] +[ext_resource type="Script" uid="uid://b3yqd1qu7dyq" path="res://card.gd" id="3_i3pqv"] [node name="Player" type="Node2D"] script = ExtResource("1_4flbx") @@ -10,5 +12,11 @@ script = ExtResource("1_4flbx") [node name="Hand" type="Node2D" parent="."] [node name="Library" type="Node2D" parent="."] +script = ExtResource("2_onrkg") -[node name="HTTPRequest" type="HTTPRequest" parent="."] +[node name="TextureRect" type="TextureRect" parent="."] +offset_left = -1.0 +offset_top = 1.0 +offset_right = 39.0 +offset_bottom = 41.0 +script = ExtResource("3_i3pqv") diff --git a/tabletop.tscn b/tabletop.tscn index ae63f6c..fa6d891 100644 --- a/tabletop.tscn +++ b/tabletop.tscn @@ -3,6 +3,5 @@ [ext_resource type="Script" uid="uid://cfkew150yl1y3" path="res://tabletop.gd" id="1_3we3x"] [node name="Tabletop" type="Node2D"] +position = Vector2(-5760, -16768) script = ExtResource("1_3we3x") - -[node name="HTTPRequest" type="HTTPRequest" parent="."]