29 lines
817 B
C#
29 lines
817 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Civilization.Core.Game;
|
|
using Civilization.GodotIntegration.Utils;
|
|
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.ToGodot());
|
|
AddChild(unitNode);
|
|
_unitViews[unit.Id] = unitNode;
|
|
}
|
|
}
|
|
} |