initialize repo

This commit is contained in:
2025-08-08 15:36:09 +02:00
parent d6a2c37a5f
commit cabf13d164
92 changed files with 2160 additions and 2 deletions

Submodule godot_game deleted from 3d8e0f2828

4
godot_game/.editorconfig Normal file
View File

@@ -0,0 +1,4 @@
root = true
[*]
charset = utf-8

2
godot_game/.gitattributes vendored Normal file
View File

@@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf

6
godot_game/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
# Godot 4+ specific ignores
.godot/
/android/
civ_codebase.txt
.idea/
./civilization/.idea/

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using Civilization.Core.Game;
using Godot;
namespace Civilization.GodotIntegration;
public partial class CityRenderer : Node2D
{
[Export] public PackedScene CityScene;
[Export] public MapRenderer MapRenderer;
private readonly Dictionary<Guid, Node2D> _cityViews = new();
public void Render(GameState state)
{
foreach (var view in _cityViews.Values) view.QueueFree();
_cityViews.Clear();
foreach (var city in state.Cities)
{
var cityNode = CityScene.Instantiate<Node2D>();
cityNode.Position = MapRenderer.MapToWorld(city.Position);
AddChild(cityNode);
_cityViews[city.Id] = cityNode;
}
}
}

View File

@@ -0,0 +1 @@
uid://byag1mawqiemf

View File

@@ -0,0 +1,13 @@
<Project Sdk="Godot.NET.Sdk/4.2.0">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../Lib/Civilization.Core/Civilization.Core.csproj" />
<ProjectReference Include="../../Lib/Civilization.Shared/Civilization.Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,61 @@
using System.Collections.Generic;
using Civilization.Core;
using Civilization.Core.Game;
using Civilization.Core.Grid;
using Civilization.Core.Units;
using Godot;
namespace Civilization.GodotIntegration;
public partial class GameController : Node
{
private const int DefaultWorldSize = 10;
[Export] public GameStateProvider StateProvider;
[Export] public MapRenderer MapRenderer;
[Export] public UnitRenderer UnitRenderer;
[Export] public CityRenderer CityRenderer;
[Export] public InputSystem InputSystem;
[Export] public SelectionSystem SelectionSystem;
public override void _Ready()
{
// Setup initial game state
var grid = new SquareGrid(DefaultWorldSize, DefaultWorldSize);
var gameMap = new GameMap(grid);
var players = new List<Player>
{
new Player(0, "Player 1", Colors.Red),
new Player(1, "Player 2", Colors.Blue)
};
var gameState = new GameState(gameMap, players);
StateProvider.Initialize(gameState);
// Setup UI systems
MapRenderer.RenderMap(gameMap);
InputSystem.OnStateChanged = Redraw;
// Add one settler to start
var settler = new Unit(0, UnitType.Settler, new Vector2I(2, 2));
gameState.AddUnit(settler);
GD.Print($"Added settler unit at {settler.Position}");
Redraw();
GD.Print($"Turn {gameState.TurnManager.TurnNumber}: {gameState.CurrentPlayer.Name}'s turn");
}
public void OnEndTurnPressed()
{
StateProvider.GameState.NextTurn();
Redraw();
GD.Print($"Turn {StateProvider.GameState.TurnManager.TurnNumber}: {StateProvider.GameState.CurrentPlayer.Name}'s turn");
}
public void Redraw()
{
UnitRenderer.Render(StateProvider.GameState);
CityRenderer.Render(StateProvider.GameState);
}
}

View File

@@ -0,0 +1 @@
uid://c5dq2mw7228ya

View File

@@ -0,0 +1,15 @@
using Civilization.Core.Game;
using Godot;
namespace Civilization.GodotIntegration;
public partial class GameStateProvider : Node
{
public GameState GameState { get; private set; }
public void Initialize(GameState gameState)
{
GameState = gameState;
GD.Print("GameStateProvider initialized with game state.");
}
}

View File

@@ -0,0 +1 @@
uid://dyoapq2dkn0d6

View File

@@ -0,0 +1,49 @@
using System;
using Civilization.Core.Actions;
using Godot;
namespace Civilization.GodotIntegration;
public partial class InputSystem : Node
{
[Export] public MapRenderer MapRenderer;
[Export] public SelectionSystem SelectionSystem;
[Export] public GameStateProvider StateProvider;
public Action? OnStateChanged;
public override void _Ready()
{
MapRenderer.TileClicked += HandleTileClick;
}
public override void _ExitTree()
{
MapRenderer.TileClicked -= HandleTileClick;
}
private void HandleTileClick(Vector2I position, bool isRightClick)
{
var state = StateProvider.GameState;
var context = new GameActionContext(state);
var selected = SelectionSystem.SelectedUnit;
if (selected != null)
{
if (!isRightClick) return;
var move = new MoveUnitAction(selected.Id, position);
if (!move.CanExecute(context)) return;
state.ActionQueue.Enqueue(move);
state.ActionQueue.ExecuteAll(context);
OnStateChanged?.Invoke();
return;
}
if (SelectionSystem.TrySelectUnitAt(position, state))
{
GD.Print($"InputSystem: unit {selected?.Id} selected at {position}");
}
}
}

