Android permissions

* Patched If function to work with actions
* Added AskPermission class action
* Added storage permission request for mods menu
This commit is contained in:
LoafyLemon 2023-06-10 16:45:31 +01:00
parent 012084ca10
commit d14fe598b5
4 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -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))

View File

@ -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"]

View File

@ -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