Last active
September 4, 2017 01:41
-
-
Save ilikenwf/61f86cf7b47a2a1749a8 to your computer and use it in GitHub Desktop.
SWG Core3 (SWGEmu) Object Create/Import script (kinda crappy but it works)
This file contains hidden or 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
#!/usr/bin/python | |
import sys | |
import os | |
objectluas=[] | |
cuserverobjs=[] | |
def objtypes(x): | |
return { | |
'building': 'SharedBuildingObjectTemplate', | |
'creature': 'SharedCreatureObjectTemplate', | |
'draft_schematic': 'SharedDraftSchematicObjectTemplate', | |
'installation': 'SharedInstallationObjectTemplate', | |
'intangible': 'SharedIntangibleObjectTemplate', | |
'mobile': 'SharedCreatureObjectTemplate', | |
'resource_container': 'SharedResourceContainerObjectTemplate', | |
'ship': 'SharedShipObjectTemplate', | |
'static': 'SharedStaticObjectTemplate', | |
'tangible': 'SharedTangibleObjectTemplate', | |
'weapon': 'SharedWeaponObjectTemplate' | |
}[x] | |
def main(): | |
f=open('cufiles.txt') | |
global objectluas | |
global cuserverobjs | |
for line in f: | |
# line is the raw object based path with .lua extension | |
line=line.replace('\n', '') | |
# path to the file we'll be writing | |
luapath='Core3-CU/MMOCoreORB/bin/scripts/'+line | |
# varname is the variable | |
varname=line.replace('/', '_').replace('.lua','') | |
# base directory of the lua in question | |
luadir=os.path.dirname(os.path.abspath(luapath)) | |
# determine the object template type | |
dirtype=line.split('/') | |
objtemplatetype=objtypes(dirtype[1]) | |
# build the shared version | |
pathparts=line.split('/') | |
pathparts[-1] = 'shared_'+pathparts[-1] | |
sharedpath='/'.join(pathparts) | |
sharedpath=sharedpath.replace('.lua', '.iff') | |
sharedvarname=sharedpath.replace('/','_').replace('.iff','') | |
# first create the proper lua for the object in question | |
lua=open(luapath,'w') | |
lua.write('--Copyright 2015 CUEmu\n\n') | |
lua.write(varname+' = '+sharedvarname+':new {\n\n}\n\n') | |
lua.write('ObjectTemplates:addTemplate('+varname+', "'+line.replace('.lua', '.iff')+'")') | |
lua.close() | |
# write it to the cu_objects file | |
cuobjects=open(luadir+'/cu_objects.lua','w') | |
cuobjects.write(sharedvarname+' = '+objtemplatetype+':new {\n') | |
cuobjects.write('\tclientTemplateFileName = "'+sharedpath+'"\n}\n\n') | |
cuobjects.write('ObjectTemplates:addClientTemplate('+sharedvarname+', "'+sharedpath+'")\n\n\n') | |
cuobjects.close() | |
# write it to the cu_serverobjects file | |
cuserverobj=open(luadir+'/cu_serverobjects.lua','w') | |
cuserverobj.write('includeFile("'+line+'")\n') | |
cuserverobj.close() | |
# append to our array of cu_objects paths if not already in there | |
if luadir+'/cu_objects.lua' not in objectluas: objectluas.append(luadir+'/cu_objects.lua') | |
# append to our array of cu_serverobjects paths if not already in there | |
if luadir+'/cu_serverobjects.lua' not in cuserverobjs: cuserverobjs.append(luadir+'/cu_serverobjects.lua') | |
f.close() | |
# append our objectluas to the allobjects.lua file | |
allobjects=open('Core3-CU/MMOCoreORB/bin/scripts/object/allobjects.lua', 'a') | |
allobjects.write('\n\n--CUEmu objects\n\n') | |
for objlua in objectluas: | |
# yes i realize the second replace below is lazy and nasty...one off script, don't care | |
allobjects.write('\nincludeFile("'+objlua.replace('\n','').replace('/home/matt/Desktop/Core3-CU/MMOCoreORB/bin/scripts/object/','')+'")') | |
allobjects.close() | |
# append our cu_serverobjects to the serverobjects.lua file | |
serverobjs=open('Core3-CU/MMOCoreORB/bin/scripts/object/serverobjects.lua', 'a') | |
serverobjs.write('\n\n--CUEmu serverobjects\n\n') | |
for serverobjectfile in cuserverobjs: | |
# yes i realize the second replace below is lazy and nasty...one off script, don't care | |
serverobjs.write('\nincludeFile("'+serverobjectfile.replace('\n','').replace('/home/asdf/Desktop/Core3-CU/MMOCoreORB/bin/scripts/object/','')+'")') | |
serverobjs.close() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment