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