View File

@@ -0,0 +1 @@
uid://clke0qvrtll81

View File

@@ -0,0 +1,41 @@
using Civilization.Core;
using Godot;
namespace Civilization.GodotIntegration;
public partial class MapRenderer : Node2D
{
private const int TileIndexOffset = 1;
[Export] public TileMapLayer TileMapLayer;
[Export] public TileSet TileSet;
[Signal] public delegate void TileClickedEventHandler(Vector2I position, bool isRightClick);
public override void _Input(InputEvent @event)
{
if (@event is not InputEventMouseButton { Pressed: true }) return;
var worldPos = GetGlobalMousePosition();
var localPos = TileMapLayer.ToLocal(worldPos);
var tilePos = TileMapLayer.LocalToMap(localPos);
EmitSignalTileClicked(tilePos, @event is InputEventMouseButton { ButtonIndex: MouseButton.Right });
}
public void RenderMap(GameMap map)
{
TileMapLayer.SetTileSet(TileSet);
var tileSetSource = TileSet.GetSource(1);
TileMapLayer.Clear();
foreach (var tile in map.GetTiles())
{
var pos = tile.Position;
var tileId = (int)tile.Type + TileIndexOffset;
var atlasCoords = tileSetSource.GetTileId(tileId);
TileMapLayer.SetCell(pos, tileId, atlasCoords);
}
}
public Vector2 MapToWorld(Vector2I position) => TileMapLayer.MapToLocal(position);
}

View File

@@ -0,0 +1 @@
uid://c0i71sgyrp2xt

View File

@@ -0,0 +1,28 @@
using System;
using Civilization.Core.Units;
using Godot;
namespace Civilization.GodotIntegration;
public partial class SelectedUnitPanel : Control
{
[Export] public Label UnitInfoLabel;
[Export] public Button SettleButton;
public Action? OnSettleClicked;
public override void _Ready()
{
SettleButton.Pressed += () => OnSettleClicked?.Invoke();
Hide();
}
public void ShowFor(Unit unit)
{
GD.Print($"Showing unit panel for {unit.Id} at {unit.Position} ({unit.Type})");
UnitInfoLabel.Text = $"{unit.Type} at {unit.Position} ({unit.ActionPoints} AP)";
Show();
}
public void HidePanel() => Hide();
}

View File

@@ -0,0 +1 @@
uid://qqlmdir1bdjd

View File

@@ -0,0 +1,31 @@
using System.Linq;
using Civilization.Core.Game;
using Civilization.Core.Units;
using Godot;
namespace Civilization.GodotIntegration;
public partial class SelectionSystem : Node2D
{
public Unit? SelectedUnit { get; private set; }
[Export] public SelectedUnitPanel UnitPanel;
public bool TrySelectUnitAt(Vector2I tilePos, GameState state)
{
var unit = state.GetUnitsForPlayer(state.CurrentPlayer.Id).FirstOrDefault(u => u.Position == tilePos);
if (unit == null) return false;
SelectedUnit = unit;
GD.Print($"Selected unit {unit.Id} at {tilePos} ({unit.Type})");
UnitPanel.ShowFor(unit);
return true;
}
public void Deselect()
{
SelectedUnit = null;
UnitPanel.HidePanel();
}
}

View File

@@ -0,0 +1 @@
uid://c2ovyn15v1rr4

View File

@@ -0,0 +1,43 @@
using Civilization.Core.Actions;
using Civilization.Core.Game;
using Godot;
namespace Civilization.GodotIntegration;
public partial class UiController : Node
{
[Export] public Label TurnLabel;
[Export] public SelectedUnitPanel UnitPanel;
[Export] public GameStateProvider StateProvider;
[Export] public SelectionSystem SelectionSystem;
[Export] public GameController GameController;
public override void _Ready()
{
UnitPanel.OnSettleClicked = TrySettleCity;
}
public override void _Process(double delta)
{
TurnLabel.Text = $"Turn: {StateProvider.GameState.TurnManager.TurnNumber} - {StateProvider.GameState.CurrentPlayer.Name}";
}
private void TrySettleCity()
{
var selected = SelectionSystem.SelectedUnit;
if (selected == null) return;
var context = new GameActionContext(StateProvider.GameState);
var settle = new SettleCityAction(selected.Id);
if (!settle.CanExecute(context))
{
GD.PrintErr($"Cannot settle city with unit {selected.Id} at {selected.Position}");
return;
}
StateProvider.GameState.ActionQueue.Enqueue(settle);
StateProvider.GameState.ActionQueue.ExecuteAll(context);
SelectionSystem.Deselect();
GameController.Redraw();
}
}

