Compare commits

...

2 Commits

Author SHA1 Message Date
4770be5f1b Convert existing cds using the new system 2024-03-28 22:28:53 +01:00
a048b0e3cc Exception type 2024-03-28 22:27:10 +01:00

View File

@ -12,7 +12,7 @@ python early hide:
""" """
# security # security
def raiser(*args, **kwargs): def raiser(*args, **kwargs):
raise NotImplementedError("Returning an instance of the class is disabled") raise TypeError("Returning an instance of the class is disabled")
cls.__init__ = raiser cls.__init__ = raiser
name = getattr(cls, "name", cls.__name__) name = getattr(cls, "name", cls.__name__)
@ -54,29 +54,31 @@ python early hide:
evaled = {n: eval(e) for n, e in self.items()} evaled = {n: eval(e) for n, e in self.items()}
renpy.dynamic(**evaled) renpy.dynamic(**evaled)
python early: @register_decorator
def parse_chibi(l): class chibi:
@staticmethod
def parse(l):
who = l.simple_expression() who = l.simple_expression()
action = l.simple_expression() action = l.simple_expression()
return (who, action) return (who, action)
def execute_chibi(p): def execute(self):
print(f"{p}") print(f"{self}")
who, action = p who, action = self
func = eval(f"{who}_chibi.{action}") func = eval(f"{who}_chibi.{action}")
# print(f"Execution: {who} {action}") # print(f"Execution: {who} {action}")
def lint_chibi(p): def lint(self):
who, action = p who, action = self
try: try:
chibi = eval(f"{who}_chibi") chibi = eval(f"{who}_chibi")
except Exception: except Exception:
renpy.error(f"Character chibi not defined: {who}") renpy.error(f"Character chibi not defined: {who}")
def predict_chibi(p): def predict(self):
who, action = p who, action = self
chibi = eval(f"{who}_chibi") chibi = eval(f"{who}_chibi")
doll = eval(f"{who}") doll = eval(f"{who}")
@ -89,15 +91,13 @@ python early:
return layers return layers
renpy.register_statement( @register_decorator
name="chibi", class random:
parse=parse_chibi, block = True
execute=execute_chibi, predict_all = True
lint=lint_chibi,
predict=predict_chibi,
)
def parse_random(l): @staticmethod
def parse(l):
l.require(":") l.require(":")
l.expect_eol() l.expect_eol()
@ -127,8 +127,8 @@ python early:
return {"blocks": blocks} return {"blocks": blocks}
def next_random(p): def next(self):
blocks = [(block, weight) for block, weight, condition in p["blocks"] if eval(condition)] blocks = [(block, weight) for block, weight, condition in self["blocks"] if eval(condition)]
total_weight = sum(weight for _, weight in blocks) total_weight = sum(weight for _, weight in blocks)
n = renpy.random.random() * total_weight n = renpy.random.random() * total_weight
@ -139,11 +139,3 @@ python early:
n -= weight n -= weight
return block return block
renpy.register_statement(
name="random",
block=True,
predict_all=True,
parse=parse_random,
next=next_random,
)