Skip to content

Commit

Permalink
Save overhaul (#2584)
Browse files Browse the repository at this point in the history
* clean up FlxSave

* new default FlxSave args and migration tool

* spacing

* check save status for allflixel auto-saving

* fix 4.0.5 CI

* comments [ignore CI]

* documentation

* eraseSave

* update changelog

* update changelog

* actually use minFileSize in flush

* add mergeData and isEmpty

* docs

* merge legacy save only if new save is empty

* new save path, move legacy data for any bind args

* changelog

* add new pr# to changelog

* default localPath to company name

* simplify isEmpty

* FlxSharedObject.exists()
  • Loading branch information
Geokureli authored Jun 30, 2022
1 parent 99b33eb commit 75a2789
Show file tree
Hide file tree
Showing 3 changed files with 440 additions and 61 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
- `WatchFrontEnd`: added `FlxG.watch.addFunction` ([#2500](https://github.com/HaxeFlixel/flixel/pull/2500))
- `FlxPoint`: added binary operators `+`, `-`, `+=`, `-=`, `*`, and `*=` ([#2557](https://github.com/HaxeFlixel/flixel/pull/2557))
- `FlxColor`: added `rgb` getter and setter ([#2555](https://github.com/HaxeFlixel/flixel/pull/2555))
- `FlxSave`: added `migrateDataFrom`, `status` and `isBound` ([#2566](https://github.com/HaxeFlixel/flixel/pull/2566))
- `FlxSave`: added `mergeDataFrom`, `mergeData` `status`, `isBound` and `isEmpty`
([#2566](https://github.com/HaxeFlixel/flixel/pull/2566))
([#2584](https://github.com/HaxeFlixel/flixel/pull/2584))

#### Bugfixes:

Expand Down
28 changes: 5 additions & 23 deletions flixel/FlxG.hx
Original file line number Diff line number Diff line change
Expand Up @@ -668,30 +668,12 @@ class FlxG
if (save.isBound)
return;

// Use Project.xml data to determine save id
var meta = stage.application.meta;
var name = meta["file"];
var path:String = null;

// replace invalid characters with hyphens
var invalidChars = ~/[ ~%&\\;:"',<>?#]/;
name = invalidChars.split(name).join("-");

#if !flash
// On most browsers using the full URL path often causes a new save path to be created
// every time a new version of the game is updated. Especially on portals like Newgrounds.
// just set the path to your company name, to ensure a unique storage id.
path = meta["company"];
if (path == null || path == "")
path = "HaxeFlixel";
else
path = invalidChars.split(path).join("-");
#end

// Create a save based on project metadata (since 5.0.0).
// Use Project.xml data to determine save id (since 5.0.0).
final name = stage.application.meta["file"];
save.bind(FlxSave.validate(name));
// look for the pre 5.0 save and convert it if it exists.
save.bind(name, path);
save.migrateDataFrom("flixel");
if (save.isEmpty())
save.mergeDataFrom("flixel", null, false, false);
}

/**
Expand Down
Loading

0 comments on commit 75a2789

Please sign in to comment.