add: Template for Save and config
This commit is contained in:
13
.idea/.idea.Polonium/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.Polonium/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/.idea.Hangman.SDK.iml
|
||||
/modules.xml
|
||||
/projectSettingsUpdater.xml
|
||||
/contentModel.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
4
.idea/.idea.Polonium/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.Polonium/.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
||||
8
.idea/.idea.Polonium/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.Polonium/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/.idea.Polonium/.idea/vcs.xml
generated
Normal file
8
.idea/.idea.Polonium/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<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>
|
||||
@@ -18,6 +18,7 @@
|
||||
<None Include="Package\build\$(AssemblyName).targets" Pack="true" PackagePath="build"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Package\build\publish" />
|
||||
<Content Include="summerizer.py" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
7
Polonium.sln.DotSettings.user
Normal file
7
Polonium.sln.DotSettings.user
Normal file
@@ -0,0 +1,7 @@
|
||||
<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>
|
||||
6
src/Attributes/RegistryEntity.cs
Normal file
6
src/Attributes/RegistryEntity.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Polonium.Attributes;
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class RegistryEntity : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
19
src/PoloniumRegistry.cs
Normal file
19
src/PoloniumRegistry.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Godot;
|
||||
using Polonium.Resources;
|
||||
using Polonium.Scenes;
|
||||
|
||||
namespace Polonium;
|
||||
|
||||
public class PoloniumRegistry
|
||||
{
|
||||
private static PoloniumRegistry InternalInstance { get; set; }
|
||||
public static PoloniumRegistry Instance => InternalInstance ??= new PoloniumRegistry();
|
||||
public RootScene RootScene { get; set; }
|
||||
public Config Config { get; set; }
|
||||
public Save Save { get; set; }
|
||||
|
||||
public static void Prepare()
|
||||
{
|
||||
DirAccess.MakeDirAbsolute("user://saves");
|
||||
}
|
||||
}
|
||||
16
src/Resources/Config.cs
Normal file
16
src/Resources/Config.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Godot;
|
||||
|
||||
namespace Polonium.Resources;
|
||||
|
||||
public partial class Config: Resource
|
||||
|
||||
{
|
||||
|
||||
public void Save() => ResourceSaver.Save(this, "user://Config.tres");
|
||||
|
||||
public static void Load<T>()
|
||||
where T : Config, new()
|
||||
{
|
||||
PoloniumRegistry.Instance.Config = ResourceLoader.Load<T>("user://Config.tres") ?? new T();
|
||||
}
|
||||
}
|
||||
49
src/Resources/Save.cs
Normal file
49
src/Resources/Save.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Godot;
|
||||
|
||||
namespace Polonium.Resources;
|
||||
|
||||
public abstract partial class Save : Resource
|
||||
{
|
||||
[Export]
|
||||
public string Name { get; set; }
|
||||
|
||||
public abstract class Preview
|
||||
{
|
||||
}
|
||||
|
||||
public void SaveToUser() => ResourceSaver.Save(this, $"user://saves/{Name}.tres");
|
||||
|
||||
public static void LoadFromUser<T>(string name)
|
||||
where T : Save, new()
|
||||
{
|
||||
T res = ResourceLoader.Load<T>($"user://saves/{name}.tres");
|
||||
if (res is null)
|
||||
{
|
||||
res = new T();
|
||||
res.Name = name;
|
||||
}
|
||||
|
||||
PoloniumRegistry.Instance.Save = res;
|
||||
}
|
||||
|
||||
public void Load() => PoloniumRegistry.Instance.Save = this;
|
||||
|
||||
public static IEnumerable<T> ListSaves<T>()
|
||||
where T : Save
|
||||
{
|
||||
DirAccess dir = DirAccess.Open("user://saves");
|
||||
if(dir is null)
|
||||
{
|
||||
DirAccess.MakeDirRecursiveAbsolute("user://saves");
|
||||
yield break;
|
||||
}
|
||||
|
||||
foreach (string save in dir.GetFiles())
|
||||
{
|
||||
if(!save.EndsWith(".tres"))
|
||||
continue;
|
||||
yield return ResourceLoader.Load<T>($"user://saves/{save}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,18 @@
|
||||
using Godot;
|
||||
|
||||
namespace Polonium.Scenes;
|
||||
|
||||
public abstract partial class CameraScene : Scene
|
||||
[GlobalClass]
|
||||
[Tool]
|
||||
public partial class CameraScene : Scene
|
||||
{
|
||||
private Camera2D Camera { get; set; }
|
||||
protected abstract float MaxZoom { get; }
|
||||
protected abstract float MinZoom { get; }
|
||||
protected abstract float ZoomRate { get; }
|
||||
[Export(PropertyHint.Range)]
|
||||
public float MaxZoom { get; set; }
|
||||
[Export(PropertyHint.Range)]
|
||||
public float MinZoom { get; set; }
|
||||
[Export(PropertyHint.Range)]
|
||||
public float ZoomRate { get; set; }
|
||||
[Export(PropertyHint.Range)]
|
||||
private float Zoom
|
||||
{
|
||||
get => Camera.Zoom.X;
|
||||
@@ -15,11 +20,12 @@ public abstract partial class CameraScene : Scene
|
||||
}
|
||||
public override void _Ready()
|
||||
{
|
||||
Camera = GetNode<Camera2D>("Camera");
|
||||
Camera = new Camera2D();
|
||||
AddChild(Camera);
|
||||
base._Ready();
|
||||
}
|
||||
protected void ZoomIn() => Mathf.Max(Zoom * (1 + ZoomRate), MaxZoom);
|
||||
protected void ZoomOut() => Mathf.Min(Zoom * (1 - ZoomRate), MinZoom);
|
||||
protected void ZoomIn() => Zoom = Mathf.Max(Zoom * (1 + ZoomRate), MaxZoom);
|
||||
protected void ZoomOut() => Zoom = Mathf.Min(Zoom * (1 - ZoomRate), MinZoom);
|
||||
protected void ZoomAt(Vector2 pos) => Camera.Position = pos;
|
||||
|
||||
}
|
||||
|
||||
14
src/Scenes/LayerCameraScene.cs
Normal file
14
src/Scenes/LayerCameraScene.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,21 @@
|
||||
using Godot;
|
||||
|
||||
namespace Polonium.Scenes;
|
||||
|
||||
public abstract partial class RootScene : Node2D
|
||||
[GlobalClass]
|
||||
public partial class RootScene : Node2D
|
||||
{
|
||||
private Polonium.Scenes.Scene CurrentScene { get; set; }
|
||||
private Scene CurrentScene { get; set; }
|
||||
|
||||
public void SwitchScene(Polonium.Scenes.Scene scene)
|
||||
public void SwitchScene(Scene scene)
|
||||
{
|
||||
if (CurrentScene != null)
|
||||
RemoveChild(CurrentScene);
|
||||
AddChild(scene);
|
||||
CurrentScene = scene;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
PoloniumRegistry.Instance.RootScene = this;
|
||||
base._Ready();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user