Skip to content

Commit

Permalink
@novely/core — deal with saves
Browse files Browse the repository at this point in the history
  • Loading branch information
yhdgms1 committed Mar 30, 2024
1 parent ad9cff1 commit 70d6c5f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@novely/core",
"description": "Novely - powerful visual novel engine for creating interactive stories and games with branching narratives and rich multimedia content",
"version": "0.27.4",
"version": "0.28.0",
"type": "module",
"sideEffects": false,
"publishConfig": {
Expand Down
20 changes: 8 additions & 12 deletions packages/core/src/novely.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ const novely = <
addEventListener('visibilitychange', onVisibilityChange);
addEventListener('beforeunload', throttledEmergencyOnStorageDataChange);

const save = (override = false, type: Save[2][1] = override ? 'auto' : 'manual') => {
const save = (type: Save[2][1]) => {
if (!coreData.get().dataLoaded) return;

/**
Expand Down Expand Up @@ -436,13 +436,9 @@ const novely = <
if (!last) return add();

/**
* Find last save that was created in current session, and check if it is latest in an array
*
* [auto save 1]
* [manual save 1]
* [auto save 2] <- should not replace first auto save
* Belongs to current game session
*/
const isLatest = findLastIndex(prev.saves, (value) => times.has(value[2][0])) === prev.saves.length - 1;
if (!times.has(last[2][0])) return add();

/**
* Update type and time information
Expand All @@ -455,7 +451,7 @@ const novely = <
/**
* Even in override is false, we will replace auto save with maual, because they are the same thing basically
*/
if (last[2][1] === 'auto' && type === 'manual' && isIdentical) {
if (last[2][1] === 'auto' && type === 'manual') {
return replace();
}

Expand All @@ -467,11 +463,11 @@ const novely = <
return prev;
}

if (!override || !isLatest) {
return add();
if (last[2][1] === 'auto' && type === 'auto') {
return replace();
}

return replace();
return add();
});
};

Expand Down Expand Up @@ -823,7 +819,7 @@ const novely = <

stack.push(current);

save(true, 'auto');
save('auto');
};

const nextPath = (path: Path) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ type RendererInit = {
set: (save: Save<State>) => Promise<void>;
restore: (save?: Save<State>) => Promise<void>;

save: (override?: boolean, type?: Save<State>[2][1]) => void;
save: (type: Save<State>[2][1]) => void;
newGame: () => void;
exit: (force?: boolean) => void;
back: () => Promise<void>;
Expand Down
2 changes: 1 addition & 1 deletion packages/solid-renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@novely/solid-renderer",
"version": "0.23.1",
"version": "0.24.0",
"type": "module",
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ControlPanelButtons: VoidComponent<ControlPanelButtonsProps> = (props) =>
class="button control-panel__button"
title={data.t('DoSave')}
onClick={() => {
data.options.save(false, 'manual');
data.options.save('manual');
}}
>
<span class="control-panel__button__content">{data.t('DoSave')}</span>
Expand All @@ -57,7 +57,7 @@ const ControlPanelButtons: VoidComponent<ControlPanelButtonsProps> = (props) =>
class="button control-panel__button"
title={data.t('Settings')}
onClick={() => {
data.options.save(false, 'auto');
data.options.save('auto');
props.openSettings();
}}
>
Expand Down

0 comments on commit 70d6c5f

Please sign in to comment.