WTS/game/scripts/cds.rpy

82 lines
2.3 KiB
Plaintext
Raw Normal View History

python early:
def parse_chibi(lexer):
who = lexer.simple_expression()
action = lexer.simple_expression()
return (who, action)
def execute_chibi(parsed_object):
print(f"{parsed_object}")
who, action = parsed_object
func = eval(f"{who[:3]}_chibi_new.{action}")
print(f"Execution: {who} {action}")
def lint_chibi(parsed_object):
who, action = parsed_object
try:
chibi = eval(f"{who[:3]}_chibi_new") # TODO: Update naming once testing is done
except Exception:
renpy.error(f"Character chibi not defined: {who}")
def predict_chibi(parsed_object):
who, action = parsed_object
chibi = eval(f"{who[:3]}_chibi_new")
doll = eval(f"{who}")
layers = (
l[0] for pose in chibi.poses.keys()
for k in doll.states.values() if k[0] and k[2]
for l in k[0].get_layers(k[0]._hash, subpath=posixpath.join("chibi", pose)).values()
)
return layers
renpy.register_statement(
name="chibi",
parse=parse_chibi,
execute=execute_chibi,
lint=lint_chibi,
predict=predict_chibi,
)
def parse_random(lexer):
l = lexer.subblock_lexer()
choices = []
while l.advance():
loc = l.get_location()
condition = "True"
if l.keyword('block'):
l.require(':')
l.expect_eol()
l.expect_block('block')
block = l.subblock_lexer().renpy_block()
choices.append((block, condition))
elif l.keyword('if'):
l.expect_block("if block")
condition = l.require(l.python_expression)
l.require(':')
block = l.subblock_lexer().renpy_block()
choices.append((block, condition))
else:
stmt = l.renpy_statement()
choices.append((stmt, condition))
return choices
def next_random(choices):
choices = [block for block, cond in choices if eval(cond)]
return renpy.random.choice(choices)
renpy.register_statement(
name="random",
block=True,
parse=parse_random,
next=next_random,
)