Added card fetching/caching, support for problem cards
This commit is contained in:
parent
6b996285a3
commit
0feb249439
16 changed files with 143 additions and 41 deletions
|
@ -21,9 +21,9 @@ compress/lossy_quality=0.8
|
|||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=true
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/mipmaps=true
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=1
|
||||
process/fix_alpha_border=true
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 22 KiB |
9
MLPAssets/Placeholders/CardMat.tres
Normal file
9
MLPAssets/Placeholders/CardMat.tres
Normal file
|
@ -0,0 +1,9 @@
|
|||
[gd_resource type="SpatialMaterial" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://MLPAssets/Placeholders/unknowncard.jpg" type="Texture" id=1]
|
||||
|
||||
[resource]
|
||||
flags_unshaded = true
|
||||
albedo_texture = ExtResource( 1 )
|
||||
uv1_scale = Vector3( 0.9, 0.9, 1 )
|
||||
uv1_offset = Vector3( 0.05, 0.05, 0 )
|
BIN
MLPAssets/Placeholders/unknowncard.jpg
Normal file
BIN
MLPAssets/Placeholders/unknowncard.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 103 KiB |
|
@ -2,8 +2,8 @@
|
|||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path.s3tc="res://.import/ff6.jpg-e066dece7da740f732cd9a31f65091eb.s3tc.stex"
|
||||
path.etc="res://.import/ff6.jpg-e066dece7da740f732cd9a31f65091eb.etc.stex"
|
||||
path.s3tc="res://.import/unknowncard.jpg-ff165d2aeb957f4e1010ac777150182d.s3tc.stex"
|
||||
path.etc="res://.import/unknowncard.jpg-ff165d2aeb957f4e1010ac777150182d.etc.stex"
|
||||
metadata={
|
||||
"imported_formats": [ "s3tc", "etc" ],
|
||||
"vram_texture": true
|
||||
|
@ -11,8 +11,8 @@ metadata={
|
|||
|
||||
[deps]
|
||||
|
||||
source_file="res://MLPAssets/ExampleCard/ff6.jpg"
|
||||
dest_files=[ "res://.import/ff6.jpg-e066dece7da740f732cd9a31f65091eb.s3tc.stex", "res://.import/ff6.jpg-e066dece7da740f732cd9a31f65091eb.etc.stex" ]
|
||||
source_file="res://MLPAssets/Placeholders/unknowncard.jpg"
|
||||
dest_files=[ "res://.import/unknowncard.jpg-ff165d2aeb957f4e1010ac777150182d.s3tc.stex", "res://.import/unknowncard.jpg-ff165d2aeb957f4e1010ac777150182d.etc.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
|
@ -25,7 +25,7 @@ flags/repeat=true
|
|||
flags/filter=true
|
||||
flags/mipmaps=true
|
||||
flags/anisotropic=false
|
||||
flags/srgb=1
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
|
@ -2,15 +2,17 @@
|
|||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/CardBack.png-c3e28c09100eabc5562ed76709826ce0.stex"
|
||||
path.s3tc="res://.import/CardBack.png-c3e28c09100eabc5562ed76709826ce0.s3tc.stex"
|
||||
path.etc="res://.import/CardBack.png-c3e28c09100eabc5562ed76709826ce0.etc.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
"imported_formats": [ "s3tc", "etc" ],
|
||||
"vram_texture": true
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://MLPAssets/Textures/CardBack.png"
|
||||
dest_files=[ "res://.import/CardBack.png-c3e28c09100eabc5562ed76709826ce0.stex" ]
|
||||
dest_files=[ "res://.import/CardBack.png-c3e28c09100eabc5562ed76709826ce0.s3tc.stex", "res://.import/CardBack.png-c3e28c09100eabc5562ed76709826ce0.etc.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
|
@ -19,9 +21,9 @@ compress/lossy_quality=0.7
|
|||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=true
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/mipmaps=true
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=1
|
||||
process/fix_alpha_border=true
|
||||
|
|
|
@ -34,21 +34,33 @@ material/0 = null
|
|||
|
||||
[node name="Cards" type="Spatial" parent="."]
|
||||
|
||||
[node name="Deck" parent="Cards" instance=ExtResource( 5 )]
|
||||
[node name="P1Deck" parent="Cards" instance=ExtResource( 5 )]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.30889, 0, 3.52858 )
|
||||
title = "Deck"
|
||||
zoneName = "player1.deck"
|
||||
faceDown = true
|
||||
|
||||
[node name="Graveyard" parent="Cards" instance=ExtResource( 5 )]
|
||||
[node name="P1Graveyard" parent="Cards" instance=ExtResource( 5 )]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5.23371, 0, 3.52858 )
|
||||
title = "Graveyard"
|
||||
zoneName = "player1.graveyard"
|
||||
|
||||
[node name="Banished" parent="Cards" instance=ExtResource( 5 )]
|
||||
[node name="P1Banished" parent="Cards" instance=ExtResource( 5 )]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5.23371, 0, 2.40401 )
|
||||
title = "Banished"
|
||||
zoneName = "player1.banished"
|
||||
[connection signal="card_picked" from="Cards/Deck" to="." method="_card_picked_zone" binds= [ "player1.deck" ]]
|
||||
[connection signal="card_picked" from="Cards/Graveyard" to="." method="_card_picked_zone" binds= [ "player1.graveyard" ]]
|
||||
[connection signal="card_picked" from="Cards/Banished" to="." method="_card_picked_zone" binds= [ "player1.banished" ]]
|
||||
|
||||
[node name="P1Problem" parent="Cards" instance=ExtResource( 5 )]
|
||||
transform = Transform( -4.37114e-008, 0, -1, 0, 1, 0, 1, 0, -4.37114e-008, 2.5, 0, 0 )
|
||||
title = "Problem"
|
||||
zoneName = "player1.problem"
|
||||
|
||||
[node name="P2Problem" parent="Cards" instance=ExtResource( 5 )]
|
||||
transform = Transform( -4.37114e-008, 0, 1, 0, 1, 0, -1, 0, -4.37114e-008, -2.5, 0, 0 )
|
||||
title = "Problem"
|
||||
zoneName = "player2.problem"
|
||||
[connection signal="card_picked" from="Cards/P1Deck" to="." method="_card_picked_zone" binds= [ "player1.deck" ]]
|
||||
[connection signal="card_picked" from="Cards/P1Graveyard" to="." method="_card_picked_zone" binds= [ "player1.graveyard" ]]
|
||||
[connection signal="card_picked" from="Cards/P1Banished" to="." method="_card_picked_zone" binds= [ "player1.banished" ]]
|
||||
[connection signal="card_picked" from="Cards/P1Problem" to="." method="_card_picked_zone" binds= [ "player1.graveyard" ]]
|
||||
[connection signal="card_picked" from="Cards/P2Problem" to="." method="_card_picked_zone" binds= [ "player1.graveyard" ]]
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Scenes/Scripts/BoardUI.gd" type="Script" id=1]
|
||||
[ext_resource path="res://MLPAssets/ExampleCard/ff6.jpg" type="Texture" id=2]
|
||||
[ext_resource path="res://MLPAssets/Placeholders/unknowncard.jpg" type="Texture" id=2]
|
||||
|
||||
[sub_resource type="Animation" id=1]
|
||||
resource_name = "fade ui card"
|
||||
length = 0.1
|
||||
step = 0.01
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("TextureRect:visible")
|
||||
tracks/0/path = NodePath("CardZoom:visible")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
|
@ -20,7 +20,7 @@ tracks/0/keys = {
|
|||
"values": [ false, true ]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/path = NodePath("TextureRect:modulate")
|
||||
tracks/1/path = NodePath("CardZoom:modulate")
|
||||
tracks/1/interp = 2
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
|
@ -32,7 +32,7 @@ tracks/1/keys = {
|
|||
"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/path = NodePath("TextureRect:margin_top")
|
||||
tracks/2/path = NodePath("CardZoom:margin_top")
|
||||
tracks/2/interp = 2
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/imported = false
|
||||
|
@ -50,7 +50,7 @@ anchor_bottom = 1.0
|
|||
mouse_filter = 2
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
[node name="CardZoom" type="TextureRect" parent="."]
|
||||
visible = false
|
||||
modulate = Color( 1, 1, 1, 0 )
|
||||
margin_left = 40.0
|
||||
|
|
|
@ -13,13 +13,26 @@ var clicked := false
|
|||
var exhausted := false
|
||||
var lifted := false
|
||||
var flipped := false
|
||||
var cardID := ""
|
||||
var cardID := "" setget set_cardid
|
||||
var playerID := 0
|
||||
var inHand := false
|
||||
var inZone := false
|
||||
var zoneName = ""
|
||||
var cardMat = preload("res://MLPAssets/Placeholders/CardMat.tres")
|
||||
var ready = false
|
||||
|
||||
onready var animation := $CardModel/Border/AnimationPlayer
|
||||
onready var cardImage := $CardModel/Border/CardImage
|
||||
onready var texture: Texture = cardImage.get_surface_material(0)
|
||||
|
||||
func set_cardid(val: String):
|
||||
cardID = val
|
||||
if ready:
|
||||
Remote.fetch(Remote.IMGURL + val + ".jpg", self, "_card_fetched")
|
||||
|
||||
func _ready():
|
||||
Remote.fetch(Remote.IMGURL + cardID + ".jpg", self, "_card_fetched")
|
||||
ready = true
|
||||
|
||||
func _mouse_hover():
|
||||
emit_signal("card_selected")
|
||||
|
@ -27,6 +40,7 @@ func _mouse_hover():
|
|||
func _mouse_blur():
|
||||
emit_signal("card_unselected")
|
||||
|
||||
# warning-ignore:unused_argument
|
||||
func _input_event(camera, event, click_position, click_normal, shape_idx):
|
||||
# Mouse motion
|
||||
if clicked and event is InputEventMouseMotion:
|
||||
|
@ -113,4 +127,23 @@ func disableInput():
|
|||
$CollisionShape.disabled = true
|
||||
|
||||
func enableInput():
|
||||
$CollisionShape.disabled = false
|
||||
$CollisionShape.disabled = false
|
||||
|
||||
# warning-ignore:unused_argument
|
||||
func _card_fetched(result: int, response_code: int, headers: PoolStringArray, body: PoolByteArray):
|
||||
assert(result == HTTPRequest.RESULT_SUCCESS)
|
||||
var img = Image.new()
|
||||
var err = img.load_jpg_from_buffer(body)
|
||||
# Depending if card pic is a problem or not, rotate the card image mesh
|
||||
if img.get_width() > img.get_height():
|
||||
cardImage.scale = Vector3(0.45,1,0.319)
|
||||
cardImage.rotation.y = PI/2
|
||||
else:
|
||||
cardImage.scale = Vector3(0.319,1,0.45)
|
||||
cardImage.rotation.y = 0
|
||||
assert(err == OK)
|
||||
var mat = cardMat.duplicate()
|
||||
texture = ImageTexture.new()
|
||||
texture.create_from_image(img)
|
||||
mat.albedo_texture = texture
|
||||
cardImage.set_surface_material(0, mat)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
[gd_scene load_steps=14 format=2]
|
||||
[gd_scene load_steps=13 format=2]
|
||||
|
||||
[ext_resource path="res://Scenes/Components/Card.gd" type="Script" id=1]
|
||||
[ext_resource path="res://MLPAssets/Models/cardborder.obj" type="ArrayMesh" id=2]
|
||||
[ext_resource path="res://MLPAssets/Models/cardborder.material" type="Material" id=3]
|
||||
[ext_resource path="res://MLPAssets/ExampleCard/ff6.jpg" type="Texture" id=4]
|
||||
[ext_resource path="res://MLPAssets/Placeholders/CardMat.tres" type="Material" id=4]
|
||||
|
||||
[sub_resource type="BoxShape" id=1]
|
||||
margin = 0.001
|
||||
|
@ -127,12 +127,6 @@ tracks/0/keys = {
|
|||
|
||||
[sub_resource type="PlaneMesh" id=8]
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=9]
|
||||
flags_unshaded = true
|
||||
albedo_texture = ExtResource( 4 )
|
||||
uv1_scale = Vector3( 0.9, 0.9, 1 )
|
||||
uv1_offset = Vector3( 0.05, 0.05, 0 )
|
||||
|
||||
[node name="Card" type="Area"]
|
||||
input_capture_on_drag = true
|
||||
script = ExtResource( 1 )
|
||||
|
@ -158,7 +152,7 @@ anims/tap = SubResource( 7 )
|
|||
[node name="CardImage" type="MeshInstance" parent="CardModel/Border"]
|
||||
transform = Transform( 0.318962, 0, 0, 0, 1, 0, 0, 0, 0.450381, 0, 0.009, 0 )
|
||||
mesh = SubResource( 8 )
|
||||
material/0 = SubResource( 9 )
|
||||
material/0 = ExtResource( 4 )
|
||||
|
||||
[node name="Tween" type="Tween" parent="."]
|
||||
[connection signal="input_event" from="." to="." method="_input_event"]
|
||||
|
|
|
@ -62,7 +62,7 @@ align = 1
|
|||
valign = 1
|
||||
|
||||
[node name="LabelSprite" type="Sprite3D" parent="."]
|
||||
transform = Transform( 0.5853, 0.810817, -3.54419e-008, 0, -4.37114e-008, -1, -0.810817, 0.5853, -2.55843e-008, 1.05839e-009, 0.0298628, 7.64017e-010 )
|
||||
transform = Transform( 0.5853, 0.810817, -3.54419e-008, 0, -4.37114e-008, -1, -0.810817, 0.5853, -2.55843e-008, 0, 0, 0 )
|
||||
texture = SubResource( 4 )
|
||||
region_rect = Rect2( 0, 0, 30, 30 )
|
||||
[connection signal="mouse_entered" from="." to="." method="_mouse_entered"]
|
||||
|
|
36
Scenes/Global/Remote.gd
Normal file
36
Scenes/Global/Remote.gd
Normal file
|
@ -0,0 +1,36 @@
|
|||
extends Node
|
||||
|
||||
const HOST = "https://mlpccg.zyg.ovh/"
|
||||
const IMGURL = HOST + "images/cards/"
|
||||
|
||||
func res_file_name(url: String) -> String:
|
||||
return "user://" + url.trim_prefix(HOST).replace("/","_")
|
||||
|
||||
func fetch(url: String, cbObj: Object, cbFn: String):
|
||||
# Check for cached resource
|
||||
var file := File.new()
|
||||
var fname := res_file_name(url)
|
||||
# Return cached resource if available
|
||||
if file.file_exists(fname):
|
||||
file.open(fname, File.READ)
|
||||
var flen := file.get_len()
|
||||
var buf := file.get_buffer(flen)
|
||||
cbObj.call(cbFn, HTTPRequest.RESULT_SUCCESS, 200, [], buf)
|
||||
print("CACHED")
|
||||
return
|
||||
var req := HTTPRequest.new()
|
||||
add_child(req)
|
||||
req.connect("request_completed", self, "_request_completed", [url, cbObj, cbFn])
|
||||
req.request(url)
|
||||
|
||||
func _request_completed(result: int, response_code: int, headers: PoolStringArray, body: PoolByteArray, url: String, cbObj: Object, cbFn: String):
|
||||
# Cache result for later
|
||||
if result == HTTPRequest.RESULT_SUCCESS:
|
||||
# Get file name by trimming the host
|
||||
var file := File.new()
|
||||
file.open(res_file_name(url), File.WRITE)
|
||||
file.store_buffer(body)
|
||||
file.close()
|
||||
print("SAVED")
|
||||
# Call callback
|
||||
cbObj.call(cbFn, result, response_code, headers, body)
|
6
Scenes/Global/Remote.tscn
Normal file
6
Scenes/Global/Remote.tscn
Normal file
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://Scenes/Global/Remote.gd" type="Script" id=1]
|
||||
|
||||
[node name="Remote" type="Node"]
|
||||
script = ExtResource( 1 )
|
|
@ -21,15 +21,19 @@ var lastCameraTransform: Transform
|
|||
onready var zones: Dictionary = {
|
||||
"player1.deck": $Cards/Deck,
|
||||
"player1.banished": $Cards/Banished,
|
||||
"player1.graveyard": $Cards/Graveyard
|
||||
"player1.graveyard": $Cards/Graveyard,
|
||||
"player1.problem": $Cards/P1Problem,
|
||||
"player2.problem": $Cards/P2Problem
|
||||
}
|
||||
|
||||
func _ready():
|
||||
add_card("ff36", 0, false)
|
||||
add_card("ff36", 0, true)
|
||||
add_card("ff36", 0, true)
|
||||
add_card("ff36", 0, true)
|
||||
add_card("ff36", 0, true)
|
||||
add_card("pr10", 0, false)
|
||||
add_card("ff33", 0, true)
|
||||
add_card("ff100", 0, true)
|
||||
add_card("ff44", 0, true)
|
||||
add_card("eo11", 0, true)
|
||||
add_card("pr168", 0, true)
|
||||
add_card("ad176", 0, true)
|
||||
reorder_hand()
|
||||
|
||||
func _input(event: InputEvent):
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
extends Control
|
||||
|
||||
onready var animation = $AnimationPlayer
|
||||
onready var cardPic = $CardZoom
|
||||
|
||||
var menu: PopupMenu = null
|
||||
|
||||
func _card_selected(card: Card):
|
||||
cardPic.texture = card.texture
|
||||
animation.play("fade ui card")
|
||||
|
||||
func _card_unselected(card: Card):
|
||||
|
|
|
@ -36,6 +36,10 @@ config/name="MLP CARD GAME"
|
|||
run/main_scene="res://Scenes/Board.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[autoload]
|
||||
|
||||
Remote="*res://Scenes/Global/Remote.tscn"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/width=1280
|
||||
|
|
Loading…
Reference in a new issue