From d14fe598b57246dd73d46aeac589a0d1c5639b2b Mon Sep 17 00:00:00 2001 From: LoafyLemon Date: Sat, 10 Jun 2023 16:45:31 +0100 Subject: [PATCH] Android permissions * Patched If function to work with actions * Added AskPermission class action * Added storage permission request for mods menu --- game/scripts/gui/main_menu.rpy | 2 +- game/scripts/mods.rpy | 10 ++++++++++ game/scripts/options.rpy | 2 ++ game/scripts/utility/engine.rpy | 9 +++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/game/scripts/gui/main_menu.rpy b/game/scripts/gui/main_menu.rpy index 48459ef6..c080aa97 100644 --- a/game/scripts/gui/main_menu.rpy +++ b/game/scripts/gui/main_menu.rpy @@ -278,7 +278,7 @@ screen navigation(title=None): textbutton _("Preferences") action ShowMenu("preferences") sensitive is_sensitive if main_menu: - textbutton _("Mods") sensitive (bool(mods_list) and is_sensitive) action ShowMenu("mods") + textbutton _("Mods") sensitive (bool(mods_list) and is_sensitive) action If(AskPermission("android.permission.WRITE_EXTERNAL_STORAGE"), ShowMenu("mods"), Function(renpy.notify, "Please grant storage permissions to enable modding functionality.")) textbutton _("Credits") action Jump("credits") sensitive is_sensitive if not renpy.mobile: textbutton _("Quit") action Quit(confirm=not main_menu) sensitive is_sensitive diff --git a/game/scripts/mods.rpy b/game/scripts/mods.rpy index 108d2058..124aa58e 100644 --- a/game/scripts/mods.rpy +++ b/game/scripts/mods.rpy @@ -80,3 +80,13 @@ init python: mods.add(name) renpy.restart_interaction() + + class AskPermission(Action, NoRollback): + def __init__(self, name): + self.name = name + + def __call__(self): + if not renpy.android: + return True + + return renpy.android and (renpy.check_permission(self.name) or renpy.request_permission(self.name)) diff --git a/game/scripts/options.rpy b/game/scripts/options.rpy index a41d0e1a..fa95995b 100644 --- a/game/scripts/options.rpy +++ b/game/scripts/options.rpy @@ -180,3 +180,5 @@ init python: build.classify("cache/**", "android") build.classify("game/saves/**", None) build.classify("game/mods/**", None) + + build.android_permissions = ["android.permission.WRITE_EXTERNAL_STORAGE"] diff --git a/game/scripts/utility/engine.rpy b/game/scripts/utility/engine.rpy index d284ad24..f8877f08 100644 --- a/game/scripts/utility/engine.rpy +++ b/game/scripts/utility/engine.rpy @@ -202,3 +202,12 @@ init -100 python: for k, v in compressed.items(): setattr(self, k, v) + + # The original does not support nested actions. + @renpy.pure + def If(expression, true=None, false=None): + + if isinstance(expression, Action): + expression = expression() + + return true if expression else false \ No newline at end of file