Skip to content

Commit

Permalink
polish up backups system
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed May 15, 2024
1 parent 7614d89 commit eb7d96f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
14 changes: 7 additions & 7 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
{
"id": "hjfod.bettersave",
"version": "1.1.0",
"version": "1.1.1",
"importance": "required"
}
],
Expand All @@ -47,6 +47,12 @@
}
},
"settings": {
"auto-save": {
"type": "bool",
"default": true,
"name": "Auto-save",
"description": "Automatically saves the level every 5 minutes, as well as creates a backup. The backups created by autosave get automatically deleted after 3 new ones have been created to avoid using too much disk space"
},
"mouse-move-on-zoom": {
"type": "bool",
"default": true,
Expand Down Expand Up @@ -126,12 +132,6 @@
"name": "Show Grid on Size Change",
"description": "If the grid is currently hidden and you use the controls to change its size, its toggled on",
"platforms": ["windows", "android64"]
},
"auto-save": {
"type": "bool",
"default": true,
"name": "Auto-save",
"description": "Automatically saves the level every 5 minutes, as well as creates a backup. The backups created by autosave get automatically deleted after 3 new ones have been created to avoid using too much disk space"
}
},
"tags": ["editor", "enhancement", "utility", "customization"]
Expand Down
Binary file added resources/backups.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/features/backups/AutoSave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class $modify(AutoSaveUI, EditorUI) {
}
void onAutoSaveTick(float) {
constexpr size_t COUNTDOWN = 5;
constexpr size_t AUTO_SAVE_INTERVAL = 20;
constexpr size_t AUTO_SAVE_INTERVAL = 60 * 5;

m_fields->secondsSinceLastAutoSave += 1;
if (m_fields->secondsSinceLastAutoSave > AUTO_SAVE_INTERVAL - COUNTDOWN) {
Expand Down
16 changes: 9 additions & 7 deletions src/features/backups/Backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,17 @@ Result<> Backup::cleanAutomated(GJGameLevel* level) {

constexpr size_t MAX_AUTOMATED_COUNT = 3;

// Do the cleanup
size_t ix = 0;
for (auto backup : automated) {
// Keep only the MAX_AUTOMATED_COUNT newest automated backups
if (++ix > MAX_AUTOMATED_COUNT) {
GEODE_UNWRAP(backup->deleteThis());
// Do the cleanup if needed
if (automated.size() > MAX_AUTOMATED_COUNT) {
size_t ix = 0;
for (auto backup : automated) {
// Keep only the MAX_AUTOMATED_COUNT newest automated backups
if (++ix > MAX_AUTOMATED_COUNT) {
GEODE_UNWRAP(backup->deleteThis());
}
}
automated.erase(automated.begin() + MAX_AUTOMATED_COUNT, automated.end());
}
automated.erase(automated.begin() + MAX_AUTOMATED_COUNT, automated.end());

return Ok();
}
6 changes: 4 additions & 2 deletions src/features/backups/BackupsUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ class $modify(BackupLevelLayer, EditLevelLayer) {
return false;

if (auto menu = this->getChildByID("folder-menu")) {
auto backupsSpr = CCSprite::createWithSpriteFrameName("GJ_myServerBtn_001.png");
backupsSpr->setScale(.65f);
auto backupsSpr = CircleButtonSprite::createWithSpriteFrameName(
"backups.png"_spr, 1.f, CircleBaseColor::Green
);
backupsSpr->setScale(.8f);
auto backupsBtn = CCMenuItemSpriteExtra::create(
backupsSpr, this, menu_selector(BackupLevelLayer::onBackups)
);
Expand Down

0 comments on commit eb7d96f

Please sign in to comment.