Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 1 addition & 33 deletions scripts/build_chemistry_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,7 @@

import yaml


class GameYamlLoader(yaml.SafeLoader):
"""YAML loader that accepts SS14 custom tags."""


def construct_tagged_value(
loader: GameYamlLoader,
tag_suffix: str,
node: yaml.Node,
) -> Any:
if isinstance(node, yaml.MappingNode):
value = loader.construct_mapping(node, deep=True)
elif isinstance(node, yaml.SequenceNode):
value = loader.construct_sequence(node, deep=True)
else:
value = loader.construct_scalar(node)

return {
"yamlTag": f"!{tag_suffix}",
"value": value,
}


GameYamlLoader.add_multi_constructor("!", construct_tagged_value)

from chemistry_yaml import GameYamlLoader, normalize_parents

FTL_MESSAGE_RE = re.compile(
r"^([A-Za-z0-9][A-Za-z0-9_-]*)\s*=\s*(.*)$"
Expand Down Expand Up @@ -154,14 +130,6 @@ def read_chemical_group_sections(
return guide_path, group_sections


def normalize_parents(value: Any) -> list[str]:
if isinstance(value, str):
return [value]
if isinstance(value, list):
return [item for item in value if isinstance(item, str)]
return []


def read_upstream_reagents(game_source: Path) -> dict[str, dict[str, Any]]:
root = game_source / "Resources/Prototypes/Reagents"
if not root.is_dir():
Expand Down
38 changes: 38 additions & 0 deletions scripts/chemistry_yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from __future__ import annotations

from typing import Any

import yaml


class GameYamlLoader(yaml.SafeLoader):
"""YAML loader that accepts and preserves SS14 custom tags."""


def construct_tagged_value(
loader: GameYamlLoader,
tag_suffix: str,
node: yaml.Node,
) -> Any:
if isinstance(node, yaml.MappingNode):
value = loader.construct_mapping(node, deep=True)
elif isinstance(node, yaml.SequenceNode):
value = loader.construct_sequence(node, deep=True)
else:
value = loader.construct_scalar(node)

return {
"yamlTag": f"!{tag_suffix}",
"value": value,
}


GameYamlLoader.add_multi_constructor("!", construct_tagged_value)


def normalize_parents(value: Any) -> list[str]:
if isinstance(value, str):
return [value]
if isinstance(value, list):
return [item for item in value if isinstance(item, str)]
return []
49 changes: 1 addition & 48 deletions scripts/index_chemistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,7 @@

import yaml


class GameYamlLoader(yaml.SafeLoader):
"""YAML loader that accepts and preserves SS14 custom tags."""


def construct_tagged_value(
loader: GameYamlLoader,
tag_suffix: str,
node: yaml.Node,
) -> Any:
if isinstance(node, yaml.MappingNode):
value = loader.construct_mapping(
node,
deep=True,
)
elif isinstance(node, yaml.SequenceNode):
value = loader.construct_sequence(
node,
deep=True,
)
else:
value = loader.construct_scalar(node)

return {
"yamlTag": f"!{tag_suffix}",
"value": value,
}


GameYamlLoader.add_multi_constructor(
"!",
construct_tagged_value,
)

from chemistry_yaml import GameYamlLoader, normalize_parents

SOURCE_ROOTS = [
{
Expand All @@ -67,20 +34,6 @@ def construct_tagged_value(
]


def normalize_parents(value: Any) -> list[str]:
if isinstance(value, str):
return [value]

if isinstance(value, list):
return [
item
for item in value
if isinstance(item, str)
]

return []


def read_file(
game_source: Path,
path: Path,
Expand Down