You can now play cards!

- Fixed invalid scripts
- Added card placement validation

Co-Authored-By: deranonymos <deranonymos@users.noreply.github.com>
This commit is contained in:
2020-04-20 01:06:26 +02:00
parent 32ccb24012
commit 1544bf6feb
8 changed files with 83 additions and 79 deletions

View File

@@ -0,0 +1,3 @@
extends Control
export var ObjectParent:NodePath

View File

@@ -7,19 +7,14 @@
[ext_resource path="res://Objects/Traps/Bear/bear.jpg" type="Texture" id=5]
[ext_resource path="res://Objects/Traps/bear.tscn" type="PackedScene" id=6]
[ext_resource path="res://Objects/Traps/Bear/Animation/0012.png" type="Texture" id=7]
[sub_resource type="GDScript" id=1]
script/source = "extends Control
export var ObjectParent:NodePath
"
[ext_resource path="res://Menus/DragNDrop/DragNDropUI.gd" type="Script" id=8]
[node name="DragNDropUI" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = -0.37735
margin_right = -0.37735
script = SubResource( 1 )
script = ExtResource( 8 )
__meta__ = {
"_edit_use_anchors_": false
}

View File

@@ -0,0 +1,30 @@
extends Container
const Grid = preload("res://Maps/Grid.gd")
onready var grid = get_tree().current_scene.get_node("Grid")
onready var ysort = get_tree().current_scene.get_node("YSort")
#DropZone
#stuff can be dropped here
func can_drop_data(_pos, data):
return typeof(data) == typeof(PackedScene)
func get_nearest_grid_pos(position):
return Vector2(round(position.x / 32.0), round(position.y / 32.0))
func get_nearest_global_pos(position):
return Vector2(round(position.x / 32.0) * 32, round(position.y / 32.0) * 32)
#what is to be done when data is dropped
func drop_data(_pos, data:PackedScene):
var new_pos = get_nearest_grid_pos(_pos)
if grid.object_grid[new_pos.x - 1][new_pos.y - 1].back() == Grid.Kind.FIELD:
var child = data.instance()
child.position = get_nearest_global_pos(_pos)
ysort.add_child(child)
grid._update_grid()

View File

@@ -1,31 +1,12 @@
[gd_scene load_steps=2 format=2]
[sub_resource type="GDScript" id=1]
script/source = "extends Container
#DropZone
#stuff can be dropped here
func can_drop_data(_pos, data):
return typeof(data) == typeof(PackedScene)
func get_nearest_grid_pos(position):
return Vector2(floor(position.x / 32.0) * 32, floor(position.y / 32.0) * 32)
#what is to be done when data is dropped
func drop_data(_pos, data:PackedScene):
var child = data.instance()
child.position = get_nearest_grid_pos(_pos)
get_node(get_parent().ObjectParent).add_child(child)
"
[ext_resource path="res://Menus/DragNDrop/DragSink.gd" type="Script" id=1]
[node name="DragSink" type="Container"]
anchor_right = 1.0
anchor_bottom = 0.789
margin_bottom = -0.0200043
script = SubResource( 1 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

View File

@@ -0,0 +1,36 @@
extends TextureRect
#CardDeck
export var Item:PackedScene
export var PreviewIcon:Texture
export var DeleteOnGrab:bool = false
#if a drag is initiated here
func get_drag_data(_pos):
var ctrl = Control.new()
var TR = TextureRect.new()
TR.texture = get_resized_texture(PreviewIcon,self.rect_size[0],self.rect_size[1])
TR.rect_size= self.rect_size
TR.set_position(_pos*-1,false)
ctrl.add_child(TR)
set_drag_preview(ctrl)
if DeleteOnGrab :
self.queue_free()
return Item
#stuff can be dropped here
#eg you picked the wrong thing up, let go and it returns to nothingness
func can_drop_data(_pos, data):
return typeof(data) == typeof(PackedScene)
#do nothing if stuff is dropped here
func drop_data(_pos, _data):
pass
func get_resized_texture(t: Texture, width: int = 0, height: int = 0):
var image = t.get_data()
if width > 0 && height > 0:
image.resize(width, height)
var itex = ImageTexture.new()
itex.create_from_image(image,0)
return itex

View File

@@ -2,45 +2,7 @@
[ext_resource path="res://icon.png" type="Texture" id=1]
[ext_resource path="res://Objects/Card/card.png" type="Texture" id=2]
[sub_resource type="GDScript" id=1]
script/source = "extends TextureRect
#CardDeck
export var Item:PackedScene
export var PreviewIcon:Texture
export var DeleteOnGrab:bool = false
#if a drag is initiated here
func get_drag_data(_pos):
var ctrl = Control.new()
var TR = TextureRect.new()
TR.texture = get_resized_texture(PreviewIcon,self.rect_size[0],self.rect_size[1])
TR.rect_size= self.rect_size
TR.set_position(_pos*-1,false)
ctrl.add_child(TR)
set_drag_preview(ctrl)
if DeleteOnGrab :
self.queue_free()
return Item
#stuff can be dropped here
#eg you picked the wrong thing up, let go and it returns to nothingness
func can_drop_data(_pos, data):
return typeof(data) == typeof(PackedScene)
#do nothing if stuff is dropped here
func drop_data(_pos, _data):
pass
func get_resized_texture(t: Texture, width: int = 0, height: int = 0):
var image = t.get_data()
if width > 0 && height > 0:
image.resize(width, height)
var itex = ImageTexture.new()
itex.create_from_image(image,0)
return itex
"
[ext_resource path="res://Menus/DragNDrop/DragSource.gd" type="Script" id=3]
[node name="DragSource" type="TextureRect"]
margin_left = 10.7364
@@ -49,11 +11,10 @@ margin_right = 42.7364
margin_bottom = 259.792
texture = ExtResource( 1 )
expand = true
script = SubResource( 1 )
script = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}
PreviewIcon = ExtResource( 1 )
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 16.0791, 16.0117 )