Implement timeline
This commit is contained in:
parent
92e8a9f74f
commit
b6ef0034ac
@ -1,10 +1,14 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
public partial class Player : Node
|
public partial class Player : Node
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
public class BudgetType {
|
/// 预算类型,用于记录项目预算的不同类别费用。
|
||||||
|
/// </summary>
|
||||||
|
public class BudgetType
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备费:用于购买设备,升级实验室是指在项目实施过程中购置或试制专用仪
|
/// 设备费:用于购买设备,升级实验室是指在项目实施过程中购置或试制专用仪
|
||||||
/// 器设备,对现有仪器设备进行升级改造,以及租赁外单位仪器设备而发生的费
|
/// 器设备,对现有仪器设备进行升级改造,以及租赁外单位仪器设备而发生的费
|
||||||
@ -12,7 +16,7 @@ public partial class Player : Node
|
|||||||
/// 置,鼓励开放共享、自主研制、租赁专用仪器设备以及对现有仪器设备进行升
|
/// 置,鼓励开放共享、自主研制、租赁专用仪器设备以及对现有仪器设备进行升
|
||||||
/// 级改造,避免重复购置。
|
/// 级改造,避免重复购置。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Facility { get; set; }
|
public int Facility { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 业务费:是指项目实施过程中消耗的各种材料、辅助材料等低值易耗品的采
|
/// 业务费:是指项目实施过程中消耗的各种材料、辅助材料等低值易耗品的采
|
||||||
/// 购、运输、装卸、整理等费用,发生的测试化验加工、燃料动力、出版/文献/
|
/// 购、运输、装卸、整理等费用,发生的测试化验加工、燃料动力、出版/文献/
|
||||||
@ -30,15 +34,72 @@ public partial class Player : Node
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 总预算
|
/// 总预算
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Total => Facility + Operational + Labor;
|
public int Total => Facility + Operational + Labor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class TimelineType
|
||||||
|
{
|
||||||
|
public DateOnly InternalDate { get; set; }
|
||||||
|
|
||||||
|
private Dictionary<DateOnly, HashSet<Guid>> _events;
|
||||||
|
|
||||||
|
public void Subscribe(DateOnly date, Guid eventUUID)
|
||||||
|
{
|
||||||
|
_events ??= new Dictionary<DateOnly, HashSet<Guid>>();
|
||||||
|
if (!_events.ContainsKey(date)) _events[date] = new HashSet<Guid>();
|
||||||
|
_events[date].Add(eventUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Unsubscribe(DateOnly date, Guid eventUUID)
|
||||||
|
{
|
||||||
|
if (_events == null) return;
|
||||||
|
if (!_events.ContainsKey(date)) return;
|
||||||
|
_events[date].Remove(eventUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NextDay()
|
||||||
|
{
|
||||||
|
if (_events == null) return;
|
||||||
|
_events.Remove(InternalDate);
|
||||||
|
|
||||||
|
InternalDate = InternalDate.AddDays(1);
|
||||||
|
OnDayChanged?.Invoke(InternalDate);
|
||||||
|
GD.Print("Today is: " + InternalDate.ToString("yyyy-MM-dd"));
|
||||||
|
|
||||||
|
if (_events.ContainsKey(InternalDate))
|
||||||
|
{
|
||||||
|
var events = _events[InternalDate];
|
||||||
|
foreach (var eventUUID in events)
|
||||||
|
{
|
||||||
|
// TODO: Trigger event
|
||||||
|
OnEventTriggered?.Invoke(InternalDate, eventUUID);
|
||||||
|
GD.Print("event triggered! eventUUID: " + eventUUID.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Attach(Timer ticker)
|
||||||
|
{
|
||||||
|
ticker.Timeout += NextDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimelineType(DateOnly startDate)
|
||||||
|
{
|
||||||
|
InternalDate = startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate void EventTriggeredEventHandler(DateOnly date, Guid eventUUID);
|
||||||
|
|
||||||
|
public event EventTriggeredEventHandler OnEventTriggered;
|
||||||
|
|
||||||
|
public delegate void DayChangedEventHandler(DateOnly date);
|
||||||
|
|
||||||
|
public event DayChangedEventHandler OnDayChanged;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 预算类型,用于记录项目预算的不同类别费用。
|
|
||||||
/// </summary>
|
|
||||||
public static BudgetType Budget { get; set; }
|
public static BudgetType Budget { get; set; }
|
||||||
|
public static readonly TimelineType Timeline = new(DateOnly.Parse("2024/11/17"));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 名字
|
/// 名字
|
||||||
@ -48,28 +109,24 @@ public partial class Player : Node
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 年龄
|
/// 年龄
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static uint Age { get; set; }
|
public static uint Age { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 日期
|
/// 日期
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static DateOnly Date { get; set; }
|
public static DateOnly Date { get; set; }
|
||||||
|
|
||||||
// Called when the node enters the scene tree for the first time.
|
// Called when the node enters the scene tree for the first time.
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
var ticker = GetNode<Timer>("/root/GameManager/OneSecondTicker");
|
var ticker = GetNode<Timer>("/root/GameManager/OneSecondTicker");
|
||||||
ticker.Timeout += OnTickerTimeout;
|
Timeline.Attach(ticker);
|
||||||
|
Timeline.Subscribe(DateOnly.Parse("2024/11/20"), Guid.NewGuid());
|
||||||
|
Timeline.OnEventTriggered += (d, e) => GD.Print($"Timeline event triggered: {d}, {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnTickerTimeout()
|
|
||||||
{
|
|
||||||
Date = DateOnly.FromDateTime(DateTime.Now);
|
|
||||||
GD.Print(Date.ToString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user