Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gaiman

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gaiman

![Gaiman Text based advanture games engine](assets/banner.svg)

  • 0.1.0-alpha
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Gaiman Engine

Gaiman Text based advanture games 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

  • Parser
    • variables
      • strings
      • regexes
      • arrays
      • booleans
      • integers
      • floats
    • property access
      • nested property access
    • Here docs - for figlet ASCII art
    • array indexing
    • dicts/structs for data
    • if/else statements
    • globals
      • argv (process.argv) or null
      • location or null
    • loop
      • for..in
      • while
    • do..end blocks
    • comments with #
    • Functions
      • Functions return keyword
      • Functions return functions
      • Lambda
      • Implementation of map/reduce/filter using gaiman
      • standard library
        • Array methods join/push/pop (maybe allow all JS methods)
        • String methods split/replace
        • ord/chr
    • Commands (restricted names)
      • ask - set prompt

      • echo - print message

      • get - send HTTP GET request

      • post - send HTTP POST request

      • set - save expression or command into variable

      • exists ... in - check if item is in array

      • parse - parse string to number, boolean or regex

      • split - to create array with string or regex separator

      • join - return string from array

      • push - item into array

      • pop - remote item from

    • Not operator inside if statements
    • Expressions
      • regex match ~=
      • $1 variables
      • comparators ==/<=/>=/</>
      • parentheses for grouping
      • -=, +=, /=, *= operators ????
      • -, +, /, * and % operators
  • compiler functions to JavaScript code escodegen.
  • Compile everything to JavaScript
  • Interpreter
  • Unit tests
  • jQuery Terminal integration
  • Async Adapters for Web and next for Terminal
  • XML like syntax for colors <bold><red>hello</red></bold>
  • Hooks to embed JS code ???

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

FAQs

Package last updated on 24 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc