Skip to content

Commit

Permalink
Cheesefruit groves merge (#95)
Browse files Browse the repository at this point in the history
* Whitespace changes

* Merging feature improvements

* Fixed errors
  • Loading branch information
QueenOfSquiggles authored Oct 24, 2023
1 parent 80560e6 commit 77d1684
Show file tree
Hide file tree
Showing 142 changed files with 258 additions and 197 deletions.
Empty file modified Core/Assets/Fonts/DelaGothicOne-Regular.ttf
100755 → 100644
Empty file.
Empty file modified Core/Assets/Fonts/NotoSans-Regular.ttf
100755 → 100644
Empty file.
Empty file modified Core/Assets/Fonts/OFL.txt
100755 → 100644
Empty file.
Empty file modified Core/Assets/Fonts/OpenDyslexic-Regular.otf
100755 → 100644
Empty file.
Empty file modified Core/Assets/Materials/GUI/blur_layer.gdshader
100755 → 100644
Empty file.
Empty file modified Core/Assets/Packs/Kenney Crosshair Pack/crosshair118.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified Core/Assets/Sfx/ClickRandom.tres
100755 → 100644
Empty file.
Empty file modified Core/Assets/Sfx/SelectRandom.tres
100755 → 100644
Empty file.
Empty file modified Core/Assets/Sfx/click_blip.wav
100755 → 100644
Empty file.
Empty file modified Core/Assets/Sfx/select_blip.wav
100755 → 100644
Empty file.
Empty file modified Core/Assets/Translation/translations_sheet.csv
100755 → 100644
Empty file.
Binary file modified Core/Assets/Translation/translations_sheet.en.translation
Binary file not shown.
Empty file modified Core/Assets/Translation/translations_sheet.ods
100755 → 100644
Empty file.
Empty file modified Core/LICENSE.md
100755 → 100644
Empty file.
Empty file modified Core/MetaConfig/ISaveSlotInformationProvider.cs
100755 → 100644
Empty file.
Empty file modified Core/MetaConfig/SaveSlotSettings.cs
100755 → 100644
Empty file.
Empty file modified Core/MetaConfig/SlotInfoProviderResource.cs
100755 → 100644
Empty file.
Empty file modified Core/MetaConfig/SquigglesCoreConfigFile.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/AI/UtilitySelector/IUtilitySelectionComponent.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/AI/UtilitySelector/UtilitySelector.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Audio/SceneBGMLoader.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Camera/CameraBrain.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Camera/CinematicSequence.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Camera/DynamicDOFRay.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Camera/VirtualCamera.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/CharStats/CharStatFloat.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/CharStats/CharStatFloatMod.cs
100755 → 100644
Empty file.
30 changes: 19 additions & 11 deletions Core/Modules/CharStats/CharStatManager.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Squiggles.Core.CharStats;
/// The root node for CharStat Management. It contains the stats and ensures everything is as expected. Use this to offload managing certain resource bars in your characters.
/// </summary>
[GlobalClass]
public partial class CharStatManager : Node {
public partial class CharStatManager : Node, IHasSaveData {

/// <summary>
/// A signal delegate for <see cref="OnStatChange"/> which notifies when a stat changes
Expand Down Expand Up @@ -259,28 +259,33 @@ public void DebugPrintStats() {
Print.Debug($"End Stats Manager: {Name}");
}

private const string EMBED_KEY = "__stats";
/// <summary>
/// Saves the stats out to a <see cref="SaveDataBuilder"/>. This should be called by the parent scene node. Such as the character controller.
/// </summary>
/// <param name="build">the builder to use.</param>
public void SaveToData(ref SaveDataBuilder build) {
public void SaveToData(ref SaveDataBuilder parentBuilder) {
var build = new SaveDataBuilder();
foreach (var stat in _stats) {
build.PutFloat($"StatS_{stat.Key}", stat.Value);
build.PutFloat(stat.Key, stat.Value);
}
foreach (var stat in _dynamicStats) {
build.PutFloat($"StatS_{stat.Key}_Value", stat.Value.Value);
build.PutFloat($"StatS_{stat.Key}_Max", stat.Value.MaxValue);
build.PutFloat($"StatS_{stat.Key}_Regen", stat.Value.RegenRate);
build.PutFloat($"{stat.Key}_Value", stat.Value.Value);
build.PutFloat($"{stat.Key}_Max", stat.Value.MaxValue);
build.PutFloat($"{stat.Key}_Regen", stat.Value.RegenRate);
}
parentBuilder.Append(build, EMBED_KEY);
}

/// <summary>
/// Loads in the properties of the stats from the given <see cref="SaveDataBuilder"/>. This should be called by the parent scene node. Such as the character controller.
/// </summary>
/// <param name="build">the builder to use</param>
public void LoadFromData(SaveDataBuilder build) {
public void LoadFromData(SaveDataBuilder parentBuilder) {
var build = parentBuilder.LoadEmbedded(EMBED_KEY);
if (build is null) { return; }
foreach (var stat in _stats) {
if (!build.GetFloat($"StatS_{stat.Key}", out var val)) {
if (!build.GetFloat(stat.Key, out var val)) {
continue;
}

Expand All @@ -290,15 +295,15 @@ public void LoadFromData(SaveDataBuilder build) {
}
}
foreach (var stat in _dynamicStats) {
if (!build.GetFloat($"StatS_{stat.Key}_Value", out var val)) {
if (!build.GetFloat($"{stat.Key}_Value", out var val)) {
continue;
}

if (!build.GetFloat($"StatS_{stat.Key}_Max", out var max)) {
if (!build.GetFloat($"{stat.Key}_Max", out var max)) {
continue;
}

if (!build.GetFloat($"StatS_{stat.Key}_Regen", out var regen)) {
if (!build.GetFloat($"{stat.Key}_Regen", out var regen)) {
continue;
}

Expand All @@ -312,4 +317,7 @@ public void LoadFromData(SaveDataBuilder build) {
}
RebuildStatDict();
}

public void Serialize(SaveDataBuilder builder) => SaveToData(ref builder);
public void Deserialize(SaveDataBuilder builder) => LoadFromData(builder);
}
Empty file modified Core/Modules/Character/FootstepSoundsComponent.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Character/GroundMaterial.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Character/GroundMaterialPoller.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Data/Access.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Data/AudioBuses.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Data/Controls.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Data/Effects.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Data/GameplaySettings.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Data/Graphics.cs
100755 → 100644
Empty file.
18 changes: 18 additions & 0 deletions Core/Modules/Data/IHasSaveData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Squiggles.Core.Data;

using Squiggles.Core.Data;

public interface IHasSaveData
{

/// <summary>
/// write component's save data to the save data builder. Which saving out to file is handled by parent
/// </summary>
public void Serialize(SaveDataBuilder builder);

/// <summary>
/// read component's save data from the save data builder. Which loading from file is handled by parent
/// </summary>
public void Deserialize(SaveDataBuilder builder);

}
Empty file modified Core/Modules/Data/LoadControlsMappings.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Data/LoadGraphicsSettings.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Data/ModLoadingStep.cs
100755 → 100644
Empty file.
Empty file modified Core/Modules/Data/ModRegistry.cs
100755 → 100644
Empty file.
12 changes: 12 additions & 0 deletions Core/Modules/Data/RegistrationManager.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public static T GetResource<T>(string id) where T : Resource {
return !registry.Dict.ContainsKey(id) ? null : registry.Dict[id] as T;
}

public static List<T> GetAllResourcesForType<T>() where T : Resource {
var type_name = typeof(T).Name;
if (!_registries.ContainsKey(type_name)) {
Print.Warn($"No registry found for type <{type_name}>");
return null;
}
var reg = _registries[type_name];
return reg.Dict.ToList()
.ConvertAll((e) => e.Value as T)
.Where((e) => e is not null).ToList();
}

public override void _Ready() {
ReloadRegistries();
EventBus.Data.OnModsLoaded += () => {
Expand Down
46 changes: 44 additions & 2 deletions Core/Modules/Data/SaveData.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Squiggles.Core.Data;
using System.Collections.Generic;
using System.Text.Json;
using Godot;
using Godot.Collections;
using Squiggles.Core.Attributes;
using Squiggles.Core.Error;
using Squiggles.Core.Extension;
Expand All @@ -28,7 +29,7 @@ public static class SaveData {
public static string[] GetKnownSaveSlots() {
using var dir = DirAccess.Open(SAVE_SLOT_ROOT);
if (dir == null) {
return Array.Empty<string>();
return System.Array.Empty<string>();
}

dir.IncludeHidden = false;
Expand Down Expand Up @@ -103,6 +104,8 @@ public static void LoadMostRecentSaveSlot() {
[MarkForRefactor("Currently Borked", "")]
public static void Save<T>(T data, string path, bool do_flush = false) where T : class => _defaultDataPath.Save(data, path, do_flush);

public static void SaveDict(Dictionary dict, string path, bool do_flush = false) => _defaultDataPath.SaveDict(dict, path, do_flush);

/// <summary>
/// Loads data from a json file to the serializable class.
/// </summary>
Expand All @@ -111,6 +114,7 @@ public static void LoadMostRecentSaveSlot() {
/// <returns>The data of type T that was loaded from file. </returns>
[MarkForRefactor("Currently Borked")]
public static T Load<T>(string path, bool print_errors = true) where T : class => _defaultDataPath.Load<T>(path, print_errors);
public static Dictionary LoadDict(string path, bool print_errors) => _defaultDataPath.LoadDict(path, print_errors);

/// <summary>
/// Change the <see cref="JsonSerializerOptions"/> for the root (non-save slot) SaveData system. This can be used to modify how types are serialized in JSON. Make sure this works for the Squiggles.Core.Data singletons if you want to mess with it.
Expand Down Expand Up @@ -202,7 +206,7 @@ public class DataPath {
/// <summary>
/// Any save slot metadata. Helpful for learning more about the save slot in question when presenting multiple slots.
/// </summary>
private readonly Dictionary<string, string> _saveSlotMetaData = new();
private readonly System.Collections.Generic.Dictionary<string, string> _saveSlotMetaData = new();
/// <summary>
/// Whether or not this data path allows deletion operations.
/// </summary>
Expand Down Expand Up @@ -246,6 +250,44 @@ public void Save<T>(T data, string path, bool do_flush = false, bool print_error
#endif
}
}

public void SaveDict(Dictionary dict, string path, bool do_flush = false, bool print_errors = true) {
try {
var json_text = Json.Stringify(dict, "\t");
SaveText(json_text, path);
}
catch (Exception e) {
#if DEBUG
if (print_errors) {
Print.Error($"Failed on JSON serialization process for godot dict '{dict}'.\n\tPath={path}\n\tError: {e.Message}", typeof(SaveData).FullName);
}
#endif
}
}

public Dictionary LoadDict(string path, bool print_errors) {
try {
var json_text = LoadText(path, print_errors);
if (json_text is null) {
return null;
}

if (json_text.EndsWith("}}")) {
json_text = json_text.Replace("}}", "}");
}

return Json.ParseString(json_text).AsGodotDictionary();
}
catch (Exception e) {
#if DEBUG
if (print_errors) {
Print.Error($"Failed on JSON serialization process for '{typeof(Dictionary).FullName}'.\n\tPath={path}\n\tError: {e.Message}", typeof(SaveData).FullName);
}
#endif
}
return null;
}

/// <summary>
/// Loads data from a json file to the serializable class.
/// </summary>
Expand Down
Loading

0 comments on commit 77d1684

Please sign in to comment.