/
cli.py
executable file
·178 lines (171 loc) · 6.03 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python
#@section License
#
#Copyright (C) 2013 ssss
#This file is a part of the GameEditor.
#
#This program 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 3 of the License, or
#(at your option) any later version.
#
#This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
import sys
from CliClass import *
if sys.version_info[0]<3:
from ConfigParser import *
else:
from configparser import *
testGameFile=tmpDir+"testgame.exe"
def newGame(code):
resourcePath=os.path.join(module_path(),"ideicons")+"/"
game=GameFile()
room=game.newRoom()
room.setMember("caption","room 0")
instance=room.newInstance()
object=game.newObject()
event=GameEvent(game)
action=GameAction(game)
action.setActionCode(code)#'show_message("show");game_end();'
#event.eventNumber=0
#event.setMember("eventKind",0)
event.actions.append(action)
object.addEvent(event)
sprite=game.newSprite()
sprite.newSubimageFile(resourcePath+"resources/sprite.png")
object.setMember("sprite",sprite)
instance.setMember("object",object)
game.newSettings()
game.newGameInformation()
return game
def loadPreferences():
print_notice("loading preferences: "+os.path.expanduser("~/.GameEditor.cfg"))
config = ConfigParser()
config.read([os.path.join(module_path(), "GameEditor.cfg"), os.path.expanduser("~/.GameEditor.cfg")])
global enigmaPath
enigmaPath = config.get("Editor", "enigmadev")
#print_notice("changing directory to enigma-dev: "+self.enigmaPath)
try:
os.chdir(enigmaPath)
except:
print_notice("error changing directory to enigma-dev: "+self.enigmaPath)
if IfEnigmaDir():
print_notice("enigma installation found")
else:
print_error("enigma installation not found")
def cli():
loadPreferences()
parser = argparse.ArgumentParser(description="input file with no options builds in debug mode and runs game")
parser.add_argument("filein", metavar="FILE.GMK", type=str, nargs="?",help="read file (gmk gm81 egm gmx gmz formats)")
parser.add_argument("-o", dest="writefile", help="convert to output file and exit (gmk ggg formats)")
parser.add_argument("-c", dest="code", help="empty game with object create event code")
parser.add_argument("-r", dest="run", action="store_true", help="run game emode (debug is default)")
parser.add_argument("-d", dest="dontrun", action="store_true", help="compile but don't run game")
parser.add_argument("-t", dest="test", action="store_true", help="don't compile with enigma")
parser.add_argument("-s", dest="stats", action="store_true", help="stats")
parser.add_argument("-p", dest="python", help="run python line")
parser.add_argument("-i", dest="interactive", action="store_true", help="interactive")
parser.add_argument("-j", dest="dejavu", action="store_true", help="print dejavu AST for scripts")
parser.add_argument("--mingw", dest="mingw", action="store_true", help="compile for Windows with mingw")
parser.add_argument("--audio", dest="audio", help="OpenAL, SFML, DirectSound, FMOD")
parser.add_argument("--collision", dest="collision", help="Precise, BBox")
parser.add_argument("--graphics", dest="graphics", help="OpenGL1, OpenGL3, Direct3D9")
if len(sys.argv)==1:
args = parser.parse_args(["--help"])
else:
args = parser.parse_args()
try:
app = QtGui.QApplication(["python"])
except:
print_warning("pyqt4 is not installed")
app = None
if args.filein:
p=args.filein
if p[-1] in ["/","\\"]:
p=p[:-1]
ext=os.path.splitext(p)[1]
gameFile=GameFile()
print_notice("loading "+p)
gameFile.Read(p)
if args.code:
gameFile=newGame(args.code)
if args.stats:
gameFile.printBasicStats()
sys.exit(0)
if args.python:
import code
t=code.InteractiveConsole(locals())
t.runsource(args.python)
if args.interactive:
gameFile.resourceTree.PrintRecursive()
import code
t=code.InteractiveConsole(locals())
t.interact()
if args.dejavu:
import dejavu.parser
for s in gameFile.scripts:
print_notice("AST for script "+s.getMember("name"))
code=s.getMember("value")
#print code
print(dejavu.parser.parseGML(s.getMember("name"), code.decode()))
for o in gameFile.objects:
for ec in o.events:
name = o.getMember("name") + "_" + str(ec.eventNumber) + "_" + str(ec.getMember("eventKind"))
print_notice("AST for "+name)
code = getActionsCode(ec.actions)#.encode()
#print code
print(dejavu.parser.parseGML(name, code))
sys.exit(0)
if args.writefile:
if args.writefile=="-":
ext=".ggg"
gameFile.SaveExt(ext,tmpDir+"crap",wfile=sys.stdout)
else:
ext=os.path.splitext(os.path.split(args.writefile)[1])[1]
if ext not in [".gmk",".gm81",".egm",".gmx",".ggg"]:
print_error("unsupported output type "+ext)
print_notice("saving "+args.writefile)
gameFile.SaveExt(ext,args.writefile)
sys.exit(0)
gameFile.app=app
if args.test:
sys.exit(0)
emode=emode_compile#make turns compile into debug
if args.run:
emode=emode_run
#if os.name!="nt":
# redirectStdout()
#realStdout=sys.stdout
# setRealStdout(realStdout)
if args.audio:
gameFile.EnigmaTargetAudio=args.audio#"OpenAL"
if args.collision:
gameFile.EnigmaTargetCollision=args.collision
if args.graphics:
gameFile.EnigmaTargetGraphics=args.graphics#"OpenGL3"
if args.mingw:
gameFile.EnigmaTargetWindowing="Win32"
gameFile.EnigmaTargetCompiler="MinGW32"
#gameFile.EnigmaTargetWidget="Win32"
LoadPluginLib()
print_notice("ENIGMA compile")
error=gameFile.compileRunEnigma(testGameFile,emode)
if error:
print_notice("returned error")
sys.exit(1)
restoreStdout()
if emode==emode_compile:
if args.dontrun:
print_notice("not running game")
else:
print_notice("run game")
print_notice(subprocess.check_output([testGameFile]))
if __name__=="__main__":
cli()