|
| 1 | +__license__ = """ |
| 2 | +NML is free software; you can redistribute it and/or modify |
| 3 | +it under the terms of the GNU General Public License as published by |
| 4 | +the Free Software Foundation; either version 2 of the License, or |
| 5 | +(at your option) any later version. |
| 6 | +
|
| 7 | +NML is distributed in the hope that it will be useful, |
| 8 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | +GNU General Public License for more details. |
| 11 | +
|
| 12 | +You should have received a copy of the GNU General Public License along |
| 13 | +with NML; if not, write to the Free Software Foundation, Inc., |
| 14 | +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.""" |
| 15 | + |
| 16 | +from nml import expression, generic, global_constants |
| 17 | +from nml.actions import action2, action2layout, action2real, real_sprite |
| 18 | +from nml.ast import base_statement |
| 19 | + |
| 20 | + |
| 21 | +class InArrayFor(base_statement.BaseStatement): |
| 22 | + def __init__(self, array, param, expressions, pos=None): |
| 23 | + base_statement.BaseStatement.__init__(self, "for", pos, False, False) |
| 24 | + self.array = array |
| 25 | + self.param = param |
| 26 | + self.expressions = expressions |
| 27 | + |
| 28 | + |
| 29 | +class For(base_statement.BaseStatementList): |
| 30 | + def __init__(self, name, param_list, layout_sprite_list, pos=None): |
| 31 | + base_statement.BaseStatement.__init__(self, "spritelayout", pos, False, False) |
| 32 | + self.initialize(name, None, len(param_list)) |
| 33 | + self.param_list = param_list |
| 34 | + self.register_map = {} # Set during action generation for easier referencing |
| 35 | + self.layout_sprite_list = layout_sprite_list |
| 36 | + |
| 37 | + # Do not reduce expressions here as they may contain variables |
| 38 | + # And the feature is not known yet |
| 39 | + def pre_process(self): |
| 40 | + # Check parameter names |
| 41 | + seen_names = set() |
| 42 | + for param in self.param_list: |
| 43 | + if not isinstance(param, expression.Identifier): |
| 44 | + raise generic.ScriptError("spritelayout parameter names must be identifiers.", param.pos) |
| 45 | + if param.value in seen_names: |
| 46 | + raise generic.ScriptError("Duplicate parameter name '{}' encountered.".format(param.value), param.pos) |
| 47 | + seen_names.add(param.value) |
| 48 | + # spritelayout_base_class.pre_process(self) |
| 49 | + |
| 50 | + def collect_references(self): |
| 51 | + return [] |
| 52 | + |
| 53 | + def debug_print(self, indentation): |
| 54 | + generic.print_dbg(indentation, "Sprite layout:", self.name.value) |
| 55 | + generic.print_dbg(indentation + 2, "Parameters:") |
| 56 | + for param in self.param_list: |
| 57 | + param.debug_print(indentation + 4) |
| 58 | + generic.print_dbg(indentation + 2, "Sprites:") |
| 59 | + for layout_sprite in self.layout_sprite_list: |
| 60 | + layout_sprite.debug_print(indentation + 4) |
| 61 | + |
| 62 | + def __str__(self): |
| 63 | + params = "" if not self.param_list else "({})".format(", ".join(str(x) for x in self.param_list)) |
| 64 | + return "spritelayout {}{} {{\n{}\n}}\n".format( |
| 65 | + str(self.name), params, "\n".join(str(x) for x in self.layout_sprite_list) |
| 66 | + ) |
| 67 | + |
| 68 | + def get_action_list(self): |
| 69 | + action_list = [] |
| 70 | + if self.prepare_act2_output(): |
| 71 | + for feature in sorted(self.feature_set): |
| 72 | + if feature == 0x04: |
| 73 | + continue |
| 74 | + action_list.extend(action2layout.get_layout_action2s(self, feature)) |
| 75 | + return action_list |
0 commit comments