Board index » Present Evidence » Games

Page 1 of 1[ 3 posts ]
 


AHLSL Precompiler for PWLib 0.11 (More commands)Topic%20Title
User avatar

Gender: None specified

Rank: Medium-in-training

Joined: Sun Jun 24, 2007 6:19 pm

Posts: 449

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!}

<lipsoff><name phoenix>
{Yes you aaaaare!!}

Into proper AHLSL code like this:
Code:
[game]
runscript("pw_showmessagebox");


runscript("pw_usepwbgdefensestand");
runscript("setlipsynctochar");
runscript("pw_enablephoenixnormal");
runscript("pw_setnameboxtophoenix");

message("This evidence proves your guilt!");

runscript("pw_usepwbgwitnessstand");
runscript("pw_enableemanormal");
runscript("pw_setnameboxtoema");

message("Why? I'm not even guilty!");

runscript("setlipsynctonoone");
runscript("pw_setnameboxtophoenix");

message("Yes you aaaaare!!");

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.
Spoiler: readme.txt
Code:
                    ++++++++++++++++++++++++++++++++++
                    +++++ AHLSL PRECOMPILER 0.1 ++++++
                    ++++++++++++++++++++++++++++++++++
                       
    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:
   
        python nezscr.py [input_file] [output_file] [command_list]

        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.
   
      =-=- BAD =-=-
       COMMAND FILE:                   SOURCE FILE:             
        :evdescrip:                     <evdescrip Everyone loves cheese.> 
        setvar([description],"%1");
       
       RESULT:
        setvar([description],"Everyone");
       
      =-=- GOOD =-=-
       COMMAND FILE:                   SOURCE FILE:             
        :evdescrip:                     <evdescrip Everyone loves cheese.> 
        setvar([description],"%%1");
       
       RESULT:
        setvar([description],"Everyone loves cheese.");
       
    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!"

Spoiler: commands.txt
Code:
:init:
runscript("pw_initpwlib");
runscript("pw_initpwbgs");

:init2:
runscript("pw_showadvarrowmenu");
runscript("showpwchar");

:run:
runscript("%1");

:jmp:
jumptoscript("%1");

:setvar:
setvar([%1],%2);

:font:
loadfont(%1,%2,%3);

:picture:
loadtexture(%1,"%2");

:makechar:
runscript("pw_create%1");

:eviid:
setvar([evidencenumber],%1);

:eviname:
setvar([evidencename],"%%1");

:evigfxcheck:
setvar([evidencestex],%1);
runscript("setevidencepagesimple");

:evigfx:
setvar([evidencegfs],%1);
setvar([evidencegfl],%1);

:evidesc:
setvar([evidenceldesc],"%%1");

:evisdesc:
setvar([evidencesdesc],"%%1");

:evfinish:
runscript("createevidence");

:evadd:
setvar([evidencenumber],%1);
runscript("addevidence");

:evaddfancy:
setvar([evidencenumber],%1);
runscript("addevidence");
setvar([pw_headeviaddmsg],"");
setvar([pw_taileviaddmsg]," was added\nto the Court Record.");
runscript("pw_startevidenceadd");

:evtake:
setvar([evidencenumber],%1);
runscript("takeevidence");

:profid:
setvar([profilenumber],%1);

:profname:
setvar([profilename],"%%1");

:profgfx:
setvar([profilegfs],%1);
setvar([profilegfl],%1);

:profdesc:
setvar([profileldesc],"%%1");

:profsdesc:
setvar([profilesdesc],"%%1");

:proffinish:
runscript("createprofile");

:profadd:
setvar([profilenumber],%1);
runscript("addprofile");

:proftake:
setvar([profilenumber],%1);
runscript("takeprofile");

:present:
definevar([signal],"int");
runscript("pw_setnameboxtonoone");
messageauto("%%4");
runscript("pw_forcepresent");
waitsignal("advance",[signal]);
if(<compare([currentitemcode],"equal",%1)>,<jumptoscript("%2")>,<jumptoscript("%3")>);

:evshow:
setvar([pw_evidtoshowinbox],%1);
runscript("pw_showflyingevidbox%2");

:evhide:
runscript("pw_hideflyingevidbox%1");

:bg:
runscript("pw_usepwbg%1");

:courtbg:
runscript("pw_show%1");

:scroll:
setvar([sld_targetcharanim],"pw_enable%3");
runscript("pw_slide%1to%2");

:char:
runscript("pw_enable%1");

:name:
runscript("pw_setnameboxto%1");

:lipson:
runscript("setlipsynctochar");

:lipsoff:
runscript("setlipsynctonoone");

:txtboxon:
runscript("pw_showmessagebox");

:txtboxoff:
runscript("pw_hidemessagebox");

:title:
changetitle("%%1");

: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!}

<lipson><name ema>
{Then prove it!}
<scroll witness attorney phoenixnormal>
<jmp present>

[present]
<courtbg attorneystand><lipson><char phoenixnormal><name phoenix>
{Alright then!}
<present 30 right wrong (Present the badge!)>

[wrong]
<courtbg witnessstand><char emamad><name ema>
{You IDIOT! Start over!}
<jmp present>

[right]
{Take THAT!}
<jmp present>


Last edited by BigFish on Wed Aug 11, 2010 7:05 pm, edited 1 time in total.
Re: AHLSL Precompiler for PWLib 0.1Topic%20Title

Gender: None specified

Rank: Desk Jockey

Joined: Sun Jul 11, 2010 1:03 am

Posts: 83

Very cool.

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)Topic%20Title
User avatar

Gender: None specified

Rank: Medium-in-training

Joined: Sun Jun 24, 2007 6:19 pm

Posts: 449

Let's just say that's a lot harder than it sounds. :sadshoe:

I'd at least want to wrap up all of PWLib before I tackle that nightmare.
Page 1 of 1 [ 3 posts ] 
 
Display posts from previous:  Sort by  

 Board index » Present Evidence » Games

Who is online
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
Jump to:  
News News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list
Powered by phpBB

phpBB SEO