From bbc9ad60e0502037f78fbb5c4b3ce3d322f7a565 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 28 Aug 2024 18:40:49 -0400 Subject: [PATCH] feat(examples): add Creator-Defined Statements (CDS) --- game/examples/_creator_defined_statements.rpy | 30 +++++++++++++++++++ game/examples/creator_defined_statements.rpy | 9 ++++++ game/examples/start.rpy | 3 ++ 3 files changed, 42 insertions(+) create mode 100644 game/examples/_creator_defined_statements.rpy create mode 100644 game/examples/creator_defined_statements.rpy diff --git a/game/examples/_creator_defined_statements.rpy b/game/examples/_creator_defined_statements.rpy new file mode 100644 index 0000000..d0b67b0 --- /dev/null +++ b/game/examples/_creator_defined_statements.rpy @@ -0,0 +1,30 @@ +# https://www.renpy.org/doc/html/cds.html +python early: + def parse_random(lexer): + subblock_lexer = lexer.subblock_lexer() + choices = [] + + while subblock_lexer.advance(): + with subblock_lexer.catch_error(): + statement = subblock_lexer.renpy_statement() + choices.append(statement) + + return choices + + + def next_random(choices): + return renpy.random.choice(choices) + + + def lint_random(parsed_object): + for i in parsed_object: + renpy.error(renpy.check_text_tags(i.what)) + + + renpy.register_statement( + name="random", + block=True, + parse=parse_random, + next=next_random, + lint=lint_random, + ) diff --git a/game/examples/creator_defined_statements.rpy b/game/examples/creator_defined_statements.rpy new file mode 100644 index 0000000..0edb0e1 --- /dev/null +++ b/game/examples/creator_defined_statements.rpy @@ -0,0 +1,9 @@ +label creator_defined_statements: + + # see `game/examples/_creator_defined_statements.rpy` + random: + "Hello." + "Welcome." + "Can I help you?" + + jump start diff --git a/game/examples/start.rpy b/game/examples/start.rpy index 1e52ed6..51cf3d3 100644 --- a/game/examples/start.rpy +++ b/game/examples/start.rpy @@ -11,6 +11,9 @@ label start: menu: "Which example do you want to see?" + "Creator-Defined Statements (CDS)": + jump creator_defined_statements + "Dialogue": jump dialogue