Added MSG processing to process-input utility script

master
Mike Gerwitz 2011-08-24 17:44:00 -04:00
parent 99447fa6be
commit cb8f5e6c65
2 changed files with 33 additions and 3 deletions

View File

@ -28,14 +28,18 @@ process-input "foo bar" 2>/dev/null <<< "" && {
# test data # test data
scene_opendoor="opendoor" scene_opendoor="opendoor"
doorspeak="Yo. I'm a door."
testscene=" testscene="
TYPE input TYPE input
OBJECT door OBJECT door
DEFAULT MSG What about the door?
ACTION open GO $scene_opendoor ACTION open GO $scene_opendoor
ACTION invalid ACTION invalid
ACTION unknown UNKNOWNCMD foo ACTION unknown UNKNOWNCMD foo
ACTION badgo GO ACTION badgo GO
ACTION talk MSG $doorspeak
ACTION badtalk MSG
STORY STORY
This is a test scene. This is a test scene.
@ -81,3 +85,13 @@ tryinput "badgo door" 2>/dev/null && {
simplefail "GO command should require a target scene" simplefail "GO command should require a target scene"
} }
# MSG should return a message
assert-equal "$( tryinput "talk door" )" "MSG $doorspeak" || {
fail "MSG command should return a message"
}
# MSG command should require an argument
tryinput "badtalk door" 2>/dev/null && {
simplefail "MSG should require output text"
}

View File

@ -2,6 +2,11 @@
# #
# Processes input text and outputs result # Processes input text and outputs result
# #
# This script will return one of two commands with an associated argument, which
# should be interpreted as follows:
# - MSG - Output the provided message
# - GO - Go to the scene matching the provided id
#
# Copyright (C) 2011 Mike Gerwitz # Copyright (C) 2011 Mike Gerwitz
# #
# This file is part of gsgp. This program is free software: you can # This file is part of gsgp. This program is free software: you can
@ -60,18 +65,29 @@ fi
# what type of command should we execute? # what type of command should we execute?
cmd=$( cut -d' ' -f1 <<< "$action_data" ) cmd=$( cut -d' ' -f1 <<< "$action_data" )
target=$( cut -s -d' ' -f2 <<< "$action_data" ) arg=$( cut -s -d' ' -f2- <<< "$action_data" )
case "$cmd" in case "$cmd" in
GO) GO)
if [ ! "$target" ]; then if [ ! "$arg" ]; then
echo "ERROR: GO command requires target scene" >&2 echo "ERROR: GO command requires target scene" >&2
exit 4 exit 4
fi fi
# the action will be to go to the target scene # the action will be to go to the target scene
echo "GO $target" echo "GO $arg"
;; ;;
MSG)
if [ ! "$arg" ]; then
echo "ERROR: MSG requires an output string" >&2
exit 4
fi
# the MSG action will indicate that a message should be output
echo "MSG $arg"
;;
*) *)
echo "ERROR: Unknown command '$cmd' for action: $words" >&2 echo "ERROR: Unknown command '$cmd' for action: $words" >&2
exit 4 exit 4