Compare commits
No commits in common. "db3e3e7253836473419fcfe6c72ae51af0a0bc36" and "8d122b650f3b3cf15433f5af84ab392489843e40" have entirely different histories.
db3e3e7253
...
8d122b650f
|
@ -1,6 +0,0 @@
|
||||||
[gd_scene load_steps=2 format=2]
|
|
||||||
|
|
||||||
[ext_resource path="res://scripts/Clock.cs" type="Script" id=1]
|
|
||||||
|
|
||||||
[node name="Clock" type="Node"]
|
|
||||||
script = ExtResource( 1 )
|
|
|
@ -1,22 +0,0 @@
|
||||||
[gd_scene load_steps=2 format=2]
|
|
||||||
|
|
||||||
[ext_resource path="res://scripts/DebugUI.cs" type="Script" id=1]
|
|
||||||
|
|
||||||
[node name="Debug UI" type="Control"]
|
|
||||||
anchor_right = 1.0
|
|
||||||
anchor_bottom = 1.0
|
|
||||||
script = ExtResource( 1 )
|
|
||||||
TicksLabelPath = NodePath("Ticks")
|
|
||||||
|
|
||||||
[node name="Ticks" type="Label" parent="."]
|
|
||||||
anchor_left = 1.0
|
|
||||||
anchor_top = 1.0
|
|
||||||
anchor_right = 1.0
|
|
||||||
anchor_bottom = 1.0
|
|
||||||
margin_right = -10.0
|
|
||||||
margin_bottom = -10.0
|
|
||||||
grow_horizontal = 0
|
|
||||||
grow_vertical = 0
|
|
||||||
text = "ticks: 0"
|
|
||||||
align = 2
|
|
||||||
valign = 2
|
|
|
@ -1,19 +1,11 @@
|
||||||
[gd_scene load_steps=5 format=2]
|
[gd_scene load_steps=3 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://nodes/grid.tscn" type="PackedScene" id=1]
|
[ext_resource path="res://nodes/grid.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://nodes/grid_cursor.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://nodes/grid_cursor.tscn" type="PackedScene" id=2]
|
||||||
[ext_resource path="res://nodes/debug_ui.tscn" type="PackedScene" id=3]
|
|
||||||
[ext_resource path="res://nodes/clock.tscn" type="PackedScene" id=4]
|
|
||||||
|
|
||||||
[node name="Root" type="Node"]
|
[node name="Root" type="Node2D"]
|
||||||
|
|
||||||
[node name="Grid" parent="." instance=ExtResource( 1 )]
|
[node name="Grid" parent="." instance=ExtResource( 1 )]
|
||||||
|
|
||||||
[node name="Cursor" parent="." instance=ExtResource( 2 )]
|
[node name="Cursor" parent="." instance=ExtResource( 2 )]
|
||||||
Grid = NodePath("../Grid")
|
Grid = NodePath("../Grid")
|
||||||
|
|
||||||
[node name="Debug UI" parent="." instance=ExtResource( 3 )]
|
|
||||||
|
|
||||||
[node name="Clock" parent="." instance=ExtResource( 4 )]
|
|
||||||
|
|
||||||
[connection signal="OnTick" from="Clock" to="Debug UI" method="_on_Clock_OnTick"]
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
using Godot;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
public class Clock : Node
|
|
||||||
{
|
|
||||||
[Signal]
|
|
||||||
delegate void OnTick(int ticks);
|
|
||||||
|
|
||||||
private int _ticks = 0;
|
|
||||||
|
|
||||||
public override void _Input(InputEvent @event)
|
|
||||||
{
|
|
||||||
base._Input(@event);
|
|
||||||
|
|
||||||
if (@event is InputEventKey keyEvent && keyEvent.Pressed)
|
|
||||||
{
|
|
||||||
switch ((KeyList)keyEvent.Scancode)
|
|
||||||
{
|
|
||||||
case KeyList.Space:
|
|
||||||
Tick();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Tick()
|
|
||||||
{
|
|
||||||
_ticks++;
|
|
||||||
EmitSignal(nameof(OnTick), _ticks);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
using Godot;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
public class DebugUI : Control
|
|
||||||
{
|
|
||||||
[Export]
|
|
||||||
public NodePath TicksLabelPath { private get; set; }
|
|
||||||
private Label _ticksLabel;
|
|
||||||
|
|
||||||
public override void _Ready()
|
|
||||||
{
|
|
||||||
_ticksLabel = GetNode<Label>(TicksLabelPath);
|
|
||||||
SetTicksText(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void _on_Clock_OnTick(int ticks) => SetTicksText(ticks);
|
|
||||||
|
|
||||||
private void SetTicksText(int ticks)
|
|
||||||
{
|
|
||||||
_ticksLabel.Text = $"ticks: {ticks}";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
using Godot;
|
|
||||||
|
|
||||||
public struct Tile
|
|
||||||
{
|
|
||||||
public bool isHighlighted;
|
|
||||||
public float value;
|
|
||||||
public ShaderMaterial material;
|
|
||||||
}
|
|
|
@ -12,6 +12,11 @@ public class WorldGrid : Node2D
|
||||||
[Export]
|
[Export]
|
||||||
public int CellSize { get; set; }
|
public int CellSize { get; set; }
|
||||||
|
|
||||||
|
private struct Tile
|
||||||
|
{
|
||||||
|
public bool isHighlighted;
|
||||||
|
public ShaderMaterial material;
|
||||||
|
}
|
||||||
private Tile[,] _tiles;
|
private Tile[,] _tiles;
|
||||||
|
|
||||||
// Called when the node enters the scene tree for the first time.
|
// Called when the node enters the scene tree for the first time.
|
||||||
|
@ -48,11 +53,6 @@ public class WorldGrid : Node2D
|
||||||
_tiles[x, y].isHighlighted ^= true;
|
_tiles[x, y].isHighlighted ^= true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTileValue(int x, int y, float value)
|
|
||||||
{
|
|
||||||
_tiles[x, y].value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void GetGridPos(Vector2 position, out int x, out int y)
|
public void GetGridPos(Vector2 position, out int x, out int y)
|
||||||
{
|
{
|
||||||
x = Mathf.FloorToInt(position.x / CellSize);
|
x = Mathf.FloorToInt(position.x / CellSize);
|
||||||
|
@ -84,7 +84,6 @@ public class WorldGrid : Node2D
|
||||||
{
|
{
|
||||||
var tile = new Tile();
|
var tile = new Tile();
|
||||||
tile.isHighlighted = false;
|
tile.isHighlighted = false;
|
||||||
tile.value = 0.0f;
|
|
||||||
|
|
||||||
var node = TileScene.Instance<Node2D>();
|
var node = TileScene.Instance<Node2D>();
|
||||||
this.AddChild(node);
|
this.AddChild(node);
|
||||||
|
|
Loading…
Reference in New Issue