Here you can download everything related to the Traffic Scripting Project (TSP). This was an assignment for the programming lectures at the ETHZ. It is written in Eiffel and serves as a scripting interface for Traffic.
Download
About
* . . . . o o o o o
* _____ o
* ____==== ]OO|_n_n__][.
* [________]_|__|________)<
* oo oo 'oo OOOO-| oo\\_
* +--+--+--+--+--+--+--+--+--+--+
*
* TRAFFIC SCRIPTING PROJECT
*
* +--+--+--+--+--+--+--+--+--+--+
INDEX
°°°°°
1. Getting started
2. Available commands
3. Examples
4. Design Concept
5. Extending
6. Contact
1. Getting started
°°°°°°°°°°°°°°°°°°°
In order to compile the project you'll need to add some images to <traffic_dir>/example/image
These images are included in this package. Missing images will result in a 'Developer exception'.
Once prepared, compile and run.
The GUI will provide three consoles and the usual traffic display:
- The first console ist the scripting console. It will act like a normal texteditor. To execute the script, hit the run-button.
- The second console is grayed out. This is the outputconsole where all error- and statusmessages will be displayed
- The third is a liveconsole acting like a terminal. The following hotkeys are available:
- enter: will execute the command
- shift-enter: will paste the current command to the editconsole
- arrow_up: browse the last 20 commands backwards
- arrow_down: browse the last 20 commands forwards
- tab: autocompletion of commands
- Furthermore there is a toolbar for saving and opening traffic-script-files (.tsf). The icons are the same as in most editors.
2. Available commands
°°°°°°°°°°°°°°°°°°°°°°
- landmark [options] a_landmark
-n x-coord,y-coord Creates a new landmark at specified Coordinates
-d "some text" Sets the specified string as description
-r angle Rotates the landmark by specified angle
-s Spotlights the landmark
-u Unspotlights the landmark
-h Print helptext
- place [options] a_place
-n x-coord,y-coord Creates a new place with specified Coordinates
-p x-coord,y-coord Defines a new position for the place
-s Highlights the place
-u Unhighlights the place
-i Displays information on the place
-h Print helptext
- line [options] a_line
-n type place name Creates a new line of specified type, at place with name
-e place Extends line by another place
-p place Prepends line by another place
-w Wipes the line
-rl Removes the last element of the line
-rf Removes the first element of the line
-s Spotlights the line
-u Unspotlights the line
-c red,green,blue Sets line colour
-h Print helptext
- populate creates some trams to test the lines
- alienate [option]
-i integer <integer> aliens will invade paris
- wait real will pause execution for <real> seconds
- kill X will remove all X, where X can be one of the following:
trams/busses/passengers/buildings/all
lines
- list X lists all X, where X can be one of the following:
trams/busses/buildings/passengers/lines/places/landmarks
- focus x-coord,y-coord focuses the a specific spot on the map
- zoomin real zoom in the map by delta-real
- zoomout real zoom out the map by delta-real
- exit stops the execution of the script
special characters:
´´´´´´´´´´´´´´´´´´
- #comment regard lines starting with # as a comment
- "text with spaces" will escape spaces i.e. text inbetween quotation marks will NOT be regarded as
multiple arguments
3. Examples
°°°°°°°°°°°°
draw a new tramline in the shape of a house:
´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´
place -n 150,150 place_1
place -n 100,150 place_2
place -n 150,100 place_3
place -n 100,100 place_4
place -n 125,60 place_5
line -n tram place_1 testline
line -e place_3 testline
line -e place_4 testline
line -e place_2 testline
line -e place_3 testline
line -e place_5 testline
line -e place_4 testline
line -e place_1 testline
line -e place_2 testline
blinking lines:
´´´´´´´´´´´´´´´´
line -s "tram 1"
wait 1
line -u "tram 1"
line -s "tram 2"
wait 1
line -u "tram 2"
line -s "tram 3"
wait 1
line -u "tram 3"
line -s "tram 4"
wait 1
line -u "tram 4"
line -s "tram 5"
wait 1
line -u "tram 5"
line -s "tram 6"
wait 1
line -u "tram 6"
alien invasion:
´´´´´´´´´´´´´´´
populate
alienate -i 10
4. Design Concept
°°°°°°°°°°°°°°°°°°
The root class is APPLICATION which builds the CUSTOM_WINDOW, a derivate of the standard MAIN_WINDOW. This window contains the usual "traffic-viewport"
along with enhancements mentioned in "Getting started". After creating the window, APPLICATION initializes the PARSER.
PARSER inherits from the following classes:
- TOURISM used in previous assignments, providing some comfort-features (e.g. console, paris...)
- HELP_TEXTS contains features used to display the help text in the standard output-console
- EV_KEY_CONSTANTS baseclass containing constants used for key recognition
another important class used in PARSER is HISTORY, a custom made class implementing a FIFO list used for the command history.
On initialization of PARSER, a hashtable containing all available commands known to the parser, as well as the corresponding agent and options.
These options are stored in another hashtable for easy access.
When the parser receives a command in form of a string, it generates a list by splitting at every " -" (indicates an option)
After checking if the command is available the parser continues to check the syntax. If the input contains syntactical errors,
the appropriate message is displayed in the output-console, otherwise the corresponding agent gets called.
The heirarchy of the syntax-checker is as follows:
1. does the command (and appropriate agent) exist?
2. are there enough arguments in the specified options?
3. are the argument types valid? (e.g. -p 450,345 requires two coordinates of type integer separated by a comma)
4. does the command have a trailing argument and is it valid?
5. => call the feature
The implementation provides the feature get_option which can be used by the "command features" to check what options were supplied.
5. Extending
°°°°°°°°°°°°°
The parser-class has been writen with extensibility in mind. Anyone could add custom functions by
providing the feature and extending the command-hashtable.
the following hints should get you started:
option.put ("string integer", "o") sets an option "-o" with two arguments of type "string" and "integer"
valid argument-types are: none, string, integer, line, line_type, place, coordinates
option.put ("string", "trailing") specifies a loose argument of type "string" as in "echo foobar"
note that -h and -n are regarded as special cases not affected by trailing
table.put ([agent your_feature,option], "your_feature") introduces the function "your_feature" with the corresponding agent and the functiontable
note that this MUST be the last line of a function-definition, as it inserts the optiontable
the option -n will always disregard the trailing argument
6. Contact
°°°°°°°°°°°
If you wish to contact me, report bugs etc,
write to public(at)rakudave(dot)ch with "traffic scripting project" in the subject line
No longer supported, I don't do Eiffel anymore ^^