add: LoadingScene, ProxyNode
This commit is contained in:
1
.idea/.idea.Polonium/.idea/vcs.xml
generated
1
.idea/.idea.Polonium/.idea/vcs.xml
generated
@@ -3,6 +3,5 @@
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../Polonium.Generators" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../Polonium.Generators.Test" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -8,7 +8,7 @@
|
||||
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||
<PackageId>Polonium</PackageId>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Version>0.0.4</Version>
|
||||
<Version>0.0.8</Version>
|
||||
<Authors>Hangman</Authors>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADynamicResolver_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb71753e8d7f5410a90c2ccab6d9fac7bd1be00_003F9b_003F0c3b144f_003FDynamicResolver_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGlobalRegistry_002Eg_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F2655819e4eaf2a7f63a82a59653d80b82de731_003FGlobalRegistry_002Eg_002Ecs_002Fz_003A4_002D3/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGlobalRegistry_002Eg_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F3cc424ce28293e197699c4e55c1b4a24aac9bd75_003FGlobalRegistry_002Eg_002Ecs_002Fz_003A3_002D2/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGlobalRegistry_002Eg_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F6f3e482ddee84872fa4917a75473b425c3154e_003FGlobalRegistry_002Eg_002Ecs_002Fz_003A5_002D4/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGlobalRegistry_002Eg_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fe6fa4548b681609c78398e67b195bc2a6e96a5e_003FGlobalRegistry_002Eg_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMethodBaseInvoker_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb71753e8d7f5410a90c2ccab6d9fac7bd1be00_003Fb6_003Fb10878e7_003FMethodBaseInvoker_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMethodBaseInvoker_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb71753e8d7f5410a90c2ccab6d9fac7bd1be00_003Fb6_003Fb10878e7_003FMethodBaseInvoker_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=Polonium_002EGenerators_002FResources/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
6
src/Attributes/ProxyNode.cs
Normal file
6
src/Attributes/ProxyNode.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Polonium.Attributes;
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class ProxyNode : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
9
src/DataStructures/ProgressInfo.cs
Normal file
9
src/DataStructures/ProgressInfo.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Polonium.DataStructures;
|
||||
|
||||
public abstract class ProgressInfo
|
||||
{
|
||||
public int CurrentTaskIndex { get; set; }
|
||||
public int TotalTasks { get; set; }
|
||||
public abstract float Progress { get; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
29
src/Managers/LoaderManager.cs
Normal file
29
src/Managers/LoaderManager.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Polonium.DataStructures;
|
||||
|
||||
namespace Polonium.Managers;
|
||||
|
||||
public abstract class LoaderManager<T>
|
||||
where T : ProgressInfo
|
||||
{
|
||||
public bool Started { get; private set; } = false;
|
||||
public bool Finished { get; protected set; } = false;
|
||||
public void Start()
|
||||
{
|
||||
if(Started)
|
||||
throw new InvalidOperationException("Loader is already started");
|
||||
Started = true;
|
||||
Thread load = new Thread(LoadTask);
|
||||
load.Start();
|
||||
|
||||
}
|
||||
|
||||
public abstract T QueryProgress();
|
||||
|
||||
public abstract void Load();
|
||||
|
||||
public void LoadTask()
|
||||
{
|
||||
Load();
|
||||
Finished = true;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using Godot;
|
||||
using Polonium.Attributes;
|
||||
|
||||
namespace Polonium.Scenes;
|
||||
[GlobalClass]
|
||||
[Tool]
|
||||
[ProxyNode]
|
||||
public partial class CameraScene : Scene
|
||||
{
|
||||
private Camera2D Camera { get; set; }
|
||||
@@ -20,8 +20,7 @@ public partial class CameraScene : Scene
|
||||
}
|
||||
public override void _Ready()
|
||||
{
|
||||
Camera = new Camera2D();
|
||||
AddChild(Camera);
|
||||
Camera = GetNode<Camera2D>("Camera");
|
||||
base._Ready();
|
||||
}
|
||||
protected void ZoomIn() => Zoom = Mathf.Max(Zoom * (1 + ZoomRate), MaxZoom);
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
namespace Polonium.Scenes;
|
||||
[GlobalClass]
|
||||
public partial class LayerCameraScene : CameraScene
|
||||
{
|
||||
private Node2D LayerHolder { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
LayerHolder = new Node2D();
|
||||
base._Ready();
|
||||
}
|
||||
}
|
||||
30
src/Scenes/LoadingScene.cs
Normal file
30
src/Scenes/LoadingScene.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Godot;
|
||||
using Polonium.DataStructures;
|
||||
using Polonium.Managers;
|
||||
|
||||
namespace Polonium.Scenes;
|
||||
|
||||
public abstract partial class LoadingScene<T> : Scene
|
||||
where T : ProgressInfo
|
||||
{
|
||||
public Scene AfterLoaded { get; set; }
|
||||
|
||||
private double CoolDown { get; set; } = 0;
|
||||
|
||||
public LoaderManager<T> Manager { get; set; }
|
||||
|
||||
protected abstract void ConsumeProgressInfo(T progressInfo);
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
CoolDown += delta;
|
||||
if (CoolDown < 1)
|
||||
return;
|
||||
CoolDown = 0;
|
||||
T progress = Manager.QueryProgress();
|
||||
ConsumeProgressInfo(progress);
|
||||
if(Manager.Finished)
|
||||
PoloniumRegistry.Instance.RootScene.SwitchScene(AfterLoaded);
|
||||
base._Process(delta);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using Godot;
|
||||
using Polonium.Attributes;
|
||||
|
||||
namespace Polonium.Scenes;
|
||||
[GlobalClass]
|
||||
[ProxyNode]
|
||||
public partial class RootScene : Node2D
|
||||
{
|
||||
private Scene CurrentScene { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user