From 77da7cf6b2fa7e621d2ca759896b78bb8afbe011 Mon Sep 17 00:00:00 2001 From: ShyProton Date: Wed, 23 Apr 2025 18:05:38 -0400 Subject: [PATCH] wip: adding visual representation, starting with player battlefield --- field.gd | 34 ++++++++++++++++++++++++++++++++++ field.gd.uid | 1 + field.tscn | 18 ++++++++++++++++++ player.gd | 30 ++++++++++++++++-------------- player.tscn | 12 +----------- 5 files changed, 70 insertions(+), 25 deletions(-) create mode 100644 field.gd create mode 100644 field.gd.uid create mode 100644 field.tscn diff --git a/field.gd b/field.gd new file mode 100644 index 0000000..f08542a --- /dev/null +++ b/field.gd @@ -0,0 +1,34 @@ +extends TextureRect + +var _screen_size: Vector2 +var _colors: Array[Color] + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + _screen_size = get_viewport_rect().size + + # TODO: Calculate this field's scale and position based on which no# field this is. + # TODO: Method to take list of colors, split into this format of dictionary, and apply as gradient. + var gradient_data := { + 0.0: Color.MAROON, + 1.0: Color.MAROON, + } + + var gradient := Gradient.new() + gradient.offsets = gradient_data.keys() + gradient.colors = gradient_data.values() + + var gradient_texture = GradientTexture1D.new() + gradient_texture.gradient = gradient + # gradient_texture.width = _screen_size.x + + texture = gradient_texture + +func set_colors(colors: Array[Color]) -> void: + _colors = colors + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass diff --git a/field.gd.uid b/field.gd.uid new file mode 100644 index 0000000..ea4c820 --- /dev/null +++ b/field.gd.uid @@ -0,0 +1 @@ +uid://cqutu8u3qenu0 diff --git a/field.tscn b/field.tscn new file mode 100644 index 0000000..aabb214 --- /dev/null +++ b/field.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=3 format=3 uid="uid://clnevm4xcexrs"] + +[ext_resource type="Script" uid="uid://cqutu8u3qenu0" path="res://field.gd" id="1_6e7u2"] +[ext_resource type="Script" uid="uid://b3yqd1qu7dyq" path="res://card.gd" id="2_ujqnb"] + +[node name="Field" type="TextureRect"] +offset_top = 540.0 +offset_right = 1920.0 +offset_bottom = 1080.0 +script = ExtResource("1_6e7u2") + +[node name="Card" type="TextureRect" parent="."] +layout_mode = 0 +offset_left = -1.0 +offset_top = 1.0 +offset_right = 39.0 +offset_bottom = 41.0 +script = ExtResource("2_ujqnb") diff --git a/player.gd b/player.gd index 897f957..ff4f6fb 100644 --- a/player.gd +++ b/player.gd @@ -1,8 +1,9 @@ extends Node2D -var _card_class = preload("res://card.gd") +# var _card_class = preload("res://card.gd") -var card +var field_scene = preload("res://field.tscn") +var fields: Array[Node] = [] func _on_request_completed(result, response_code, headers, body): @@ -10,23 +11,24 @@ func _on_request_completed(result, response_code, headers, body): print(json["name"]) -func _test_func(): - card.load_card() - print(card.card_id) - print(card.card_name) - print(card.card_type) - print(card.oracle_text) +# func _test_func(): +# card.load_card() +# print(card.card_id) +# print(card.card_name) +# print(card.card_type) +# 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 = _card_class.new("d3f10f07-7cfe-4a6f-8de6-373e367a731b") + # add_child(card) + # card.cache_done.connect(_test_func) - card.cache_done.connect(_test_func) - - pass # Replace with function body. + fields.append(field_scene.instantiate()) + var colors: Array[Color] = [Color(1, 0, 1)] + fields[0].set_colors(colors) + add_child(fields[0]) # Called every frame. 'delta' is the elapsed time since the previous frame. diff --git a/player.tscn b/player.tscn index 605f046..f50248a 100644 --- a/player.tscn +++ b/player.tscn @@ -1,22 +1,12 @@ -[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://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") -[node name="Field" type="Node2D" parent="."] - [node name="Hand" type="Node2D" parent="."] [node name="Library" type="Node2D" parent="."] script = ExtResource("2_onrkg") - -[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")