Skip to content

Commit

Permalink
Codechange: simplify cargo class constant implementation, using nml c…
Browse files Browse the repository at this point in the history
…onstants and removing need to imprt polar_fox.cargo_classes for nml generation
  • Loading branch information
andythenorth committed Oct 24, 2024
1 parent 4501118 commit 829c9dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
16 changes: 1 addition & 15 deletions src/cargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
from economies import registered_economies
from cargos import registered_cargos

# this will be suboptimal for performance, as it will be imported multiple times per compile, causing duplicat TOML parsing
# fine for v4, but for v5, this might be better centralised?
from polar_fox.cargo_classes import cargo_classes

cargo_class_scheme = cargo_classes.CargoClassSchemes().default_scheme


class Cargo(object):
"""Base class to hold cargos"""

Expand Down Expand Up @@ -161,14 +154,7 @@ def get_cargo_colour(self, economy):
return global_constants.valid_cargo_colours[self.get_numeric_id(economy)]

def get_cargo_classes_for_nml(self):
classes_mapped_to_bit_numbers = []
for cargo_class in self.cargo_classes:
classes_mapped_to_bit_numbers.append(
str(
cargo_class_scheme.cargo_classes_taxonomy[cargo_class]["bit_number"]
)
)
return "bitmask(" + ",".join(classes_mapped_to_bit_numbers) + ")"
return "bitmask(" + ",".join(self.cargo_classes) + ")"

def get_property(self, property_name, economy):
# straightforward lookup of a property, doesn't try to handle failure case of property not found; don't look up props that don't exist
Expand Down
3 changes: 3 additions & 0 deletions src/templates/cargos.pynml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ disable_item(FEAT_CARGOS, 0, 29);
<!--! don't disable 30, it's used by NARS 2 for regearing and disabling it breaks NARS 2 -->
disable_item(FEAT_CARGOS, 31, 31);

<!--! include constants for 2024 Polar Fox cargo classes -->
<tal:include metal:use-macro="load: ../polar_fox/cargo_classes/docs/cargo_class_constants.nml" />

<tal:cargos repeat="cargo registered_cargos">
spriteset(cargoicon_${cargo.id}) {
[10 + 20 * ${cargo.icon_indices[0]}, 10 + 20 * ${cargo.icon_indices[1]}, 10, 10, 0, 0, ${"ANIM," if cargo.allow_animated_pixels else None} "src/graphics/other/cargoicons.png"]
Expand Down

0 comments on commit 829c9dd

Please sign in to comment.