95 lines
2.9 KiB
C#
95 lines
2.9 KiB
C#
using Firebird2D.Core;
|
|
using Firebird2D.SceneSystem.Actors;
|
|
using SFML.Graphics;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Firebird2D.SceneSystem
|
|
{
|
|
public static class SceneManager
|
|
{
|
|
//static List<I_Scene> scenes = new List<I_Scene>();
|
|
|
|
static string scenesPath = "scenes.dll";
|
|
|
|
static Assembly sceneDll = null;
|
|
|
|
static MainWindow mainWindow = null;
|
|
|
|
static SceneGroup ActiveSceneGroup = null;
|
|
|
|
public static void LoadScenes(MainWindow renderWindow)
|
|
{
|
|
if (mainWindow == null) return; // todo wenn render window null
|
|
mainWindow = renderWindow;
|
|
|
|
sceneDll = Assembly.Load(scenesPath);
|
|
|
|
if (sceneDll == null) return; //Todo wenn scenes nicht geladen werden fehler
|
|
|
|
Type? scenesConfig = sceneDll.GetType("Scenes.Config");
|
|
|
|
if (scenesConfig == null) return; //Todo wenn die scenes config nicht gefunden wird
|
|
|
|
FieldInfo? startSceneGroup = scenesConfig.GetField("startingGroup", BindingFlags.Public | BindingFlags.Static);
|
|
|
|
if (startSceneGroup == null) return;// Todo wenn die scenes config nicht gefunden wird
|
|
|
|
SceneGroup? startingGroup = startSceneGroup.GetValue(null) as SceneGroup;
|
|
|
|
if (startingGroup == null) return;//Todo wenn die scenes config nicht gefunden wird
|
|
|
|
LoadSceneGroup(startingGroup, null);
|
|
|
|
}
|
|
|
|
private static async void LoadSceneGroup(SceneGroup sceneGroup, List<I_BaseActor>? carryOverActors)
|
|
{
|
|
if (sceneGroup == null) return; //todoo wenn scene group null
|
|
|
|
ActiveSceneGroup = sceneGroup;
|
|
|
|
changeScene(sceneGroup.SceneChangeAnimation, carryOverActors);
|
|
|
|
// Asynchrone Initialisierung der Szene im Hintergrund
|
|
await Task.Run(() => sceneGroup.InitializeGroup());
|
|
}
|
|
|
|
public static void changeScene(Type type, List<I_BaseActor> carryOverActors)
|
|
{
|
|
if (type != typeof(I_Scene)) return;
|
|
|
|
I_Scene? scene = ActiveSceneGroup.Get_Scene(type);
|
|
|
|
changeScene(scene,carryOverActors);
|
|
}
|
|
|
|
private static void changeScene(I_Scene? scene, List<I_BaseActor>? carryOverActors)
|
|
{
|
|
if (scene == null) return; //todo reaction
|
|
|
|
if (mainWindow.ActiveSecene != null)
|
|
mainWindow.ActiveSecene.DestroyScene();
|
|
|
|
if (carryOverActors != null)
|
|
foreach (I_BaseActor actor in carryOverActors)
|
|
{
|
|
scene.addActor(actor);
|
|
}
|
|
|
|
mainWindow.ActiveSecene = scene.BuildScene();
|
|
}
|
|
|
|
public static void changeGroup(SceneGroup nextSceneGroup, List<I_BaseActor> carryOverActors)
|
|
{
|
|
LoadSceneGroup(nextSceneGroup, carryOverActors);
|
|
}
|
|
|
|
}
|
|
}
|