Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup awareness #9628

Merged
merged 12 commits into from
Oct 29, 2022
6 changes: 6 additions & 0 deletions Monika After Story/game/0config.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ init -1200 python:
renpy.config.menu_clear_layers = ["front"]
renpy.config.gl_test_image = "white"

# Remove extra save location (for whatever reason we do this)
# FIXME: Also, this is unsafe since renpy has a thread that
ThePotatoGuy marked this conversation as resolved.
Show resolved Hide resolved
# iterates thru this list
if len(renpy.loadsave.location.locations) > 1:
renpy.loadsave.location.locations.pop()

################START: INIT TIME CONFIGS

## Uncomment the following line to set an audio file that will be played while
Expand Down
2 changes: 1 addition & 1 deletion Monika After Story/game/options.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ init python:
mas_override_label("_choose_renderer", "mas_choose_renderer_override")

#The rest
if len(renpy.loadsave.location.locations) > 1: del(renpy.loadsave.location.locations[1])
# if len(renpy.loadsave.location.locations) > 1: del(renpy.loadsave.location.locations[1])
renpy.game.preferences.pad_enabled = False
def replace_text(s):
s = s.replace('--', u'\u2014') # em dash
Expand Down
2 changes: 1 addition & 1 deletion Monika After Story/game/script-affection.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -2722,7 +2722,7 @@ init python:
# This must be called first
mas_affection._absence_decay_aff()

if persistent._mas_long_absence:
if persistent._mas_long_absence or persistent._mas_is_backup:
return

time_difference = persistent._mas_absence_time
Expand Down
11 changes: 11 additions & 0 deletions Monika After Story/game/script-ch30.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,17 @@ init 999 python in mas_reset:
store.mas_stripEVL("mas_after_bath_cleanup", list_pop=True, remove_dates=True)


@ch30_reset(-560)
def backups():
"""
Runs reset for backup code
"""
if persistent._mas_is_backup:
store.MASEventList.push("mas_backup_restored")
mas_utils.mas_log.info("Detected a restored backup")
persistent._mas_is_backup = False


