Add backend projects with core models and tests, setup Godot frontend
This commit is contained in:
13
frontend/scripts/core/GameData.cs
Normal file
13
frontend/scripts/core/GameData.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Godot;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class GameData : Resource
|
||||
{
|
||||
[Export] public string CompanyName { get; set; } = "My Company";
|
||||
[Export] public int StartYear { get; set; } = 1980;
|
||||
[Export] public decimal StartingCash { get; set; } = 100000m;
|
||||
|
||||
// Настройки карты
|
||||
[Export] public int CityCount { get; set; } = 10;
|
||||
[Export] public bool EnableImports { get; set; } = true;
|
||||
}
|
||||
59
frontend/scripts/core/GameManager.cs
Normal file
59
frontend/scripts/core/GameManager.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Godot;
|
||||
|
||||
/// <summary>
|
||||
/// Менеджер игры - управляет состоянием игры
|
||||
/// </summary>
|
||||
public partial class GameManager : Node
|
||||
{
|
||||
public static GameManager Instance { get; private set; } = null!;
|
||||
|
||||
[Signal] public delegate void MoneyChangedEventHandler(decimal newAmount);
|
||||
[Signal] public delegate void DateChangedEventHandler(int year, int month, int day);
|
||||
|
||||
public decimal Money { get; private set; } = 100000m;
|
||||
public int GameYear { get; private set; } = 1980;
|
||||
public int GameMonth { get; private set; } = 1;
|
||||
public int GameDay { get; private set; } = 1;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
QueueFree();
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void AddMoney(decimal amount)
|
||||
{
|
||||
Money += amount;
|
||||
EmitSignal(SignalName.MoneyChanged, Money);
|
||||
}
|
||||
|
||||
public void SpendMoney(decimal amount)
|
||||
{
|
||||
if (Money >= amount)
|
||||
{
|
||||
Money -= amount;
|
||||
EmitSignal(SignalName.MoneyChanged, Money);
|
||||
}
|
||||
}
|
||||
|
||||
public void AdvanceTime(int ticks)
|
||||
{
|
||||
GameDay += ticks;
|
||||
if (GameDay > 30)
|
||||
{
|
||||
GameDay = 1;
|
||||
GameMonth++;
|
||||
if (GameMonth > 12)
|
||||
{
|
||||
GameMonth = 1;
|
||||
GameYear++;
|
||||
}
|
||||
}
|
||||
EmitSignal(SignalName.DateChanged, GameYear, GameMonth, GameDay);
|
||||
}
|
||||
}
|
||||
13
frontend/scripts/core/Main.cs
Normal file
13
frontend/scripts/core/Main.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Godot;
|
||||
|
||||
public partial class Main : Node2D
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
GD.Print("MyBiz - Game Started!");
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
}
|
||||
35
frontend/scripts/ui/GameUI.cs
Normal file
35
frontend/scripts/ui/GameUI.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Godot;
|
||||
|
||||
/// <summary>
|
||||
/// Базовый класс для всех UI элементов
|
||||
/// </summary>
|
||||
public partial class GameUI : Control
|
||||
{
|
||||
protected GameManager GameManager => GameManager.Instance;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
ConnectSignals();
|
||||
}
|
||||
|
||||
protected virtual void ConnectSignals()
|
||||
{
|
||||
if (GameManager != null)
|
||||
{
|
||||
GameManager.MoneyChanged += OnMoneyChanged;
|
||||
GameManager.DateChanged += OnDateChanged;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnMoneyChanged(decimal newAmount) { }
|
||||
protected virtual void OnDateChanged(int year, int month, int day) { }
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (GameManager != null)
|
||||
{
|
||||
GameManager.MoneyChanged -= OnMoneyChanged;
|
||||
GameManager.DateChanged -= OnDateChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user