Added missing Symbol to the game, Improved move and explore logic, added map refresh for tiles.
This commit is contained in:
@@ -34,8 +34,26 @@ public class ItemData
|
||||
return char.ToUpper(noUnderscore[0]) + noUnderscore.Substring(1);
|
||||
}
|
||||
|
||||
public static string GetReadableName(string input)
|
||||
{
|
||||
string noUnderscore = input.Replace("_", " ").ToLower();
|
||||
return char.ToUpper(noUnderscore[0]) + noUnderscore.Substring(1);
|
||||
}
|
||||
|
||||
public static string GetIndex(string readable)
|
||||
{
|
||||
return readable.ToLower().Replace(" ", "_");
|
||||
}
|
||||
|
||||
public string GetCraftingDisplay()
|
||||
{
|
||||
string result = "";
|
||||
result += GetReadableName() + ": \r";
|
||||
foreach (Ingredient ingredient in Inputs)
|
||||
{
|
||||
result += $"{GetReadableName(ingredient.Item)} ({ingredient.Amount}),\r";
|
||||
}
|
||||
result = result.Remove(result.Length - 2);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public class CraftNode : ProgramNode
|
||||
if(GameData.availableResearch[item.Research].state != ResearchState.RESEARCHED) continue;
|
||||
if (item.Inputs.Count > 0)
|
||||
{
|
||||
options.AddItem(item.GetReadableName());
|
||||
options.AddItem(item.GetCraftingDisplay());
|
||||
}
|
||||
}
|
||||
if (selectedItem != null)
|
||||
|
||||
@@ -41,15 +41,14 @@ public class ExploreNode : ProgramNode
|
||||
Vector3 target = pathPoints[0] - startPosition;
|
||||
float distance = target.Length();
|
||||
|
||||
if (distance < 0.1f)
|
||||
if (distance < 0.1f * Mathf.Sqrt(GameData.robotSpeed))
|
||||
{
|
||||
robot.Position = pathPoints[0];
|
||||
Vector3I mapIndex = Pathfinding.GetClosestStartPoint(robot.Position);
|
||||
Tile tile = GameData.map[mapIndex.Y].tiles[mapIndex.X, mapIndex.Z];
|
||||
if (!tile.wasVisited)
|
||||
{
|
||||
tile.wasVisited = true;
|
||||
tile.ContentNode.Visible = true;
|
||||
tile.VisitTile();
|
||||
}
|
||||
pathPoints.Remove(pathPoints[0]);
|
||||
if (pathPoints.Count <= 0)
|
||||
|
||||
@@ -30,8 +30,7 @@ public class MoveNode : ProgramNode
|
||||
Tile tile = GameData.map[mapIndex.Y].tiles[mapIndex.X, mapIndex.Z];
|
||||
if (!tile.wasVisited)
|
||||
{
|
||||
tile.wasVisited = true;
|
||||
tile.ContentNode.Visible = true;
|
||||
tile.VisitTile();
|
||||
}
|
||||
pathPoints.Remove(pathPoints[0]);
|
||||
if (pathPoints.Count <= 0)
|
||||
|
||||
@@ -4,7 +4,7 @@ using Godot;
|
||||
|
||||
public partial class GameData
|
||||
{
|
||||
public static bool DEBUGMODE = true;
|
||||
public static bool DEBUGMODE = false;
|
||||
public static Random rand = new Random(seed);
|
||||
public static Layer[] map;
|
||||
//Current layer the player wants to see
|
||||
|
||||
@@ -16,6 +16,7 @@ public partial class UIHandler : Control
|
||||
[Export] Control uiContent;
|
||||
[Export] PanelContainer menu;
|
||||
[Export] PanelContainer inventory;
|
||||
[Export] ResearchList researchList;
|
||||
|
||||
bool receivedRobotJumpSignal = false;
|
||||
public override void _Ready()
|
||||
@@ -46,6 +47,7 @@ public partial class UIHandler : Control
|
||||
if (Input.IsActionJustPressed("menu")) HandleMenuButton();
|
||||
if (Input.IsActionJustPressed("robot_list")) HandleRobotListButton();
|
||||
if (Input.IsActionJustPressed("inventory")) HandleInventoryButton();
|
||||
if (Input.IsActionJustPressed("research")) HandleResearchButton();
|
||||
|
||||
}
|
||||
|
||||
@@ -57,7 +59,7 @@ public partial class UIHandler : Control
|
||||
public void HandleMapButton()
|
||||
{
|
||||
OpenUIElement(map);
|
||||
map.ShowMap();
|
||||
if(map.Visible) map.ShowMap();
|
||||
}
|
||||
|
||||
public void HandleRobotListButton()
|
||||
@@ -71,6 +73,12 @@ public partial class UIHandler : Control
|
||||
OpenUIElement(inventory);
|
||||
}
|
||||
|
||||
public void HandleResearchButton()
|
||||
{
|
||||
OpenUIElement(researchList);
|
||||
if(researchList.Visible) researchList.SetupGraph();
|
||||
}
|
||||
|
||||
public void DisplayStats()
|
||||
{
|
||||
FPS.Text = Engine.GetFramesPerSecond().ToString() + " FPS";
|
||||
|
||||
@@ -7,16 +7,12 @@ public partial class ResearchList : PanelContainer
|
||||
{
|
||||
[Export] private GraphEdit researchGraph;
|
||||
|
||||
private const float StartXDivisor = 32f;
|
||||
private const float StartYDivisor = 4f;
|
||||
private const float NodeSpacingMultiplier = 10f;
|
||||
|
||||
private List<string> reloadKeys = new List<string>();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
RecalculateResearchStates();
|
||||
SetupGraph();
|
||||
if(Visible) SetupGraph();
|
||||
}
|
||||
|
||||
public void SetupGraph()
|
||||
@@ -25,6 +21,7 @@ public partial class ResearchList : PanelContainer
|
||||
ClearGraph();
|
||||
CreateResearchNodes();
|
||||
CreateResearchConnections();
|
||||
researchGraph.ArrangeNodes();
|
||||
}
|
||||
|
||||
private void ClearGraph()
|
||||
@@ -111,7 +108,6 @@ public partial class ResearchList : PanelContainer
|
||||
{
|
||||
Name = id,
|
||||
Title = id,
|
||||
PositionOffset = GetNodePosition(texture),
|
||||
SelfModulate = stateColor
|
||||
};
|
||||
|
||||
@@ -131,24 +127,6 @@ public partial class ResearchList : PanelContainer
|
||||
return node;
|
||||
}
|
||||
|
||||
private Vector2 GetNodePosition(Texture2D texture)
|
||||
{
|
||||
Vector2 viewportSize = GetViewport().GetVisibleRect().Size;
|
||||
|
||||
float textureWidth = texture?.GetWidth() ?? 64f;
|
||||
|
||||
Vector2 startPosition = new Vector2(
|
||||
viewportSize.X / StartXDivisor,
|
||||
viewportSize.Y / StartYDivisor
|
||||
);
|
||||
|
||||
float xOffset =
|
||||
GameData.availableResearch.Count * -textureWidth +
|
||||
researchGraph.GetChildCount() * textureWidth * NodeSpacingMultiplier;
|
||||
|
||||
return startPosition + new Vector2(xOffset, 0);
|
||||
}
|
||||
|
||||
private void OnResearchPressed(string id)
|
||||
{
|
||||
GameData.availableResearch[id].state = ResearchState.RESEARCHED;
|
||||
@@ -208,4 +186,4 @@ public partial class ResearchList : PanelContainer
|
||||
_ => Colors.Red
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,5 +49,4 @@ public partial class Robot : Node3D
|
||||
isExecuting = true;
|
||||
currentNode = nodes[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class Map : PanelContainer
|
||||
{
|
||||
[Export] GridContainer grid;
|
||||
private HashSet<Tile> handledTiles = new HashSet<Tile>();
|
||||
private Dictionary<Tile, TextureRect> textureMap = new Dictionary<Tile, TextureRect>();
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -76,6 +79,15 @@ public partial class Map : PanelContainer
|
||||
texture.TooltipText = "Not explored";
|
||||
}
|
||||
|
||||
|
||||
textureMap[tiles[x, z]] = texture;
|
||||
|
||||
if (!handledTiles.Contains(tiles[x, z]))
|
||||
{
|
||||
tiles[x, z].OnTileVisited += OnTileVisited;
|
||||
handledTiles.Add(tiles[x, z]);
|
||||
}
|
||||
|
||||
texture.SizeFlagsHorizontal = SizeFlags.ExpandFill;
|
||||
texture.SizeFlagsVertical = SizeFlags.ExpandFill;
|
||||
texture.StretchMode = TextureRect.StretchModeEnum.Scale;
|
||||
@@ -86,6 +98,35 @@ public partial class Map : PanelContainer
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTileVisited(object sender, EventArgs e)
|
||||
{
|
||||
Tile tile = sender as Tile;
|
||||
|
||||
if (tile == null)
|
||||
return;
|
||||
|
||||
if (textureMap.TryGetValue(tile, out TextureRect texture))
|
||||
{
|
||||
UpdateMap(tile, texture);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateMap(Tile tile, TextureRect texture)
|
||||
{
|
||||
if (!IsInstanceValid(texture)) return;
|
||||
|
||||
if (tile.containsResource)
|
||||
{
|
||||
texture.Texture = ResourceDistributor.resources[tile.resource.name];
|
||||
texture.TooltipText = tile.resource.item.GetReadableName() + $"\r(X: {tile.GridPosition.X},Y: {GameData.currentLayer},Z: {tile.GridPosition.Y})";
|
||||
}
|
||||
else
|
||||
{
|
||||
texture.Texture = GenerateTexture(32, new Color(0, 0, 0, 0));
|
||||
texture.TooltipText = "";
|
||||
}
|
||||
}
|
||||
|
||||
public Texture2D GenerateTexture(int size, Color fillColor)
|
||||
{
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ public partial class Tile
|
||||
public bool containsLight, containsDecoration, containsResource;
|
||||
public GameResource resource;
|
||||
public bool wasVisited;
|
||||
public event EventHandler OnTileVisited;
|
||||
|
||||
|
||||
public void SetMeshes(Dictionary<string, MeshInstance3D> tileMeshes)
|
||||
@@ -138,4 +139,10 @@ public partial class Tile
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void VisitTile()
|
||||
{
|
||||
wasVisited = true;
|
||||
OnTileVisited?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user