Skip to content
Draft
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
2 changes: 1 addition & 1 deletion nml/actions/action6.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from nml import free_number_list, generic
from nml.actions import base_action

free_parameters = free_number_list.FreeNumberList(list(range(0x40, 0x80)), "No free parameters available to use for internal computations.", "No unique free parameters available for internal computations.")
free_parameters = free_number_list.FreeNumberList(list(range(0, 0x80)), "No free parameters available to use for internal computations.", "No unique free parameters available for internal computations.")

def print_stats():
"""
Expand Down
33 changes: 33 additions & 0 deletions nml/actions/actionC.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
__license__ = """
NML is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

NML is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with NML; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA."""

from nml.actions import base_action

class ActionC(base_action.BaseAction):
def __init__(self, text):
self.text = text

def write(self, file):
#<Sprite-number> * <Length> 0C [<ignored>]
size = len(self.text)+1
file.start_sprite(size)
file.print_bytex(0x0C)
file.print_string(self.text, final_zero = False)
file.newline()
file.end_sprite()

def parse_actionC(comment):
return [ActionC(comment.text.value)]

38 changes: 38 additions & 0 deletions nml/ast/comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
__license__ = """
NML is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

NML is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with NML; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA."""

from nml.actions import actionC
from nml.ast import base_statement
from nml import expression, generic

class Comment(base_statement.BaseStatement):
def __init__(self, text, pos):
base_statement.BaseStatement.__init__(self, "comment()", pos)
self.text = text

def pre_process(self):
self.text = self.text.reduce()
if not isinstance(self.text, expression.StringLiteral):
raise generic.ScriptError("Comment must be a string literal.", self.text.pos)

def debug_print(self, indentation):
generic.print_dbg(indentation, 'Comment:')
self.text.debug_print(indentation + 2)

def get_action_list(self):
return actionC.parse_actionC(self)

def __str__(self):
return 'comment(%s);\n' % (self.text,)
12 changes: 8 additions & 4 deletions nml/ast/grf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
with NML; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA."""

from nml import expression, generic, grfstrings, global_constants
from nml.actions import action8, action14
from nml import expression, free_number_list, generic, grfstrings, global_constants
from nml.actions import action6, action8, action14
from nml.ast import base_statement

palette_node = None
Expand All @@ -23,9 +23,11 @@
"""
Statistics about registers used for parameters.
The 1st field is the largest parameter register used.
The 2nd field is the maximum amount of parameter registers available. This is where L{action6.free_parameters} begins.
The 2nd field is the maximum amount of parameter registers available.
After preprocessing the GRF block, the limit for L{action6.free_parameters} is set to
the number of reserved params.
"""
param_stats = [0, 0x40]
param_stats = [0, 0x80]

def print_stats():
"""
Expand Down Expand Up @@ -132,6 +134,8 @@ def pre_process(self):
raise generic.ScriptError("No free parameters available. Consider assigning <num> manually and combine multiple bool parameters into a single bitmask parameter using <bit>.", self.pos)
if param_num > param_stats[0]:
param_stats[0] = param_num
action6.free_parameters = free_number_list.FreeNumberList(list(range(param_stats[0], 0x80)), "No free parameters available to use for internal computations.", "No unique free parameters available for internal computations.")


def debug_print(self, indentation):
generic.print_dbg(indentation, 'GRF')
Expand Down
7 changes: 6 additions & 1 deletion nml/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA."""

from nml import generic, expression, tokens, nmlop, unit
from nml.ast import assignment, basecost, cargotable, conditional, deactivate, disable_item, error, font, general, grf, item, loop, produce, tracktypetable, replace, spriteblock, switch, townnames, snowline, skipall, tilelayout, alt_sprites, base_graphics, override, sort_vehicles
from nml.ast import assignment, basecost, cargotable, conditional, deactivate, disable_item, error, font, general, grf, item, loop, produce, tracktypetable, replace, spriteblock, switch, townnames, snowline, skipall, tilelayout, alt_sprites, base_graphics, override, sort_vehicles, comment
from nml.actions import actionD, real_sprite
import ply.yacc as yacc

Expand Down Expand Up @@ -119,6 +119,7 @@ def p_main_block(self, t):
| snowline
| engine_override
| sort_vehicles
| comment
| basecost'''
t[0] = t[1]

Expand Down Expand Up @@ -719,6 +720,10 @@ def p_sort_vehicles(self, t):
'sort_vehicles : SORT_VEHICLES LPAREN expression_list RPAREN SEMICOLON'
t[0] = sort_vehicles.SortVehicles(t[3], t.lineno(1))

def p_comment(self, t):
'comment : COMMENT LPAREN expression RPAREN SEMICOLON'
t[0] = comment.Comment(t[3], t.lineno(1))

def p_tilelayout(self, t):
'tilelayout : TILELAYOUT ID LBRACE tilelayout_list RBRACE'
t[0] = tilelayout.TileLayout(t[2], t[4], t.lineno(1))
Expand Down
1 change: 1 addition & 0 deletions nml/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
'recolour_sprite' : 'RECOLOUR_SPRITE',
'engine_override' : 'ENGINE_OVERRIDE',
'sort' : 'SORT_VEHICLES',
'comment' : 'COMMENT',
}

line_directive1_pat = re.compile(r'\#line\s+(\d+)\s*(\r?\n|"(.*)"\r?\n)')
Expand Down
9 changes: 9 additions & 0 deletions regression/031_comment.nml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
grf {
grfid: "NML\31";
name: string(STR_REGRESSION_NAME);
desc: string(STR_REGRESSION_DESC);
version: 0;
min_compatible_version: 0;
}

comment("test");
Binary file added regression/expected/031_comment.grf
Binary file not shown.
20 changes: 20 additions & 0 deletions regression/expected/031_comment.nfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Automatically generated by GRFCODEC. Do not modify!
// (Info version 32)
// Escapes: 2+ 2- 2< 2> 2u< 2u> 2/ 2% 2u/ 2u% 2* 2& 2| 2^ 2sto = 2s 2rst = 2r 2psto 2ror = 2rot 2cmp 2ucmp 2<< 2u>> 2>>
// Escapes: 71 70 7= 7! 7< 7> 7G 7g 7gG 7GG 7gg 7c 7C
// Escapes: D= = DR D+ = DF D- = DC Du* = DM D* = DnF Du<< = DnC D<< = DO D& D| Du/ D/ Du% D%
// Format: spritenum imagefile depth xpos ypos xsize ysize xrel yrel zoom flags

0 * 4 \d3

1 * 54 14 "C" "INFO"
"B" "VRSN" \w4 \dx00000000
"B" "MINV" \w4 \dx00000000
"B" "NPAR" \w1 00
"B" "PALS" \w1 "A"
"B" "BLTR" \w1 "8"
00
00
2 * 52 08 08 "NML\31" "NML regression test" 00 "A test newgrf testing NML" 00
3 * 5 0C "test"