Gaiman Engine
Storytelling Text Based Game Engine
Main part of Gaiman is a minimalistic language that generate Text Advanture Games.
Examples
This is basic Gaiman DLS example:
def ask_email(message)
set reply = ask message
if reply ~= /y|yes/i then
echo "OK"
else if reply ~= /n|no/i then
echo "FAIL"
else
global(message)
end
end
def global(command)
if command ~= /help/ then
echo "available commands help"
else if command ~= /ls/
echo get "/exec?command=ls"
else
echo "wrong command"
end
end
if cookie.visited then
if cookie.USER_NAME then
echo "hello $user"
else if cookie.EMAIL then
echo "Will contact with with any updates"
else
echo "Do you want me to contact you with updates?"
set confirm = ask "yes/no: "
if confirm ~= /y|yes/i then
echo "what is your name?"
set command = ask "name: "
if command then
set user = command
set cookie.user = command
set response = post "/register" { name: user, email: email }
if response then
echo "Welcome $user. You're successfully registered"
end
end
end
end
end
TODO
TODO: syntax example
echo <<GREET
____ _
/ ___| __ _(_)_ __ ___ __ _ _ __
| | _ / _` | | '_ ` _ \ / _` | '_ \
| |_| | (_| | | | | | | | (_| | | | |
\____|\__,_|_|_| |_| |_|\__,_|_| |_|
Gaiman Engine
Copyright (C) 2021 Jakub Jankiewicz <https://jcubic.pl/me>
Released under GPLv3 license
GREET
if location then
echo "Wellcome on this website"
else
echo "Wellcome to this CLI app"
end
var env = []
var items = ["bottle", "flower"]
set command = ask "? "
if command ~= /pick (.+)/ then
if $1 then
if exists $1 in items then
env.push($1)
pop items
else
echo "invalid item"
end
else
echo "What do you want topick"
end
end
var stop = false
var count = 0
while not stop do
var command = ask "? "
if command ~= /exit/
stop = true
echo "goodby"
else if command ~= /add ([0-9]+)/ then
count += parse $1
echo "corrent count $count"
else
echo "your command $command"
end
end
def once(fn)
var result = null
return lambda(...args)
if result == null then
result = fn(...args)
end
return result
end
end
def map(fn, array)
var result = []
for item in array do
result.push(fn(item))
end
return result
end
To consider
- do we need
set
maybe foo = ??
is enough - scope for variales (php with global is not good idea)
- methods
- standard library (e.g.:
push
/pop
/split
/join
) - functions should be compiled to JavaScript, use
command = ask "? "
should be compile to:
var command = await term.read('? ')
Compile:
do
var x = 10
echo x + x
end
x # throw exception x is not defined
to
{
let $_x = 10
term.echo($_x + $_x);
}
x
All names prefixed with $_
to solve conflicts
Adapter API
class Adapter {
constructor() { }
async ask(message) { }
echo(string) { }
async get(url) { }
async post(url, data) { }
start() { }
}
functon is_node() {
return typeof process !== 'undefined' &&
process.release.name === 'node';
}
var term, $_location, $_argv
if (is_node()) {
term = new NodeAdapter();
$_argv = process.argv;
} else {
term = new WebAdapter();
$_location = location;
}
term.start();
Name
Name came from Neil Gaiman,
Author of novels, comic books, graphic novels and films. Great storyteller.
Acknowledge
Logo use:
License
Released under GPLv3 license
Copyright (c) 2021 Jakub T. Jankiewicz