Changes project to fullscreen 1920x1080, formats .gd files
This commit is contained in:
parent
4489eb5f76
commit
29042d5d05
35
card.gd
35
card.gd
@ -18,32 +18,38 @@ var oracle_text = "placeholder_oracle_text"
|
||||
var _png_path = "placeholder_image_path"
|
||||
var _jpg_path = "placeholder_image_path"
|
||||
|
||||
|
||||
func _card_error(error_type: String) -> String:
|
||||
return "CARD::" + card_id + "::" + error_type + "\n"
|
||||
|
||||
|
||||
func _init(id) -> void:
|
||||
card_id = id
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if (_check_cache(card_id)):
|
||||
if _check_cache(card_id):
|
||||
return
|
||||
await _do_cache_grab()
|
||||
|
||||
|
||||
func _do_cache_grab() -> void:
|
||||
await _do_http_request_card()
|
||||
await _do_http_request_imgs(_png_path, true)
|
||||
await _do_http_request_imgs(_jpg_path, false)
|
||||
cache_done.emit()
|
||||
|
||||
|
||||
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"):
|
||||
return false
|
||||
if (!FileAccess.file_exists("user://card_cache/" + id + "/card.png")):
|
||||
if !FileAccess.file_exists("user://card_cache/" + id + "/card.png"):
|
||||
return false
|
||||
if (!FileAccess.file_exists("user://card_cache/" + id + "/card.jpg")):
|
||||
if !FileAccess.file_exists("user://card_cache/" + id + "/card.jpg"):
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
func _do_http_request_imgs(image_path: String, png: bool) -> void:
|
||||
var httpr = HTTPRequest.new()
|
||||
add_child(httpr)
|
||||
@ -66,6 +72,7 @@ func _do_http_request_imgs(image_path: String, png: bool) -> void:
|
||||
img.save_png("user://card_cache/" + card_id + ("/card.png" if png else "/card.jpg"))
|
||||
img = null
|
||||
|
||||
|
||||
func _do_http_request_card() -> void:
|
||||
var httpr = HTTPRequest.new()
|
||||
add_child(httpr)
|
||||
@ -77,21 +84,22 @@ func _do_http_request_card() -> void:
|
||||
|
||||
var response = await httpr.request_completed
|
||||
|
||||
|
||||
if response[0] != HTTPRequest.RESULT_SUCCESS:
|
||||
push_error(_card_error("GET_REQUEST") + "Failed to fetch card data from Scryfall")
|
||||
return
|
||||
|
||||
var unprocessed_body = response[3].get_string_from_utf8()
|
||||
var card_content = JSON.parse_string(unprocessed_body)
|
||||
if (card_content == null):
|
||||
if card_content == null:
|
||||
push_error(_card_error("PARSING") + "Failed to parse the Scryfall card results.")
|
||||
|
||||
var dir = DirAccess.open("user://")
|
||||
dir.make_dir_recursive("user://card_cache/" + card_id + "/") # lets ensure the path is there
|
||||
dir = null
|
||||
|
||||
var card_cache = FileAccess.open("user://card_cache/" + card_id + "/card.json", FileAccess.WRITE)
|
||||
var card_cache = FileAccess.open(
|
||||
"user://card_cache/" + card_id + "/card.json", FileAccess.WRITE
|
||||
)
|
||||
card_cache.store_string(unprocessed_body) # cache the json response
|
||||
card_cache = null # closes the file
|
||||
|
||||
@ -99,6 +107,7 @@ func _do_http_request_card() -> void:
|
||||
_png_path = image_uris["png"]
|
||||
_jpg_path = image_uris["normal"]
|
||||
|
||||
|
||||
## load_card
|
||||
##
|
||||
## Loads the card, returns false, and triggers
|
||||
@ -107,11 +116,17 @@ func _do_http_request_card() -> void:
|
||||
func load_card() -> bool:
|
||||
if !_check_cache(card_id):
|
||||
await _do_cache_grab()
|
||||
push_error(_card_error("CACHE_FAIL") + "Cache wasn't ready, this card will need to be reinitialized")
|
||||
push_error(
|
||||
(
|
||||
_card_error("CACHE_FAIL")
|
||||
+ "Cache wasn't ready, this card will need to be reinitialized"
|
||||
)
|
||||
)
|
||||
return false
|
||||
|
||||
|
||||
var ondisk_card = FileAccess.open("user://card_cache/" + card_id + "/card.json", FileAccess.READ)
|
||||
var ondisk_card = FileAccess.open(
|
||||
"user://card_cache/" + card_id + "/card.json", FileAccess.READ
|
||||
)
|
||||
var card_json = JSON.parse_string(ondisk_card.get_as_text())
|
||||
|
||||
card_name = card_json["name"]
|
||||
|
11
data/mana.gd
11
data/mana.gd
@ -1,10 +1 @@
|
||||
enum ManaCosts {
|
||||
WHITE,
|
||||
BLUE,
|
||||
BLACK,
|
||||
RED,
|
||||
GREEN,
|
||||
COLOURLESS,
|
||||
GENERIC,
|
||||
LIFE
|
||||
}
|
||||
enum ManaCosts { WHITE, BLUE, BLACK, RED, GREEN, COLOURLESS, GENERIC, LIFE }
|
||||
|
@ -5,9 +5,11 @@ 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
|
||||
@ -17,19 +19,23 @@ func _init(card_ids: Array) -> void:
|
||||
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:
|
||||
|
@ -4,10 +4,12 @@ var _card_class = preload("res://card.gd")
|
||||
|
||||
var card
|
||||
|
||||
|
||||
func _on_request_completed(result, response_code, headers, body):
|
||||
var json = JSON.parse_string(body.get_string_from_utf8())
|
||||
print(json["name"])
|
||||
|
||||
|
||||
func _test_func():
|
||||
card.load_card()
|
||||
print(card.card_id)
|
||||
|
@ -15,6 +15,12 @@ run/main_scene="uid://b4ldtb3gw0jlu"
|
||||
config/features=PackedStringArray("4.4", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=1920
|
||||
window/size/viewport_height=1080
|
||||
window/size/mode=3
|
||||
|
||||
[editor_plugins]
|
||||
|
||||
enabled=PackedStringArray("res://addons/godot_vim/plugin.cfg")
|
||||
enabled=PackedStringArray()
|
||||
|
@ -3,7 +3,6 @@ extends Node2D
|
||||
var player_class = preload("res://player.gd")
|
||||
|
||||
|
||||
|
||||
# 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.
|
||||
|
@ -3,5 +3,4 @@
|
||||
[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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user