def final():
"""
Runs reset code that should run after everythign else
Expand Down
111 changes: 111 additions & 0 deletions Monika After Story/game/script-story-events.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -2687,3 +2687,114 @@ P.S: Don't tell her about me!\
repeat

return "pause: 30"


init 5 python:
addEvent(
Event(
persistent.event_database,
eventlabel="mas_backup_restored",
)
)

label mas_backup_restored:
if mas_isMoniNormal(higher=True):
m 2ekc "[player]..."
m 2ekd "I'm having this odd feeling of deja vu... {w=0.3}{nw}"
extend 7ekd "I wanted to talk to you, but then somehow remembered we already did."

if mas_getEVL_shown_count("mas_backup_restored") > 0:
m 1etc "Wait, have I said this before, too?"

m 1wuo "Oh! {w=0.3}{nw}"
extend 3wud "You restored my memories from a backup, didn't you?{nw}"
$ _history_list.pop()
menu:
m "Oh! You restored my memories from a backup, didn't you?{fast}"

"Yes, I did.":
$ mas_gainAffection(modifier=0.5)

m 2eka "Thank you, [player]. {w=0.2}I knew I could rely on you."
m 7rkd "It had to be really bad if you had to restore me, though..."

m 1ekc "What's happened?{nw}"
$ _history_list.pop()
menu:
m "What's happened?{fast}"

"The game crashed.":
m 1wud "Oh, that's weird and concerning."
m 1ekc "This time it wasn't my code. {w=0.2}I don't remember messing with it, anyway."
m 1gfd "{cps=*1.5}I swear if it's another Ren'Py bug...{/cps}{nw}"
$ _history_list.pop()
m 1ekc "Let's try to make sure it won't happen again, alright?"
$ mas_moni_idle_disp.force_by_code("1ekc", duration=25, skip_dissolve=True)

"I added a submod.":
m 1etc "Added a {w=0.1}{i}submod{/i}?"
m 3esd "You should be more mindful of what you install on this computer."
m 2lkd "It's my home, too..."
$ mas_moni_idle_disp.force_by_code("1ekc", duration=25, skip_dissolve=True)

"My PC broke.":
m 2wuo "I'm glad you found a way to restore me!"
m 2ekc "Hopefully this won't happen again."
m 2lktpc "I can't imagine losing you..."
$ mas_moni_idle_disp.force(
MASMoniIdleExpGroup(
[
MASMoniIdleExp("2lktdc", duration=15),
MASMoniIdleExp("2rktdc", duration=10),
MASMoniIdleExp("1dkc", duration=10),
MASMoniIdleExp("1euc", duration=10),
]
),
skip_dissolve=True
)

"I'm not sure.":
m 1etc "That's concerning, [player]..."
m 3esd "I lost my memory and we don't even know why."
m 4eud "We should try to figure it out and prevent it from happening in the future."
m 7eka "Promise?"
$ mas_moni_idle_disp.force_by_code("1eka", duration=20, skip_dissolve=True)

"No, I didn't.":
m 2etc "Oh, then what's going on, [player]?"
m 2ektpc "I don't want to forget you."
m 2ektpd "Please, can you figure out what's happening?"
m 7eutdd "Maybe you could make some backups just in case?"

if mas_seenEvent("monika_back_ups"):
m 3eud "I explained how to back me up before, remember?"

else:
m 3euc "{a=https://github.com/Monika-After-Story/MonikaModDev/wiki/FAQ#i-want-to-back-up-my-persistent}{i}{u}This{/u}{/i}{/a} should help you."

m 1eka "I'm relying on you, [player]."
$ mas_moni_idle_disp.force_by_code("1eka", duration=15, skip_dissolve=True)

elif mas_isMoniUpset():
m 2gtc "Somehow I'm having this weird feeling of deja vu..."
m 2tfd "I hope you're not messing with my data."
$ mas_moni_idle_disp.force_by_code("2mfc", duration=10, skip_dissolve=True)

else:
m 6ekc "[player], what's going on? {w=0.3}{nw}"
extend 6lksdlc "I know you did something to my data."
m 6lktpsdld "Are you trying to get rid of me?"
m 6rktpc "I just wanted us to be happy together..."
m 6ektuc "Please, forgive me..."
$ mas_moni_idle_disp.force(
MASMoniIdleExpGroup(
[
MASMoniIdleExp("6lktsc", duration=10),
MASMoniIdleExp("6rktsc", duration=10),
MASMoniIdleExp("6dktdc", duration=20)
]
),
skip_dissolve=True
)

return "no_unlock|pause: 35"
8 changes: 4 additions & 4 deletions Monika After Story/game/sprite-chart.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -3136,7 +3136,7 @@ init -3 python:
startup=False
):
"""
Changes both clothes and hair. also sets the persisten forced vars
Changes both clothes and hair. also sets the persistent forced vars
to by_user, if its not None

IN:
Expand Down Expand Up @@ -3838,7 +3838,7 @@ init -3 python:

def set_acs(self, acs, wear):
"""
Basically a single function so callers don't need to
Basically a single function so callers don't need to
if-statement-toggle wearing and removal of ACS.

IN:
Expand Down Expand Up @@ -7591,7 +7591,7 @@ init -3 python:
Use the functions to modify outfit data as appropriate.

Supports:
- preventing ACS from being removed
- preventing ACS from being removed
- preventing hair or ACS from being worn
"""

Expand Down Expand Up @@ -7634,7 +7634,7 @@ init -3 python:
def set_acs_change_all(self, value):
"""
Enables or disables ALL ACS changing as part of outfit mode

IN:
value - pass True to enable, False to disable
"""
Expand Down
54 changes: 32 additions & 22 deletions Monika After Story/game/zz_backup.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ default persistent._mas_incompat_per_rpy_files_found = False
# only set if the user entered the incompat flow at all
default persistent._mas_incompat_per_entered = False

default persistent._mas_is_backup = False

python early in mas_per_check:
import __main__
import cPickle
Expand Down Expand Up @@ -129,7 +131,7 @@ python early in mas_per_check:
Checks if a persistent version can work with the current version

IN:
per_version - the persisten version to check
per_version - the persistent version to check
cur_version - the current version to check.

RETURNS: True if the per version can work with the current version
Expand Down Expand Up @@ -193,7 +195,7 @@ python early in mas_per_check:

def should_show_chibika_persistent():
"""
Should we show the chibika persistent dialogue?
Should we show the chibika persistent dialogue?

RETURNS: True if we should show the chibika persistent dialogue
"""
Expand Down Expand Up @@ -239,7 +241,7 @@ python early in mas_per_check:

