Skip to content

Commit

Permalink
set cookies & locals + boolean values
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Apr 5, 2021
1 parent c91df66 commit 8c0385d
Show file tree
Hide file tree
Showing 7 changed files with 512 additions and 254 deletions.
60 changes: 40 additions & 20 deletions README.md
Expand Up @@ -8,15 +8,31 @@

[Storytelling Text Based Game Engine](https://github.com/jcubic/gaiman)

Main part of Gaiman is a minimalistic language that generate Text Advanture Games.
Main part of Gaiman is a minimalist language that generate
[Text Adventure Games](https://en.wikipedia.org/wiki/Interactive_fiction).

## Installation

```
npm install -g gaiman
```

## Usage

```
gaiman -o directory input.gs
```

This will compile your source file and generate `dir/index.html` and `dir/index.js` files.
And you can open generated html file in browser and run the game.

## Examples

This is basic Gaiman DSL example:

```ruby
def ask_email(message)
set reply = ask message
let reply = ask message
if reply ~= /y|yes/i then
echo "OK"
else if reply ~= /n|no/i then
Expand All @@ -43,14 +59,14 @@ if cookie.visited then
echo "Will contact with with any updates"
else
echo "Do you want me to contact you with updates?"
set confirm = ask "yes/no: "
let confirm = ask "yes/no: "
if confirm ~= /y|yes/i then
echo "what is your name?"
set command = ask "name: "
let command = ask "name: "
if command then
set user = command
set cookie.user = command
set response = post "/register" { name: user, email: email }
let user = command
let cookie.user = command
let response = post "/register" { name: user, email: email }
if response then
echo "Welcome $user. You're successfully registered"
end
Expand All @@ -66,7 +82,7 @@ end
- [x] strings
- [x] regexes
- [ ] arrays
- [ ] booleans
- [x] booleans
- [ ] integers
- [ ] floats
- [x] property access
Expand All @@ -76,15 +92,19 @@ end
- [ ] dicts/structs for data
- [x] `if/else` statements
- [ ] globals
- [ ] argv (process.argv) or null
- [x] cookie
- [x] set cookie
- [ ] argv (process.argv) or null
- [ ] location or null
- [ ] loop
- [ ] access nested properties
- [ ] set location and redirect
- [ ] loops
- [ ] `for`..`in`
- [ ] `while`
- [ ] `do`..`end` blocks
- [ ] comments with `#`
- [x] comments with `#`
- [x] Functions
- [ ] Functions `return` keyword
- [x] Functions `return` keyword
- [ ] Functions return functions
- [ ] Lambda
- [ ] Implementation of `map`/`reduce`/`filter` using gaiman
Expand All @@ -97,7 +117,7 @@ end
- [x] `echo` - print message
- [x] `get` - send HTTP GET request
- [x] `post` - send HTTP POST request
- [x] `set` - save expression or command into variable
- [x] `let` - save expression or command into variable
- [ ] `exists` ... `in` - check if item is in array
- [ ] `parse` - parse string to number, boolean or regex

Expand All @@ -108,17 +128,17 @@ end
- [ ] Not operator inside if statements
- [ ] Expressions
- [x] regex match `~=`
- [ ] `$1` variables
- [x] `$1` variables
- [ ] comparators `==`/`<=`/`>=`/`<`/`>`
- [ ] parentheses for grouping
- [ ] `-=`, `+=`, `/=`, `*=` operators ????
- [ ] `-`, `+`, `/`, `*` and `%` operators
- [ ] compiler functions to JavaScript code [escodegen](https://github.com/estools/escodegen).
- [ ] Compile everything to JavaScript
- [ ] Interpreter
- [ ] Unit tests
- [ ] jQuery Terminal integration
- [ ] Async Adapters for Web and next for Terminal
- [x] compiler functions to JavaScript code [escodegen](https://github.com/estools/escodegen).
- [x] Compile everything to JavaScript
- [x] Unit tests
- [x] jQuery Terminal integration
- [x] Async Adapters for Web
- [ ] Async Adapters for Terminal
- [ ] XML like syntax for colors `<bold><red>hello</red></bold>`
- [ ] Hooks to embed JS code ???

Expand Down
5 changes: 4 additions & 1 deletion docs/index.js
Expand Up @@ -5,7 +5,9 @@ function parse_cookies(cookies) {
const result = {};
cookies.split(/\s*;\s*/).forEach(function(pair) {
pair = pair.split(/\s*=\s*/);
result[pair[0]] = pair.splice(1).join('=');
var name = decodeURIComponent(pair[0]);
var value = decodeURIComponent(pair.splice(1).join('='));
result[name] = value;
});
return result;
}
Expand Down Expand Up @@ -57,6 +59,7 @@ if (is_node()) {
if ($$__m = String($_confirm).match(/yes/i)) {
await $_ask_color();
}
term.echo(`Ok, have a nice day`);
}
term.echo(`Welcome stranger, can you tell me what is your name?`);
let $_name = await term.ask(`name? `);;
Expand Down
1 change: 1 addition & 0 deletions examples/demo.gs
Expand Up @@ -15,6 +15,7 @@ def ask_color()
if confirm ~= /yes/i then
ask_color()
end
echo "Ok, have a nice day"
end

echo "Welcome stranger, can you tell me what is your name?"
Expand Down
91 changes: 49 additions & 42 deletions examples/email.gs
@@ -1,12 +1,26 @@
def ask_email(message)
let reply = ask message
if reply ~= /y|yes/i then
echo "OK"
else if reply ~= /n|no/i then
echo "FAIL"
else
global(message)
end

def prompt_email()
echo "What is your email"
let email = ask "email? "
if email then
echo "is email $email correct?"
let confirm = ask "YES/NO? "
if confirm ~= /yes/i then
echo "ok will keep your email and contact you when time come."
end
else
echo "You need to type your email"
prompt_email()
end
end

def ask_email()
let command = ask "YES/NO? "
if command ~= /yes/i then
prompt_email()
else
echo "Ok, I understand."
end
end

def global(command)
Expand All @@ -19,42 +33,35 @@ def global(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?"
let confirm = ask "yes/no: "
if confirm ~= /y|yes/i then
echo "what is your name?"
let command = ask "name: "
if command then
let user = command
#let response = post "/register" { name: user, email: email }
if response then
echo "Welcome $user. You're successfully registered"
end
end
end
end
else
echo "Welcome stranger. What is your name? "
def ask_name()
let name = ask "name: "
if name then
cookie.USER_NAME = name
echo "Hi $name. Do you want me to concat you when time come?"
let command = ask "YES/NO? "
if command ~= /yes/i then
echo "What is your email"
let email = ask "email? "
if email then
echo "is email $email correct?"
let confirm = ask "YES/NO? "
if confirm ~= /yes/i then
echo "ok will keep your email and contact you when time come."
end
end
else
echo "You need to type something"
ask_name()
end
end

if cookie.VISITED then
if cookie.USER_NAME then
let user = cookie.USER_NAME
if cookie.EMAIL then
echo "Welcome back $user. Will contact with with any updates"
else
echo "Welcome back $user. Do you want me to contact you with updates?"
ask_email()
end
else
echo "Welcome back stranger. What is your name?"
ask_name()
ask_email()
end
else
cookie.VISITED = true
echo "Welcome stranger. What is your name? "
ask_name()
echo "Do you want me to contact you with updates?"
ask_email()
end

0 comments on commit 8c0385d

Please sign in to comment.