So, in my infinite frustration with AHLSL's bizarrities, and wishes to make PWLib more user friendly, I decided to write a Python script that turns code like this:
Code:
[game] <txtboxon>
<bg defensestand><lipson><char phoenixnormal><name phoenix> {This evidence proves your guilt!}
<bg witnessstand><char emanormal><name ema> {Why? I'm not even guilty!}
Interested? Read on. You can get the current version of the program for yourself by making files out of all these giant spoiler tags of doom and getting Python 2.5 for your computer. (That's the version I use, at least. I'm not sure if other versions will work.) I'll release binaries when I'm sure most fatal bugs have been squashed and such.
Did I mention you can write your own commands and change the syntax to whatever your whims desire?
Changelog August 11, 2010 - Added more commands, updated test game to use these commands.
This program makes scripting for AIGE a lot easier by letting you define fill-in-the-blank commands for anything you want. To use it, launch it like so:
NOTE: On Windows, removing the 'python' when you launch the script from the command line can make it work right if your system complains.
Replacing the bracketed with whatever files you want. A normal execution would look like:
python nezscr.py case.txt case.hlsl commands.txt
Which means that the precompiler will generate case.hlsl from the text in case.txt, using the commands in command.txt to specify what to replace with what.
The source file will have the simplified scripts, having commands and arguments enclosed in command tags, dialogue in dialogue tags, and some regular AHLSL mixed in to glue stuff together.
IS GONNA CHANGE SOON since AHLSL uses these for IF tests. Sorry. :[ || \/ By default, commands are enclosed in HTML like < > signs, with arguments separated by spaces. So the format would be <command arg1 arg2 arg3 . . .>
By defauly, dialogue is enclosed in curly brackets, so {Hi, I'm cool!} would get replaced by message("Hi, I'm cool!"); when the precompiler precompiles it.
This can all be changed in the script, though, with the parameters in the beginning.
The command file has all the commands in it. The format, by default, looks like this:
:commandname: sdhshsdhsdh(%1,%2,"%%3");
Each command name is enclosed in colons, and anything that isn't enclosed in colons is part of the command definition, sort of like an INI file. %1 means that the first argument will be put there, %2 means that the second argument will be put there, and so on. %%3, with two % signs in front of it, means that everything from that argument on is one long argument, even if the argument separator (a space by default) is used in it. This is useful when you need to set things such as evidence description, in which you'd need to use spaces.
The whole syntax can be changed with the parameters in the script, as with everything else. This is all document with comments inside the script itself.
Spoiler: nezscr.py
Code:
# SYNTAX STUFF: You can change them to whatever you want. # Useful cause right now the start and end tags conflict with # AIGE's comparison function, and I can't think of a suitable # replacment and I'm shoving that onto you. :P
# For script file... start_tag = '<' # < and > would make <command arg arg arg> end_tag = '>' d_start_tag = '{' # { and } would make {I am talking!} d_end_tag = '}' d_prefix = 'message("' # Would turn {I am talking!} into d_suffix = '");' # message("I am talking!"); arg_separator = ' ' # : would make <command: arg arg arg> arg_starter = ' ' # , would make <command arg, arg, arg>
# For command list.... comm_surrounder = ':' # So : would make :stuff: denote a new command. arg_replacer = '%' # So % would make %1 mean argument #1. arg_replacer_b = '%%' # So %% would make %%1 mean argument #1 until # the end joined by the argument separator. # (Useful when the separator is a space.)
# FILES: If no command line arguments are specified, it uses these files. # They are relative to where the script is. / is a cross platform # directory separator in Python. input_file = 'test.txt' output_file = 'case.hlsl' command_list = 'commands.txt'
import sys
def ezscr(filename,file2,cfile='commands.txt'): # Gets command list. commands = {} f = open(cfile,'r') fall = f.read() falls = fall.split(comm_surrounder) for i in range(0,len(falls),2): commands[falls[i-1]] = falls[i] f.close()
# Gets text of input file. fil = open(filename,'r') alltext = fil.read() fil.close()
# Gets all the commands. parsed = alltext.split(start_tag) for i in range(0,len(parsed)): parsed[i] = parsed[i].split(end_tag)
for i in parsed: command = i[0] arguments = command.split(arg_separator) del arguments[0] for i in commands.keys(): if command.split(arg_starter)[0].lower() == i.lower(): s = commands[i].strip() for j in range(1,len(arguments)+1): s = s.replace(arg_replacer_b+str(j),arg_separator.join(arguments[j-1:len(arguments)]).strip()) s = s.replace(arg_replacer+str(j),arguments[j-1].strip()) s += '\n' #print start_tag + command + end_tag #print s alltext = alltext.replace(start_tag + command + end_tag,s) alltext = alltext.replace(d_start_tag,d_prefix) alltext = alltext.replace(d_end_tag,d_suffix) #print alltext f = open(file2,'w') f.write(alltext) f.close() #print " WROTE FILE"' return 1
if __name__ == '__main__': if len(sys.argv) >= 3: if len(sys.argv) == 4: print "Turning " + sys.argv[1] + " into " + sys.argv[2] + " using " + sys.argv[3] + "." b = ezscr(sys.argv[1],sys.argv[2],sys.argv[3]) else: print "Turning " + sys.argv[1] + " into " + sys.argv[2] + " using " + command_list + "." b = ezscr(sys.argv[1],sys.argv[2],command_list) else: print "No files specified, using the default ones, " + input_file + ", " + output_file + ", and " + command_list + "." b = ezscr(input_file,output_file,command_list) if b == 1: print "Success!"
:gsdhsdjdsj: Last item of the command list doesn't get parsed right, so this makes it work right =[
Spoiler: test.txt
Code:
#include(pwlib\pwlib.hlsl)
[load] <font 70 Arial 12> <picture 1000 PW/evidence/badge.png> <eviid 30><evigfx 1000> <eviname Attorney's Badge> <evisdesc Type: Misc\nOne of my belongings> <evidesc My badge.><evfinish> <evadd 30>
<picture 1002 PW/evidence/aluadone.png> <eviid 31><evigfx 1002> <eviname Hand Thingy> <evisdesc Type: Evidece\nIt proves stuff.> <evidesc It has a wonderful scent coming from it.\nMmmmmm....\nOh yeah, that's good stuff.><evfinish>
<picture 1001 PW/profile/ema.png> <profid 600><profgfx 1001> <profname Ema Skye> <profsdesc Type: Misc\nSome person.> <profdesc A strange girl that follows me around.><proffinish> <profadd 600>
[main] <init> <makechar phoenix> <makechar ema> <init2> <title The Great Test> <run load> <jmp game>
[game] <txtboxon>
<courtbg attorneystand><lipson><char phoenixnormal><name phoenix> {This evidence proves your guilt!}
<scroll attoney witness emanormal> <courtbg witnessstand><char emanormal><name ema> {Why? I'm not even guilty!} <char emamad> {Are you wrongly accusing me!?} <evshow 1002 left> {Even when I'll give you free \nhand sanitizer!?} <evhide left> <evaddfancy 31>
<lipsoff><name phoenix> {No, because you are guilty!}
With the use of Python and a simpler scripting language, this makes PWLib resemble PyWright a whole lot.
In fact, if you used the actual Wrightscript from PyWright, developers could start to write code for both engines. I'm not sure if you're familiar with Wrightscript, but it's syntactically similar to the sample code you wrote. Saluk and I may even be able to help you convert your Python code to conform (I'm just not familiar enough with PWLib to do it on my own). This could be the cross-platform solution everyone is looking for.
Re: AHLSL Precompiler for PWLib 0.11 (More commands)
Users browsing this forum: No registered users and 28 guests
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum