diff --git a/.vs/ProjectEvaluation/tiermaker.metadata.v7.bin b/.vs/ProjectEvaluation/tiermaker.metadata.v7.bin new file mode 100644 index 0000000..ecbb11a Binary files /dev/null and b/.vs/ProjectEvaluation/tiermaker.metadata.v7.bin differ diff --git a/.vs/ProjectEvaluation/tiermaker.projects.v7.bin b/.vs/ProjectEvaluation/tiermaker.projects.v7.bin new file mode 100644 index 0000000..63dc505 Binary files /dev/null and b/.vs/ProjectEvaluation/tiermaker.projects.v7.bin differ diff --git a/.vs/TIERMAKER/DesignTimeBuild/.dtbcache.v2 b/.vs/TIERMAKER/DesignTimeBuild/.dtbcache.v2 new file mode 100644 index 0000000..5864135 Binary files /dev/null and b/.vs/TIERMAKER/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/TIERMAKER/FileContentIndex/119fa0ee-0754-40a1-a652-10dfb23fb072.vsidx b/.vs/TIERMAKER/FileContentIndex/119fa0ee-0754-40a1-a652-10dfb23fb072.vsidx new file mode 100644 index 0000000..91fb225 Binary files /dev/null and b/.vs/TIERMAKER/FileContentIndex/119fa0ee-0754-40a1-a652-10dfb23fb072.vsidx differ diff --git a/.vs/TIERMAKER/v17/.futdcache.v2 b/.vs/TIERMAKER/v17/.futdcache.v2 new file mode 100644 index 0000000..ab259a3 Binary files /dev/null and b/.vs/TIERMAKER/v17/.futdcache.v2 differ diff --git a/.vs/TIERMAKER/v17/.suo b/.vs/TIERMAKER/v17/.suo new file mode 100644 index 0000000..852006d Binary files /dev/null and b/.vs/TIERMAKER/v17/.suo differ diff --git a/.vs/TIERMAKER/v17/DocumentLayout.json b/.vs/TIERMAKER/v17/DocumentLayout.json new file mode 100644 index 0000000..957ab84 --- /dev/null +++ b/.vs/TIERMAKER/v17/DocumentLayout.json @@ -0,0 +1,37 @@ +{ + "Version": 1, + "WorkspaceRootPath": "C:\\Users\\Cameron\\Godot\\TierMaker\\", + "Documents": [ + { + "AbsoluteMoniker": "D:0:0:{08AED6D9-4B08-4196-8211-B04CD7ED8440}|TierMaker.csproj|c:\\users\\cameron\\godot\\tiermaker\\cardsprite.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "RelativeMoniker": "D:0:0:{08AED6D9-4B08-4196-8211-B04CD7ED8440}|TierMaker.csproj|solutionrelative:cardsprite.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" + } + ], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [ + { + "DockedWidth": 193, + "SelectedChildIndex": 0, + "Children": [ + { + "$type": "Document", + "DocumentIndex": 0, + "Title": "CardSprite.cs", + "DocumentMoniker": "C:\\Users\\Cameron\\Godot\\TierMaker\\CardSprite.cs", + "RelativeDocumentMoniker": "CardSprite.cs", + "ToolTip": "C:\\Users\\Cameron\\Godot\\TierMaker\\CardSprite.cs", + "RelativeToolTip": "CardSprite.cs", + "ViewState": "AQIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", + "WhenOpened": "2024-04-14T23:28:03.053Z", + "EditorCaption": "" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/CardShape.cs b/CardShape.cs new file mode 100644 index 0000000..dea8f5c --- /dev/null +++ b/CardShape.cs @@ -0,0 +1,23 @@ +using Godot; +using System; + +public partial class CardShape : CollisionShape2D, IUsesCardSize +{ + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + } + + // Called every frame. 'delta' is the elapsed time since the previous frame. + public override void _Process(double delta) + { + } + + public void UpdateCardSize(Vector2 size) + { + Shape = new RectangleShape2D + { + Size = size + }; + } +} diff --git a/CardSprite.cs b/CardSprite.cs new file mode 100644 index 0000000..29579e4 --- /dev/null +++ b/CardSprite.cs @@ -0,0 +1,24 @@ +using Godot; +using System; + +public partial class CardSprite : Sprite2D, IUsesCardSize +{ + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + //set scale for default color + // if (GetParent()?.Shape is RectangleShape2D rect) + // Scale = rect.Size; + } + + // Called every frame. 'delta' is the elapsed time since the previous frame. + public override void _Process(double delta) + { + } + + public void UpdateCardSize(Vector2 size) + { + var s = Texture.GetSize(); + Scale = new Vector2(size.X / s.X, size.Y / s.Y); + } +} diff --git a/Extensions.cs b/Extensions.cs new file mode 100644 index 0000000..5f6cc8b --- /dev/null +++ b/Extensions.cs @@ -0,0 +1,55 @@ +using System.Collections.Generic; +using Godot; + +public static class ExtensionHelper +{ + public static Card GetCardWithId(this SceneTree tree, string id) + { + const string CardGroup = "Card"; + var cards = tree.GetNodesInGroup(CardGroup); + foreach (var card in cards) + { + if (card is Card c) + { + if (c.Id == id) + return c; + } + else + throw new System.Exception($"Node in group {CardGroup} is not of type {nameof(Card)}"); + } + return null; + } + public static Row GetRowWithId(this SceneTree tree, string id) + { + const string RowGroup = "Card"; + var rows = tree.GetNodesInGroup(RowGroup); + foreach (var row in rows) + { + if (row is Row r) + { + if (r.Id == id) + return r; + } + else + throw new System.Exception($"Node in group {RowGroup} is not of type {nameof(Row)}"); + } + return null; + } + public static IEnumerable GetAllDescendents(this Node node, bool includeInternal = false) + { + foreach (Node n in node.GetChildren(includeInternal)) + { + yield return n; + foreach (Node c in n.GetAllDescendents()) + yield return c; + } + } + // gets all descendents of a given type (in undefined order) + public static IEnumerable GetAllDescendents(this Node node, + bool includeInternal = false) + { + foreach (var n in node.GetAllDescendents(includeInternal)) + if (n is T t) + yield return t; + } +} diff --git a/IdLabel.cs b/IdLabel.cs new file mode 100644 index 0000000..5b162b1 --- /dev/null +++ b/IdLabel.cs @@ -0,0 +1,26 @@ +using Godot; +using System; + +public partial class IdLabel : Label, IUsesCardId, IUsesCardSize +{ + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + } + + // Called every frame. 'delta' is the elapsed time since the previous frame. + public override void _Process(double delta) + { + } + public void UpdateCardId(string id) + { + Text = id; + } + //doesn't resize, but realigns + public void UpdateCardSize(Vector2 size) + { + var parentBottomLeft = new Vector2(-size.X, size.Y) / 2; + var thisBottomLeft = new Vector2(0, Size.Y); + Position = parentBottomLeft - thisBottomLeft; + } +} diff --git a/CardCollisionShape2D.cs b/Row.cs similarity index 71% rename from CardCollisionShape2D.cs rename to Row.cs index a466e27..9f0fbb6 100644 --- a/CardCollisionShape2D.cs +++ b/Row.cs @@ -1,13 +1,13 @@ using Godot; using System; -public partial class CardCollisionShape2D : CollisionShape2D +public partial class Row : Area2D { - private Vector2 MouseOffset { get; set; } + [Export] + public string Id { get; set; } // Called when the node enters the scene tree for the first time. public override void _Ready() { - } // Called every frame. 'delta' is the elapsed time since the previous frame. diff --git a/Sprites/SingleWhitePixel.png b/Sprites/SingleWhitePixel.png new file mode 100644 index 0000000..818c71d Binary files /dev/null and b/Sprites/SingleWhitePixel.png differ diff --git a/Sprites/SingleWhitePixel.png.import b/Sprites/SingleWhitePixel.png.import new file mode 100644 index 0000000..7883fd7 --- /dev/null +++ b/Sprites/SingleWhitePixel.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b8acjd4lvei07" +path="res://.godot/imported/SingleWhitePixel.png-24ae9a98b3e2a24518720903e0c57636.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/SingleWhitePixel.png" +dest_files=["res://.godot/imported/SingleWhitePixel.png-24ae9a98b3e2a24518720903e0c57636.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/card.cs b/card.cs index 63a2fcf..55a47fc 100644 --- a/card.cs +++ b/card.cs @@ -1,23 +1,61 @@ using Godot; using System; +using System.Drawing; -public partial class card : Area2D +public partial class Card : Area2D { private Vector2 MouseOffset { get; set; } + public Vector2 _Size; + [Export] + public Vector2 Size + { + get => _Size; + set + { + _Size = value; + UpdateChildrenSize(value); + } + } + public CollisionShape2D CollisionObject + => GetNode("CollisionShape2D"); + public string _Id; + [Export] + public string Id + { + get => _Id; + set + { + _Id = value; + UpdateChildrenId(value); + } + } + protected void UpdateChildrenId(string id) + { + foreach (var child in this.GetAllDescendents()) + child.UpdateCardId(id); + } + protected void UpdateChildrenSize(Vector2 size) + { + foreach (var child in this.GetAllDescendents()) + child.UpdateCardSize(size); + } + //private Theme CardTheme = GD.Load("res://card_theme.tres"); // Called when the node enters the scene tree for the first time. public override void _Ready() { InputPickable = true; //TODO worry about dragging later, websocket control is more important //InputEvent += MouseClick; + UpdateChildrenId(_Id); } // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { + } - private void MouseClick(Node viewport, InputEvent @event, long shapeIdx) + private static void MouseClick(Node viewport, InputEvent @event, long shapeIdx) { if (@event is InputEventMouse mouseEvent) { @@ -32,3 +70,13 @@ public partial class card : Area2D } } } + +public interface IUsesCardId +{ + public void UpdateCardId(string id); +} + +public interface IUsesCardSize +{ + public void UpdateCardSize(Vector2 size); +} \ No newline at end of file diff --git a/card.tscn b/card.tscn index b7b1a78..7b65c40 100644 --- a/card.tscn +++ b/card.tscn @@ -1,10 +1,39 @@ -[gd_scene load_steps=2 format=3 uid="uid://bcmgf041scwb4"] +[gd_scene load_steps=8 format=3 uid="uid://bcmgf041scwb4"] + +[ext_resource type="Script" path="res://Card.cs" id="1_sy5mp"] +[ext_resource type="Texture2D" uid="uid://b8acjd4lvei07" path="res://Sprites/SingleWhitePixel.png" id="2_v2iad"] +[ext_resource type="Script" path="res://CardShape.cs" id="2_w7o1r"] +[ext_resource type="Script" path="res://CardSprite.cs" id="3_0aoyx"] +[ext_resource type="Script" path="res://IdLabel.cs" id="4_0khjp"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_25ape"] +size = Vector2(1, 1) -[node name="Card" type="Area2D"] +[sub_resource type="LabelSettings" id="LabelSettings_vre1j"] +outline_size = 1 +outline_color = Color(0, 0, 0, 1) -[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +[node name="Card" type="Area2D" groups=["Card"]] +script = ExtResource("1_sy5mp") +Size = Vector2(150, 150) + +[node name="CardShape" type="CollisionShape2D" parent="."] shape = SubResource("RectangleShape2D_25ape") +script = ExtResource("2_w7o1r") -[node name="Sprite2D" type="Sprite2D" parent="."] +[node name="IdLabel" type="Label" parent="CardShape"] +anchors_preset = 2 +anchor_top = 1.0 +anchor_bottom = 1.0 +offset_top = -23.0 +offset_right = 40.0 +grow_vertical = 0 +text = "A1" +label_settings = SubResource("LabelSettings_vre1j") +vertical_alignment = 2 +script = ExtResource("4_0khjp") + +[node name="CardSprite" type="Sprite2D" parent="CardShape"] +modulate = Color(0.721569, 0, 0.572549, 1) +texture = ExtResource("2_v2iad") +script = ExtResource("3_0aoyx") diff --git a/card_theme.tres b/card_theme.tres new file mode 100644 index 0000000..c99018e --- /dev/null +++ b/card_theme.tres @@ -0,0 +1,3 @@ +[gd_resource type="Theme" format=3 uid="uid://dhyp0ou15akxv"] + +[resource] diff --git a/project.godot b/project.godot index 179ddc9..f93d20d 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="TierMaker" -config/features=PackedStringArray("4.2", "Forward Plus") +config/features=PackedStringArray("4.2", "C#", "Forward Plus") config/icon="res://icon.svg" [dotnet] diff --git a/row.tscn b/row.tscn index c7fdf57..4662aee 100644 --- a/row.tscn +++ b/row.tscn @@ -1,8 +1,11 @@ -[gd_scene load_steps=2 format=3 uid="uid://d4j824viqwho2"] +[gd_scene load_steps=3 format=3 uid="uid://d4j824viqwho2"] + +[ext_resource type="Script" path="res://Row.cs" id="1_lr7oy"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_n14fa"] -[node name="Row" type="Area2D"] +[node name="Row" type="Area2D" groups=["Row"]] +script = ExtResource("1_lr7oy") [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource("RectangleShape2D_n14fa")