HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.97k stars 434 forks source link

Why is `FlxSave.validate` private? #3058

Open DetectiveBaldi opened 7 months ago

DetectiveBaldi commented 7 months ago

FlxSave.validate and FlxSave.validateAndWarn are not public functions. Is there a reason for this? The requirement of needing a @:privateAccess call seems unnecessary.

Fields such as invalidChars are also private, this could be avoided by making the setter null.

Geokureli commented 7 months ago

if we make validate public, it should be renamed to something less vague like validateSavePath (keep and deprecate the old private func too in case anyone was using @:privateAccess, and rather than making invalidChars read only, lets add a public isValidSavePath().

Geokureli commented 7 months ago

Also if you're calling save.bind() with a custom path, there's a good chance you're doing something wrong. The preferred way of using a custom save path is to change the title and company fields in your project.xml's app node. Can you talk about why you need this?

DetectiveBaldi commented 7 months ago

Also if you're calling save.bind() with a custom path, there's a good chance you're doing something wrong. The preferred way of using a custom save path is to change the title and company fields in your project.xml's app node. Can you talk about why you need this?

I'm making a syetem where the player can select multiple saves, or have the ability to create new ones while also being able to change their name, I want to validate the name inputted to make sure it's valid

Geokureli commented 7 months ago

what about having multiple save slots under one actual save? pretty sure you can use a Maps in FlxSave or if not, can use DynamicAccess, example:

final data:DynamicAccess<{score:Int, levelsCompleted:Int}> = cast FlxG.save.data;
if (data.exists(saveSlotName))
{
    final slotData = data.get(saveSlotName);
    trace('score: ${slotData.score}, levels completed: ${slotData.levelsCompleted}');
}
else
{
    data.set(saveSlotName, { score: 0, levelsCompleted:0 });
    trace('No existing slot named "$saveSlotName", creating new one');
    FlxG.save.data.flush();
}