View File

@@ -0,0 +1 @@
uid://bx7oa1veqfk35

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using Civilization.Core.Game;
using Godot;
namespace Civilization.GodotIntegration;
public partial class UnitRenderer : Node2D
{
[Export] public PackedScene UnitScene;
[Export] public MapRenderer MapRenderer;
private readonly Dictionary<Guid, Node2D> _unitViews = new();
public void Render(GameState state)
{
foreach (var view in _unitViews.Values) view.QueueFree();
_unitViews.Clear();
foreach (var unit in state.Units)
{
var unitNode = UnitScene.Instantiate<Node2D>();
unitNode.Position = MapRenderer.MapToWorld(unit.Position);
AddChild(unitNode);
_unitViews[unit.Id] = unitNode;
}
}
}

View File

@@ -0,0 +1 @@
uid://bqa3dsxjyij5m

View File

@@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3 uid="uid://dtymuhj7dn87s"]
[ext_resource type="Texture2D" uid="uid://c8ukthe4bm6ui" path="res://Sprites/city.png" id="1_8or66"]
[node name="CityView" type="Node2D"]
[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.005, 0.005)
texture = ExtResource("1_8or66")

View File

@@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3 uid="uid://cty4sa1bq3obk"]
[ext_resource type="Texture2D" uid="uid://chkaihrs4nd65" path="res://Sprites/settler.webp" id="1_7g07s"]
[node name="UnitView" type="Node2D"]
[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.005, 0.005)
texture = ExtResource("1_7g07s")

File diff suppressed because one or more lines are too long

BIN
godot_game/Sprites/city.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c8ukthe4bm6ui"
path="res://.godot/imported/city.png-42096f3d2559488a3d64d50a417bd5ff.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/city.png"
dest_files=["res://.godot/imported/city.png-42096f3d2559488a3d64d50a417bd5ff.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

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://chkaihrs4nd65"
path="res://.godot/imported/settler.webp-a74f7464a102bfcbf0634a3635027a21.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/settler.webp"
dest_files=["res://.godot/imported/settler.webp-a74f7464a102bfcbf0634a3635027a21.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

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://syk5syuba1rw"
path="res://.godot/imported/tiny_terrain.png-83221922c05e6d1fda6dd63ec35b2d2c.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/tiny_terrain.png"
dest_files=["res://.godot/imported/tiny_terrain.png-83221922c05e6d1fda6dd63ec35b2d2c.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

View File

@@ -0,0 +1,21 @@
[gd_resource type="TileSet" load_steps=3 format=3 uid="uid://cmtqrdho2188u"]
[ext_resource type="Texture2D" uid="uid://syk5syuba1rw" path="res://Sprites/tiny_terrain.png" id="1_587l3"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_5a7ea"]
texture = ExtResource("1_587l3")
texture_region_size = Vector2i(1, 1)
0:0/0 = 0
1:0/0 = 0
2:0/0 = 0
3:0/0 = 0
4:0/0 = 0
5:0/0 = 0
6:0/0 = 0
7:0/0 = 0
8:0/0 = 0
9:0/0 = 0
[resource]
tile_size = Vector2i(1, 1)
sources/1 = SubResource("TileSetAtlasSource_5a7ea")

View File

@@ -0,0 +1,27 @@
[gd_scene load_steps=2 format=3 uid="uid://na1o6j7stseb"]
[ext_resource type="Script" uid="uid://c3mt3skudb7ky" path="res://GodotIntegration/SelectedUnitPanel.cs" id="1_sosfk"]
[node name="SelectedUnitPanel" type="MarginContainer" node_paths=PackedStringArray("UnitInfoLabel", "SettleButton")]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/margin_left = 8
theme_override_constants/margin_top = 8
theme_override_constants/margin_right = 8
theme_override_constants/margin_bottom = 8
script = ExtResource("1_sosfk")
UnitInfoLabel = NodePath("UnitInfoLabel")
SettleButton = NodePath("SettleButton")
[node name="UnitInfoLabel" type="Label" parent="."]
layout_mode = 2
size_flags_vertical = 0
text = "Unit name"
[node name="SettleButton" type="Button" parent="."]
layout_mode = 2
size_flags_vertical = 8
text = "Settle city"

1
godot_game/icon.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg>

After

Width:  |  Height:  |  Size: 994 B

View File

@@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cudqpxk1k2gk8"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.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
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

25
godot_game/project.godot Normal file
View File

@@ -0,0 +1,25 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=5
[application]
config/name="civilization"
run/main_scene="uid://dy20m1dgo6mqq"
config/features=PackedStringArray("4.4", "GL Compatibility")
config/icon="res://icon.svg"
[dotnet]
project/assembly_name="civilization"
[rendering]
renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"