Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| db1a4367ae | |||
| fe8dc69cde | |||
| 3ebd020841 | |||
| 1bc5e25ed3 |
+1
-1
@@ -102,7 +102,7 @@ from renpy.character import show_display_say, predict_show_display_say, display_
|
||||
import renpy.audio.sound as sound
|
||||
import renpy.audio.music as music
|
||||
|
||||
from renpy.statements import register as register_statement
|
||||
from renpy.statements import register as register_statement, register_decorator
|
||||
from renpy.text.extras import check_text_tags
|
||||
|
||||
from renpy.memory import profile_memory, diff_memory, profile_rollback
|
||||
|
||||
@@ -309,6 +309,65 @@ def register(
|
||||
|
||||
parsers.add(name, parse_data)
|
||||
|
||||
# import inspect # only works in py3
|
||||
# register_params = frozenset(inspect.signature(register).parameters) - {"name", "parse", "execute"}
|
||||
register_params = frozenset((
|
||||
# "name", # special-cased
|
||||
# "parse", # special-cased
|
||||
"lint",
|
||||
# "execute", # special-cased
|
||||
"predict",
|
||||
"next",
|
||||
"scry",
|
||||
"block",
|
||||
"init",
|
||||
"translatable",
|
||||
"execute_init",
|
||||
"init_priority",
|
||||
"label",
|
||||
"warp",
|
||||
"translation_strings",
|
||||
"force_begin_rollback",
|
||||
"post_execute",
|
||||
"post_label",
|
||||
"predict_all",
|
||||
"predict_next",
|
||||
"execute_default",
|
||||
"reachable",
|
||||
))
|
||||
def register_decorator(cls):
|
||||
"""
|
||||
:doc: statement_register decorator
|
||||
:args:
|
||||
|
||||
A class decorator which registers a new statement.
|
||||
|
||||
The name of the statement will be the class name unless a ``name``
|
||||
class attribute is present, which should be a string.
|
||||
|
||||
The `parse` parameter to :func:`renpy.register_statement` should
|
||||
either be the class constructor itself, or a method named ``parse``
|
||||
(likely a class method or static method) returning an instance of
|
||||
the class.
|
||||
|
||||
For the `execute` parameter, Ren'Py will look for a method named
|
||||
``execute`` on the class, or if it is not found, will use the class's
|
||||
``__call__`` method to call like a function the object created by `parse`.
|
||||
|
||||
All other parameters to :func:`renpy.register_statement` should be set as
|
||||
class attributes or methods with the same name.
|
||||
"""
|
||||
name = getattr(cls, "name", cls.__name__)
|
||||
parse = getattr(cls, "parse", cls)
|
||||
execute = getattr(cls, "execute", None) or cls.__call__
|
||||
register(
|
||||
name,
|
||||
parse=parse,
|
||||
execute=execute,
|
||||
**{k:getattr(cls, k) for k in register_params.intersection(vars(cls))}
|
||||
)
|
||||
return cls
|
||||
|
||||
|
||||
def parse(node, line, subblock):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user