Compare commits
No commits in common. "4489eb5f7606137e746f8588a5fbd51f7e023595" and "5fc67ab5e5caf3541a0d73beeb7d525a602bbc7c" have entirely different histories.
4489eb5f76
...
5fc67ab5e5
24
card.gd
24
card.gd
@ -1,4 +1,4 @@
|
|||||||
extends TextureRect
|
extends Node
|
||||||
## The card class [br][br]
|
## The card class [br][br]
|
||||||
##
|
##
|
||||||
##
|
##
|
||||||
@ -9,14 +9,14 @@ extends TextureRect
|
|||||||
# in the helper text box, but thats for the future
|
# in the helper text box, but thats for the future
|
||||||
const ManaCosts = preload("res://data/mana.gd")
|
const ManaCosts = preload("res://data/mana.gd")
|
||||||
|
|
||||||
signal cache_done
|
var cached = false
|
||||||
|
|
||||||
var card_id = "placedholder_id"
|
var card_id = "placedholder_id"
|
||||||
var card_name = "placeholder_name"
|
var card_name = "placeholder_name"
|
||||||
var card_type = "placeholder_card_type"
|
var card_type = "placeholder_card_type"
|
||||||
var oracle_text = "placeholder_oracle_text"
|
var oracle_text = "placeholder_oracle_text"
|
||||||
var _png_path = "placeholder_image_path"
|
var png_path = "placeholder_image_path"
|
||||||
var _jpg_path = "placeholder_image_path"
|
var jpg_path = "placeholder_image_path"
|
||||||
|
|
||||||
func _card_error(error_type: String) -> String:
|
func _card_error(error_type: String) -> String:
|
||||||
return "CARD::" + card_id + "::" + error_type + "\n"
|
return "CARD::" + card_id + "::" + error_type + "\n"
|
||||||
@ -25,15 +25,13 @@ func _init(id) -> void:
|
|||||||
card_id = id
|
card_id = id
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
if (_check_cache(card_id)):
|
|
||||||
return
|
|
||||||
await _do_cache_grab()
|
await _do_cache_grab()
|
||||||
|
|
||||||
func _do_cache_grab() -> void:
|
func _do_cache_grab() -> void:
|
||||||
await _do_http_request_card()
|
await _do_http_request_card()
|
||||||
await _do_http_request_imgs(_png_path, true)
|
await _do_http_request_imgs(png_path, true)
|
||||||
await _do_http_request_imgs(_jpg_path, false)
|
await _do_http_request_imgs(jpg_path, false)
|
||||||
cache_done.emit()
|
|
||||||
|
|
||||||
func _check_cache(id: String) -> bool:
|
func _check_cache(id: String) -> bool:
|
||||||
if (!FileAccess.file_exists("user://card_cache/" + id + "/card.json")):
|
if (!FileAccess.file_exists("user://card_cache/" + id + "/card.json")):
|
||||||
@ -96,8 +94,8 @@ func _do_http_request_card() -> void:
|
|||||||
card_cache = null # closes the file
|
card_cache = null # closes the file
|
||||||
|
|
||||||
var image_uris = card_content["image_uris"]
|
var image_uris = card_content["image_uris"]
|
||||||
_png_path = image_uris["png"]
|
png_path = image_uris["png"]
|
||||||
_jpg_path = image_uris["normal"]
|
jpg_path = image_uris["normal"]
|
||||||
|
|
||||||
## load_card
|
## load_card
|
||||||
##
|
##
|
||||||
@ -118,9 +116,5 @@ func load_card() -> bool:
|
|||||||
card_type = card_json["type_line"]
|
card_type = card_json["type_line"]
|
||||||
oracle_text = card_json["oracle_text"]
|
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
|
ondisk_card = null
|
||||||
return true
|
return true
|
||||||
|
37
library.gd
37
library.gd
@ -1,37 +0,0 @@
|
|||||||
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
|
|
@ -1 +0,0 @@
|
|||||||
uid://bc51go8t8uvts
|
|
20
player.gd
20
player.gd
@ -2,28 +2,22 @@ extends Node2D
|
|||||||
|
|
||||||
var _card_class = preload("res://card.gd")
|
var _card_class = preload("res://card.gd")
|
||||||
|
|
||||||
var card
|
|
||||||
|
|
||||||
func _on_request_completed(result, response_code, headers, body):
|
func _on_request_completed(result, response_code, headers, body):
|
||||||
var json = JSON.parse_string(body.get_string_from_utf8())
|
var json = JSON.parse_string(body.get_string_from_utf8())
|
||||||
print(json["name"])
|
print(json["name"])
|
||||||
|
|
||||||
func _test_func():
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready() -> void:
|
||||||
|
# TODO: Create 2-4 player instances as children of this tabletop node.
|
||||||
|
var card = _card_class.new("d3f10f07-7cfe-4a6f-8de6-373e367a731b")
|
||||||
|
add_child(card)
|
||||||
|
|
||||||
card.load_card()
|
card.load_card()
|
||||||
|
|
||||||
print(card.card_id)
|
print(card.card_id)
|
||||||
print(card.card_name)
|
print(card.card_name)
|
||||||
print(card.card_type)
|
print(card.card_type)
|
||||||
print(card.oracle_text)
|
print(card.oracle_text)
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready() -> void:
|
|
||||||
# TODO: Create 2-4 player instances as children of this tabletop node.
|
|
||||||
card = _card_class.new("d3f10f07-7cfe-4a6f-8de6-373e367a731b")
|
|
||||||
add_child(card)
|
|
||||||
|
|
||||||
card.cache_done.connect(_test_func)
|
|
||||||
|
|
||||||
pass # Replace with function body.
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
16
player.tscn
16
player.tscn
@ -1,8 +1,7 @@
|
|||||||
[gd_scene load_steps=4 format=3 uid="uid://cx0vga81xwckh"]
|
[gd_scene load_steps=3 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://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="2_onrkg"]
|
||||||
[ext_resource type="Script" uid="uid://b3yqd1qu7dyq" path="res://card.gd" id="3_i3pqv"]
|
|
||||||
|
|
||||||
[node name="Player" type="Node2D"]
|
[node name="Player" type="Node2D"]
|
||||||
script = ExtResource("1_4flbx")
|
script = ExtResource("1_4flbx")
|
||||||
@ -10,13 +9,8 @@ script = ExtResource("1_4flbx")
|
|||||||
[node name="Field" type="Node2D" parent="."]
|
[node name="Field" type="Node2D" parent="."]
|
||||||
|
|
||||||
[node name="Hand" type="Node2D" parent="."]
|
[node name="Hand" type="Node2D" parent="."]
|
||||||
|
|
||||||
[node name="Library" type="Node2D" parent="."]
|
|
||||||
script = ExtResource("2_onrkg")
|
script = ExtResource("2_onrkg")
|
||||||
|
|
||||||
[node name="TextureRect" type="TextureRect" parent="."]
|
[node name="Library" type="Node2D" parent="."]
|
||||||
offset_left = -1.0
|
|
||||||
offset_top = 1.0
|
[node name="HTTPRequest" type="HTTPRequest" parent="."]
|
||||||
offset_right = 39.0
|
|
||||||
offset_bottom = 41.0
|
|
||||||
script = ExtResource("3_i3pqv")
|
|
||||||
|
@ -3,5 +3,6 @@
|
|||||||
[ext_resource type="Script" uid="uid://cfkew150yl1y3" path="res://tabletop.gd" id="1_3we3x"]
|
[ext_resource type="Script" uid="uid://cfkew150yl1y3" path="res://tabletop.gd" id="1_3we3x"]
|
||||||
|
|
||||||
[node name="Tabletop" type="Node2D"]
|
[node name="Tabletop" type="Node2D"]
|
||||||
position = Vector2(-5760, -16768)
|
|
||||||
script = ExtResource("1_3we3x")
|
script = ExtResource("1_3we3x")
|
||||||
|
|
||||||
|
[node name="HTTPRequest" type="HTTPRequest" parent="."]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user