Add CycleShopCategory

This commit is contained in:
LoafyLemon 2024-05-03 22:20:51 +01:00
parent a8d183e804
commit 978be68399

View File

@ -1,5 +1,5 @@
init python:
class SwitchShopCategory(Action):
class SetShopCategory(Action):
def __init__(self, category: str, items: list):
self.category = category
self.items = items
@ -19,6 +19,37 @@ init python:
renpy.restart_interaction()
class CycleShopCategory(Action):
def __init__(self, screenvar: str, items: dict, reverse=False):
self.screenvar = screenvar
self.items = items
self.reverse = reverse
def __call__(self):
cs = renpy.current_screen()
if cs is None:
raise Exception("No current screen.")
scope = cs.scope
var = self.screenvar
current = scope[var]
keys_list = list(self.items.keys())
try:
current_index = keys_list.index(current)
except ValueError:
current_index = -1
step = -1 if self.reverse else 1
next_index = (current_index + step) % len(keys_list)
next_key = keys_list[next_index]
scope[var] = next_key
SetShopCategory(next_key, self.items[next_key])()
class SortFilter(Action):
def __init__(self, screenvar: str, sort_keys=None, filter_keys=None):
self.screenvar = screenvar