background still missing
This commit is contained in:
parent
b7be82d7b1
commit
95926f7638
@ -77,10 +77,10 @@ public partial class Controller : Window
|
|||||||
this._screenReady = true;
|
this._screenReady = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._btnScene1.IsPressed()) mainScript.SetScene(1);
|
if (this._btnScene1.IsPressed()) mainScript.SetScene(0);
|
||||||
if (this._btnScene2.IsPressed()) mainScript.SetScene(2);
|
if (this._btnScene2.IsPressed()) mainScript.SetScene(1);
|
||||||
if (this._btnScene3.IsPressed()) mainScript.SetScene(3);
|
if (this._btnScene3.IsPressed()) mainScript.SetScene(2);
|
||||||
if (this._btnScene4.IsPressed()) mainScript.SetScene(4);
|
if (this._btnScene4.IsPressed()) mainScript.SetScene(3);
|
||||||
|
|
||||||
if (this._btnLoad.IsPressed() && this._loadReady)
|
if (this._btnLoad.IsPressed() && this._loadReady)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,6 +2,7 @@ using Godot;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using StarSkyPresenter;
|
using StarSkyPresenter;
|
||||||
using YamlDotNet.Serialization;
|
using YamlDotNet.Serialization;
|
||||||
using FileAccess = System.IO.FileAccess;
|
using FileAccess = System.IO.FileAccess;
|
||||||
@ -13,7 +14,7 @@ public partial class MainScript : Node2D
|
|||||||
private bool _configIsLoaded = false;
|
private bool _configIsLoaded = false;
|
||||||
|
|
||||||
private Dictionary<string, Star> _stars = new Dictionary<string, Star>();
|
private Dictionary<string, Star> _stars = new Dictionary<string, Star>();
|
||||||
private List<Dictionary<string, StarSceneData>> _scenes = new List<Dictionary<string, StarSceneData>>()
|
private List<Scene> _scenes = new List<Scene>();
|
||||||
|
|
||||||
// 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()
|
||||||
@ -36,6 +37,16 @@ public partial class MainScript : Node2D
|
|||||||
DisplayServer.WindowSetMode(DisplayServer.WindowMode.ExclusiveFullscreen, window.GetWindowId());
|
DisplayServer.WindowSetMode(DisplayServer.WindowMode.ExclusiveFullscreen, window.GetWindowId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Star> GetStars()
|
||||||
|
{
|
||||||
|
return this._stars.Values.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Scene> GetScenes()
|
||||||
|
{
|
||||||
|
return this._scenes;
|
||||||
|
}
|
||||||
|
|
||||||
public int GetScene()
|
public int GetScene()
|
||||||
{
|
{
|
||||||
return this._scene;
|
return this._scene;
|
||||||
@ -63,9 +74,9 @@ public partial class MainScript : Node2D
|
|||||||
// deserialize the values
|
// deserialize the values
|
||||||
IDeserializer deser = new DeserializerBuilder().Build();
|
IDeserializer deser = new DeserializerBuilder().Build();
|
||||||
Objects obj_conf = deser.Deserialize<Objects>(new StreamReader(configFile));
|
Objects obj_conf = deser.Deserialize<Objects>(new StreamReader(configFile));
|
||||||
List<Dictionary<string, StarSceneData>> scene_conf = deser.Deserialize<List<Dictionary<string, StarSceneData>>>(new StreamReader(scenesFile));
|
List<SceneConfig> scene_conf = deser.Deserialize<List<SceneConfig>>(new StreamReader(scenesFile));
|
||||||
|
|
||||||
Dictionary<string, Star> stars = new Dictionary<string, Star>();
|
this._stars.Clear();
|
||||||
|
|
||||||
foreach (StarConfig star_config in obj_conf.stars)
|
foreach (StarConfig star_config in obj_conf.stars)
|
||||||
{
|
{
|
||||||
@ -85,7 +96,7 @@ public partial class MainScript : Node2D
|
|||||||
Sprite = sprite
|
Sprite = sprite
|
||||||
};
|
};
|
||||||
|
|
||||||
stars.Add(star_config.id, star);
|
this._stars.Add(star_config.id, star);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Node child in projection.GetChildren())
|
foreach (Node child in projection.GetChildren())
|
||||||
@ -94,23 +105,63 @@ public partial class MainScript : Node2D
|
|||||||
child.QueueFree();
|
child.QueueFree();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (KeyValuePair<string, Star> star in stars)
|
foreach (KeyValuePair<string, Star> star in this._stars)
|
||||||
{
|
{
|
||||||
projection.AddChild(star.Value.Sprite);
|
projection.AddChild(star.Value.Sprite);
|
||||||
|
star.Value.Sprite.ZIndex = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Dictionary<string, Star>> scenes = new List<Dictionary<string, Star>>();
|
List<Scene> scenes = new List<Scene>();
|
||||||
foreach (var scene in scene_conf)
|
foreach (var scene in scene_conf)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<string, StarSceneData> kv in scene)
|
Dictionary<string, Star> namedStars = new Dictionary<string, Star>();
|
||||||
|
foreach (KeyValuePair<string, Star> kv in this._stars)
|
||||||
{
|
{
|
||||||
// TODO: continue here
|
Star star;
|
||||||
|
// check whether a given object is overridden in this scene
|
||||||
|
if (scene.stars.ContainsKey(kv.Key))
|
||||||
|
{
|
||||||
|
// compute the combination of the scene with changes applied
|
||||||
|
var sceneStar = scene.stars[kv.Key];
|
||||||
|
star = new Star
|
||||||
|
{
|
||||||
|
Id = kv.Value.Id,
|
||||||
|
X = sceneStar.x ?? kv.Value.X,
|
||||||
|
Y = sceneStar.y ?? kv.Value.Y,
|
||||||
|
Rot = sceneStar.rot ?? kv.Value.Rot,
|
||||||
|
Scale = sceneStar.scale ?? kv.Value.Scale,
|
||||||
|
Sprite = (Sprite2D)kv.Value.Sprite.Duplicate(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// copy the original if not
|
||||||
|
star = new Star
|
||||||
|
{
|
||||||
|
Id = kv.Value.Id,
|
||||||
|
X = kv.Value.X,
|
||||||
|
Y = kv.Value.Y,
|
||||||
|
Rot = kv.Value.Rot,
|
||||||
|
Scale = kv.Value.Scale,
|
||||||
|
Sprite = (Sprite2D)kv.Value.Sprite.Duplicate()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namedStars.Add(kv.Key, star);
|
||||||
|
}
|
||||||
|
|
||||||
|
scenes.Add(new Scene
|
||||||
|
{
|
||||||
|
transition = scene.transition,
|
||||||
|
stars = namedStars
|
||||||
|
});
|
||||||
|
}
|
||||||
|
GD.Print(scenes.Count);
|
||||||
|
|
||||||
configFile.Close();
|
configFile.Close();
|
||||||
scenesFile.Close();
|
scenesFile.Close();
|
||||||
|
|
||||||
this._configIsLoaded = true;
|
this._configIsLoaded = true;
|
||||||
|
this._scenes = scenes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,16 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Numerics;
|
||||||
|
using StarSkyPresenter;
|
||||||
using YamlDotNet.Serialization;
|
using YamlDotNet.Serialization;
|
||||||
|
using Vector2 = Godot.Vector2;
|
||||||
|
|
||||||
public partial class Projection : Window
|
public partial class Projection : Window
|
||||||
{
|
{
|
||||||
private double _sceneTime = 0;
|
private double _sceneTime = 0;
|
||||||
private int _lastScene = 1;
|
private int _lastScene = 0;
|
||||||
private int _activeScene = 1;
|
private int _activeScene = 0;
|
||||||
|
|
||||||
|
|
||||||
// Called when the node enters the scene tree for the first time.
|
// Called when the node enters the scene tree for the first time.
|
||||||
@ -16,12 +19,35 @@ public partial class Projection : Window
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double Fapply(double input, string fname)
|
||||||
|
{
|
||||||
|
switch (fname)
|
||||||
|
{
|
||||||
|
case "lin": return input;
|
||||||
|
case "sin": return Math.Sin(input);
|
||||||
|
case "cos": return 1.0 - Math.Cos(input);
|
||||||
|
case "sin2": return Math.Sin(input)*Math.Sin(input);
|
||||||
|
default: return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private double FadeTime(bool fadeIn, bool fadeOut, double t)
|
||||||
|
{
|
||||||
|
switch ((fadeIn, fadeOut))
|
||||||
|
{
|
||||||
|
case (true, true): return Math.Sin(t)*Math.Sin(t);
|
||||||
|
case (true, false): return 1 - Math.Cos(t);
|
||||||
|
case (false, true): return Math.Sin(t);
|
||||||
|
case (false, false): return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
// get MainScript instance
|
// get MainScript instance
|
||||||
MainScript mainScript = (MainScript)this.GetTree().GetRoot().GetNode<MainScript>("Main");
|
MainScript mainScript = (MainScript)this.GetTree().GetRoot().GetNode<MainScript>("Main");
|
||||||
Window projectionWindow = GetNode<Window>("/root/Main/Projection");
|
if (mainScript.GetScenes().Count == 0) return;
|
||||||
|
|
||||||
// check for scene update and if so reset the scene time
|
// check for scene update and if so reset the scene time
|
||||||
if (mainScript.GetScene() != this._activeScene)
|
if (mainScript.GetScene() != this._activeScene)
|
||||||
@ -35,6 +61,38 @@ public partial class Projection : Window
|
|||||||
this._sceneTime += delta;
|
this._sceneTime += delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: calculate scene weight
|
||||||
|
var transition = mainScript.GetScenes()[this._lastScene].transition;
|
||||||
|
string xFade = transition.x;
|
||||||
|
string yFade = transition.y;
|
||||||
|
double t = (Math.Clamp(this._sceneTime / transition.t, 0, 1)) * 3.14159265 / 2;
|
||||||
|
double weight = FadeTime(transition.fade_out, transition.fade_in, t);
|
||||||
|
Vector2 posWeight = new Vector2((float)Fapply(weight * 3.14159265 / 2, yFade), (float)Fapply(weight * 3.14159265 / 2, xFade));
|
||||||
|
|
||||||
|
GD.Print("T: " + t + ", weight: " + weight + ", posWeight: " + posWeight);
|
||||||
|
|
||||||
|
// update background
|
||||||
|
// TODO: update background
|
||||||
|
|
||||||
|
// update all the stars
|
||||||
|
foreach (Star star in mainScript.GetStars())
|
||||||
|
{
|
||||||
|
var oldStar = mainScript.GetScenes()[this._lastScene].stars[star.Id];
|
||||||
|
var newStar = mainScript.GetScenes()[this._activeScene].stars[star.Id];
|
||||||
|
|
||||||
|
float baseScale = ((float)this.GetSize().X / star.Sprite.GetTexture().GetWidth()) / 100;
|
||||||
|
|
||||||
|
double activeRot = (1 - weight) * oldStar.Rot + weight * newStar.Rot;
|
||||||
|
Vector2 activePos = (Vector2.One - posWeight) * new Vector2(oldStar.X, oldStar.Y) + posWeight * new Vector2(newStar.X, newStar.Y);
|
||||||
|
float activeScale = ((1 - (float)weight) * oldStar.Scale + (float)weight * newStar.Scale) * baseScale;
|
||||||
|
|
||||||
|
//GD.Print("Scene: " + this._activeScene + ", Time: " + this._sceneTime + ", Weight: " + weight + ", ActiveRot: " + activeRot + ", ActivePos: " + activePos + ", ActiveScale: " + activeScale);
|
||||||
|
|
||||||
|
star.Sprite.Rotation += (float)(((2*3.14159265)*(activeRot / 365)) * delta);
|
||||||
|
star.Sprite.Position = activePos * this.GetSize();
|
||||||
|
star.Sprite.Scale = Vector2.One * activeScale;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
32
Star.cs
32
Star.cs
@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
@ -17,10 +18,33 @@ public class StarConfig
|
|||||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||||
public class StarSceneData
|
public class StarSceneData
|
||||||
{
|
{
|
||||||
public float x { get; set; }
|
public float? x { get; set; }
|
||||||
public float y { get; set; }
|
public float? y { get; set; }
|
||||||
public float rot { get; set; }
|
public float? rot { get; set; }
|
||||||
public float scale { get; set; }
|
public float? scale { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||||
|
public class TransitionConfig
|
||||||
|
{
|
||||||
|
public bool fade_in { get; set; } = false;
|
||||||
|
public bool fade_out { get; set; } = false;
|
||||||
|
public double t { get; set; } = 1;
|
||||||
|
public string x { get; set; } = "lin";
|
||||||
|
public string y { get; set; } = "lin";
|
||||||
|
}
|
||||||
|
|
||||||
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||||
|
public class SceneConfig
|
||||||
|
{
|
||||||
|
public Dictionary<string, StarSceneData> stars { get; set; }
|
||||||
|
public TransitionConfig transition { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Scene
|
||||||
|
{
|
||||||
|
public Dictionary<string, Star> stars { get; set; }
|
||||||
|
public TransitionConfig transition { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Star
|
public class Star
|
||||||
|
|||||||
15
config.yaml
15
config.yaml
@ -1,18 +1,9 @@
|
|||||||
|
|
||||||
stars:
|
stars:
|
||||||
- id: star-1
|
- id: star-1
|
||||||
x: 50
|
x: 0.1
|
||||||
y: 50
|
y: 0.1
|
||||||
rot: 15
|
|
||||||
scale: 5
|
scale: 5
|
||||||
|
rot: 5
|
||||||
image: nice-star-1.png
|
image: nice-star-1.png
|
||||||
- id: star-2
|
|
||||||
x: 25
|
|
||||||
y: 25
|
|
||||||
rot: 10
|
|
||||||
scale: 4
|
|
||||||
image: nice-star-2.png
|
|
||||||
|
|
||||||
|
|
||||||
background: background-01.jpg
|
background: background-01.jpg
|
||||||
frameRate: 30
|
frameRate: 30
|
||||||
@ -39,7 +39,7 @@ offset_left = 420.0
|
|||||||
offset_top = 30.0
|
offset_top = 30.0
|
||||||
offset_right = 520.0
|
offset_right = 520.0
|
||||||
offset_bottom = 90.0
|
offset_bottom = 90.0
|
||||||
text = "Scene 3"
|
text = "Scene 4"
|
||||||
|
|
||||||
[node name="BtnClose" type="Button" parent="Controller"]
|
[node name="BtnClose" type="Button" parent="Controller"]
|
||||||
offset_left = 42.0
|
offset_left = 42.0
|
||||||
|
|||||||
42
scenes.yaml
42
scenes.yaml
@ -1,12 +1,30 @@
|
|||||||
- star-1:
|
- stars:
|
||||||
x: 50
|
star-1:
|
||||||
y: 50
|
x: 1.1
|
||||||
star-2:
|
y: 1.1
|
||||||
x: 60
|
transition:
|
||||||
y: 0
|
t: 5
|
||||||
- star-1:
|
fade_in: true
|
||||||
x: 10
|
fade_out: false
|
||||||
y: 10
|
x: sin
|
||||||
star-2:
|
y: cos
|
||||||
x: 25
|
- stars:
|
||||||
y: 25
|
star-1:
|
||||||
|
x: 0.5
|
||||||
|
y: 0.5
|
||||||
|
transition:
|
||||||
|
t: 5
|
||||||
|
fade_in: false
|
||||||
|
fade_out: true
|
||||||
|
x: cos
|
||||||
|
y: sin
|
||||||
|
- stars:
|
||||||
|
star-1:
|
||||||
|
x: -0.1
|
||||||
|
y: 1.1
|
||||||
|
transition:
|
||||||
|
t: 5
|
||||||
|
fade_in: true
|
||||||
|
fade_out: false
|
||||||
|
x: sin
|
||||||
|
y: cos
|
||||||
Loading…
x
Reference in New Issue
Block a user