117 lines
2.9 KiB
C#
117 lines
2.9 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using StarSkyPresenter;
|
|
using YamlDotNet.Serialization;
|
|
using FileAccess = System.IO.FileAccess;
|
|
|
|
public partial class MainScript : Node2D
|
|
{
|
|
|
|
private int _scene = 1;
|
|
private bool _configIsLoaded = false;
|
|
|
|
private Dictionary<string, Star> _stars = new Dictionary<string, Star>();
|
|
private List<Dictionary<string, StarSceneData>> _scenes = new List<Dictionary<string, StarSceneData>>()
|
|
|
|
// Called when the node enters the scene tree for the first time.
|
|
public override void _Ready()
|
|
{
|
|
}
|
|
|
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
public override void _Process(double delta)
|
|
{
|
|
}
|
|
|
|
|
|
public void SetFullScreen()
|
|
{
|
|
Window window = GetNode<Window>("Projection");
|
|
GD.Print("Window: ", window);
|
|
window.SetCurrentScreen(1);
|
|
window.SetSize(new Vector2I(1920, 1080));
|
|
|
|
DisplayServer.WindowSetMode(DisplayServer.WindowMode.ExclusiveFullscreen, window.GetWindowId());
|
|
}
|
|
|
|
public int GetScene()
|
|
{
|
|
return this._scene;
|
|
}
|
|
|
|
public void SetScene(int scene)
|
|
{
|
|
this._scene = scene;
|
|
}
|
|
|
|
public void UpdateConfig()
|
|
{
|
|
// check if config is already loaded
|
|
if (this._configIsLoaded)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Open the config file
|
|
FileStream configFile = File.Open("config.yaml", FileMode.Open, FileAccess.Read);
|
|
FileStream scenesFile = File.Open("scenes.yaml", FileMode.Open, FileAccess.Read);
|
|
|
|
Window projection = this.GetNode<Window>("/root/Main/Projection");
|
|
|
|
// deserialize the values
|
|
IDeserializer deser = new DeserializerBuilder().Build();
|
|
Objects obj_conf = deser.Deserialize<Objects>(new StreamReader(configFile));
|
|
List<Dictionary<string, StarSceneData>> scene_conf = deser.Deserialize<List<Dictionary<string, StarSceneData>>>(new StreamReader(scenesFile));
|
|
|
|
Dictionary<string, Star> stars = new Dictionary<string, Star>();
|
|
|
|
foreach (StarConfig star_config in obj_conf.stars)
|
|
{
|
|
Sprite2D sprite = new Sprite2D();
|
|
Image image = Image.LoadFromFile("resources/" + star_config.image);
|
|
ImageTexture texture = ImageTexture.CreateFromImage(image);
|
|
sprite.SetTexture(texture);
|
|
sprite.Position = new Vector2(star_config.x, star_config.y);
|
|
|
|
Star star = new Star
|
|
{
|
|
Id = star_config.id,
|
|
X = star_config.x,
|
|
Y = star_config.y,
|
|
Rot = star_config.rot,
|
|
Scale = star_config.scale,
|
|
Sprite = sprite
|
|
};
|
|
|
|
stars.Add(star_config.id, star);
|
|
}
|
|
|
|
foreach (Node child in projection.GetChildren())
|
|
{
|
|
projection.RemoveChild(child);
|
|
child.QueueFree();
|
|
}
|
|
|
|
foreach (KeyValuePair<string, Star> star in stars)
|
|
{
|
|
projection.AddChild(star.Value.Sprite);
|
|
}
|
|
|
|
List<Dictionary<string, Star>> scenes = new List<Dictionary<string, Star>>();
|
|
foreach (var scene in scene_conf)
|
|
{
|
|
foreach (KeyValuePair<string, StarSceneData> kv in scene)
|
|
{
|
|
// TODO: continue here
|
|
}
|
|
}
|
|
|
|
configFile.Close();
|
|
scenesFile.Close();
|
|
|
|
this._configIsLoaded = true;
|
|
}
|
|
}
|