-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: allow inserting ActionC comments
- Loading branch information
Showing
6 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|