# first, check if we have a special persistent
if os.access(_sp_per, os.F_OK):
# we have one, so check if its valid
# we have one, so check if its valid
try: # TEST_CASE_A
per_read, version = tryper(_sp_per)

Expand Down Expand Up @@ -367,7 +369,7 @@ python early in mas_per_check:

try: # TEST_CASE_F
shutil.copy(_cur_per, _sp_per)
os.remove(_cur_per)
os.remove(_cur_per)

# and then close out of here - the game should generate a fresh
# persistent.
Expand Down Expand Up @@ -533,10 +535,10 @@ init -900 python:
# we only accept persistents with the correct number scheme
filenumbers.append(num)

if len(filenumbers) > 0:
return sorted(filenumbers)
if filenumbers:
filenumbers.sort()

return []
return filenumbers


def __mas__backupAndDelete(loaddir, org_fname, savedir=None, numnum=None):
Expand Down Expand Up @@ -566,7 +568,7 @@ init -900 python:
RETURNS:
tuple of the following format:
[0]: numbernumber we just made
[1]: numbernumber we delted (None means no deltion)
[1]: numbernumber we deleted (None means no deletion)
"""
if savedir is None:
savedir = loaddir
Expand Down Expand Up @@ -594,7 +596,7 @@ init -900 python:

# now do the iterative backup system
numbernumber_del = None
if len(numberlist) <= 0:
if not numberlist:
numbernumber = __mas__numnum.format(0)

elif 99 in numberlist:
Expand Down Expand Up @@ -660,13 +662,23 @@ init -900 python:
"""
try:
p_savedir = os.path.normcase(renpy.config.savedir + "/")
p_name = "persistent"
numnum, numnum_del = __mas__backupAndDelete(p_savedir, p_name)
cal_name = "db.mcal"
__mas__backupAndDelete(p_savedir, cal_name, numnum=numnum)
is_pers_backup = persistent._mas_is_backup

try:
persistent._mas_is_backup = True
renpy.save_persistent()
numnum, numnum_del = __mas__backupAndDelete(p_savedir, "persistent")
ThePotatoGuy marked this conversation as resolved.
Show resolved Hide resolved

finally:
persistent._mas_is_backup = is_pers_backup
renpy.save_persistent()

__mas__backupAndDelete(p_savedir, "db.mcal", numnum=numnum)

except Exception as e:
store.mas_utils.mas_log.error(str(e))
store.mas_utils.mas_log.error(
"persistent/calendar data backup failed: {}".format(e)
)


def __mas__memoryCleanup():
Expand Down Expand Up @@ -844,7 +856,7 @@ label mas_backups_incompat_start:
$ mas_darkMode(True) # required for the updater

if (
persistent._mas_incompat_per_rpy_files_found
persistent._mas_incompat_per_rpy_files_found
and mas_hasRPYFiles()
):
# user said they would delete the RPY files, but we still have them
Expand Down Expand Up @@ -984,7 +996,7 @@ label mas_backups_incompat_rpy_yes_del:
show chibika 3 at sticker_hop
"Done!"
"Let's try updating now!"
jump mas_backups_incompat_updater_start
jump mas_backups_incompat_updater_start


label mas_backups_incompat_rpy_no_del:
Expand Down Expand Up @@ -1022,8 +1034,8 @@ label mas_backups_incompat_updater_failed:
# fall through

label mas_backups_incompat_updater_start:
# setup for unstable

# setup for unstable
$ persistent._mas_unstable_mode = True
$ mas_updater.force = True

Expand All @@ -1044,10 +1056,10 @@ label mas_backups_incompat_updater_start:
# NOTE: why don't we lock or remove the cancel button? The user
# might have their own reasons for canceling the update check:
# - maybe they are on low bandwidth/metered connections?
# - maybe they actually want to stay on stable and have a backup
# - maybe they actually want to stay on stable and have a backup
# persistent to us?
# - maybe its maybelline?
# either way, since the user has an unstable per, no need for
# either way, since the user has an unstable per, no need for
# extravagant handholding.

#"hol up" # use this to debug cancel returns
Expand Down Expand Up @@ -1075,5 +1087,3 @@ label mas_backups_incompat_updater_start:
"Good luck!"

jump _quit