You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-11 13:10:58 +00:00
Display BitField[Enum] in docs to distinguish from Enum
This commit is contained in:
@@ -27,7 +27,7 @@ MARKUP_ALLOWED_SUBSEQUENT = " -.,:;!?\\/'\")]}>"
|
||||
# Used to translate section headings and other hardcoded strings when required with
|
||||
# the --lang argument. The BASE_STRINGS list should be synced with what we actually
|
||||
# write in this script (check `translate()` uses), and also hardcoded in
|
||||
# `doc/translations/extract.py` to include them in the source POT file.
|
||||
# `scripts/extract_classes.py` (godotengine/godot-editor-l10n repo) to include them in the source POT file.
|
||||
BASE_STRINGS = [
|
||||
"All classes",
|
||||
"Globals",
|
||||
@@ -65,6 +65,7 @@ BASE_STRINGS = [
|
||||
"This method is used to construct a type.",
|
||||
"This method doesn't need an instance to be called, so it can be called directly using the class name.",
|
||||
"This method describes a valid operator to use with this type as left-hand operand.",
|
||||
"This value is an integer composed as a bitmask of the following flags.",
|
||||
]
|
||||
strings_l10n: Dict[str, str] = {}
|
||||
|
||||
@@ -362,13 +363,14 @@ class State:
|
||||
|
||||
|
||||
class TypeName:
|
||||
def __init__(self, type_name: str, enum: Optional[str] = None) -> None:
|
||||
def __init__(self, type_name: str, enum: Optional[str] = None, is_bitfield: bool = False) -> None:
|
||||
self.type_name = type_name
|
||||
self.enum = enum
|
||||
self.is_bitfield = is_bitfield
|
||||
|
||||
def to_rst(self, state: State) -> str:
|
||||
if self.enum is not None:
|
||||
return make_enum(self.enum, state)
|
||||
return make_enum(self.enum, self.is_bitfield, state)
|
||||
elif self.type_name == "void":
|
||||
return "void"
|
||||
else:
|
||||
@@ -376,7 +378,7 @@ class TypeName:
|
||||
|
||||
@classmethod
|
||||
def from_element(cls, element: ET.Element) -> "TypeName":
|
||||
return cls(element.attrib["type"], element.get("enum"))
|
||||
return cls(element.attrib["type"], element.get("enum"), element.get("is_bitfield") == "true")
|
||||
|
||||
|
||||
class DefinitionBase:
|
||||
@@ -1280,7 +1282,7 @@ def make_type(klass: str, state: State) -> str:
|
||||
return klass
|
||||
|
||||
|
||||
def make_enum(t: str, state: State) -> str:
|
||||
def make_enum(t: str, is_bitfield: bool, state: State) -> str:
|
||||
p = t.find(".")
|
||||
if p >= 0:
|
||||
c = t[0:p]
|
||||
@@ -1296,7 +1298,12 @@ def make_enum(t: str, state: State) -> str:
|
||||
c = "@GlobalScope"
|
||||
|
||||
if c in state.classes and e in state.classes[c].enums:
|
||||
return f":ref:`{e}<enum_{c}_{e}>`"
|
||||
if is_bitfield:
|
||||
if not state.classes[c].enums[e].is_bitfield:
|
||||
print_error(f'{state.current_class}.xml: Enum "{t}" is not bitfield.', state)
|
||||
return f"|bitfield|\<:ref:`{e}<enum_{c}_{e}>`\>"
|
||||
else:
|
||||
return f":ref:`{e}<enum_{c}_{e}>`"
|
||||
|
||||
# Don't fail for `Vector3.Axis`, as this enum is a special case which is expected not to be resolved.
|
||||
if f"{c}.{e}" != "Vector3.Axis":
|
||||
@@ -1412,6 +1419,7 @@ def make_footer() -> str:
|
||||
"This method doesn't need an instance to be called, so it can be called directly using the class name."
|
||||
)
|
||||
operator_msg = translate("This method describes a valid operator to use with this type as left-hand operand.")
|
||||
bitfield_msg = translate("This value is an integer composed as a bitmask of the following flags.")
|
||||
|
||||
return (
|
||||
f".. |virtual| replace:: :abbr:`virtual ({virtual_msg})`\n"
|
||||
@@ -1420,6 +1428,7 @@ def make_footer() -> str:
|
||||
f".. |constructor| replace:: :abbr:`constructor ({constructor_msg})`\n"
|
||||
f".. |static| replace:: :abbr:`static ({static_msg})`\n"
|
||||
f".. |operator| replace:: :abbr:`operator ({operator_msg})`\n"
|
||||
f".. |bitfield| replace:: :abbr:`BitField ({bitfield_msg})`\n"
|
||||
)
|
||||
|
||||
|
||||
@@ -1834,7 +1843,7 @@ def format_text_block(
|
||||
escape_post = True
|
||||
|
||||
elif cmd.startswith("enum"):
|
||||
tag_text = make_enum(link_target, state)
|
||||
tag_text = make_enum(link_target, False, state)
|
||||
escape_pre = True
|
||||
escape_post = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user