Convert existing cds using the new system

(cherry picked from commit 4770be5f1b)
This commit is contained in:
Gouvernathor 2024-03-28 22:28:53 +01:00 committed by LoafyLemon
parent 6408942054
commit c5c04ff79e

View File

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