Code Monkey home page Code Monkey logo

jcubic / gaiman Goto Github PK

View Code? Open in Web Editor NEW
137.0 3.0 11.0 2.93 MB

Gaiman: Text based game engine and programming language

Home Page: https://gaiman.js.org

License: GNU General Public License v3.0

JavaScript 94.37% Makefile 0.22% HTML 0.25% PEG.js 5.08% CSS 0.07% GLSL 0.01%
story-driven-games storytelling story game game-development text-adventure-engine text-adventure-game text-adventure javascript javascript-library dsl programming-language text-adventure-games

gaiman's Issues

Dictionaries

Dictionaries should be created using Map or {} decided on runtime which is supported.

  • create inline
let dict_1 = {}
let dict_2 = {
  "ten" => 10,
  "twenty" => 20
}
  • Dictionary access
// access Adapter
function access(object, arg, ...rest) {
    let first;
    if (object instanceof Map) {
        first = object.get(arg);
    } else {
        first = object[arg];
    }
    return access(firt, ...rest);
}

mapping:

  • location.href.baz ==> access(location, 'href', 'baz')
  • location.replace("about:blank") => access(location, 'repalce')('about:blank').
  • settter
  • location.href = "about:blank" ==> location.href = "about:blank"
  • foo.bar.baz = 10 => set(foo, 'bar', 'baz', 10).
function set(object, ...rest) {
    let result = object;
    while (rest.length > 2) {
        const prop = rest.shift();
        if (object instanceof Map) {
            object = object.get(prop);
        } else {
            object = object[prop]
        }
    }
    const prop = rest.shift();
    const value = rest.shift();
    if (object instanceof Map) {
        object.set(prop, value);
    } else {
        object[prop] = value;
    }
}
  • Dict as dict key
let x = {
  "foo" => 10
}
let y = {
  "bar" => 20
}
let z = {}
z[x] = "hello"
z[y] = "world"
z[x] + ", " + z[y]
# hello, world
  • Add key,value for loop
for key, value in {"hello" => 10, "world" => 20} do
   echo "$key => $value"
end

Add the way to set css variables in output

Add way to customize output html with custom CSS.
Allow to add:

:root {
  --color: black;
  --background: white;
}

Consider adding tab with custom style, with default colors, that User can change. Similar to config files on Linux.

Write documentation

Add to Wiki or Readme.

  • Create Reference Manual
  • Create Tutorial or Getting Started guide

Add support for i18n

There should be easy way to translate the output game. Maybe add gettext support.

It may require adding modules.

import "i18n"
import "gettext"

and use:

echo _("Welcome to Gaiman game")

Add game playthrough gif to readme

Create an interesting example that will showcase the library.

It should:

  • Be relatively short.
  • Has some logic, maybe mini-game.
  • Have Glow style.
  • Have colors.
  • Have Typing animation.

Execute function from bracket prop property access

Add syntax:

let list = {
   hello => lambda()
     echo "HELLO FROM LAMBDA"
   end
}
list["hello"]()

This is important if "hello" is variable:

let cmd = ask "? "
if type list[cmd] == "function" then
   list[cmd]()
end

parse command

Parse string from ask into array of arguments. Possible parse and parse*.

Here docs as part of expression

There should be a way to call:

let factorial = eval(<<<CODE
(function(n) {
   return Array.from({length: n}, (_, i) => i + 1).reduce((a,b) => a * b, 1);
})
CODE)

this works:

let code = <<<CODE
(function(n) {
   return Array.from({length: n}, (_, i) => i + 1).reduce((a,b) => a * b, 1);
})
CODE

let factorial = eval(code)

while loop

let x = 10
while x > 0 do
  echo "NUM: $x"
  x = x - 1
end

Add break and continue statements

let x = 0
while true do
  x = x + 1
  if x > 10 then
    break
  end
  echo x
end

for i in [1, 2, 3, 4, 5, 6, 7] do
   if i % 2 == 0 then
      continue
   end
   echo x
end

Implement tail recursion with trampoline

function calls should return Thunk that should be resolved with the trampoline so you will be able to create real infinite loops. This is important for cases like inn demo:

def ask_color()
    echo "Pick color?"
    let color = ask "color? "
    if color ~= /red/i then
      echo "I like red, it remiding me of sun at sunset"
    else if color ~= /blue/i then
      echo "I like blue, it remind me of sky"
    else if color ~= /black/i then
      echo "I like black it remind me of the darkest night"
    else
      echo "sorry I only know red, blue and black colors"
    end
    echo "Do you want to check another color?"
    let confirm = ask "yes/no? "
    if confirm ~= /yes/i then
      ask_color() # here recursive call should be returned in a thunk
    else
      echo "Ok, have a nice day"
    end
end

Add Python range function

There will be no standard for C loop. So to interate over numbers there is need to have range function from Python.

Promisify Array::reduce

After updating Array::map and Array::filter there is need to make reduce work with async functions.

For loops

Add support for:

for item in iterator do
   echo* item
end

Add rerun button to playground

I would be easier to refresh the iframe and rerun the terminal. Right now you need to update something in the code (e.g. add and remove space).

Add way for runtime type checking

You should be able to check if something is

  • object
  • array
  • string
  • number
  • null
  • boolean
  • undefined

Best if it's command type that return type but it's not typeof that is not infinitive.

Use jQuery for Ajax

jQuery detect mime type of the response and return XML root element, Object or string. THe function do the right thing. It will simplify things, if get and post just return Object if the response is JSON.

Support Themes for browser

The js code can add terminal to #term and there can be different themes that user can pick.
Vintage, Forest, Dracula, etc.
There also should be a way to pick window version. There can be modules that will be combined into one CSS and HTML.

Add automation to the game

There should be a way to run exec and play the game without interaction.
Either as animation or as unit tests.

  • Add way to write unit tests for game, test input and output
  • Add way to animate the game as a demo to show how to play

Add splat operator

Splat should be compiled to rest operator

def sum(*args)
   let result = 0
   for i in args
       result += i
   end
   return result
end

Using current syntax. It should be able to use array.map in the future.

Commands as part of expression

This doesn't work:

echo "<white>" + (ask "? ") + "</white>"

it should parse command inside parentheses as part of expression.

The same

echo* (get "https://jcubic.pl/file.txt"), 100

This may be the same kind of expression

Add support for audio

Allow playing sound and music.

  • Came up with syntax.
  • Support for looping (music)
  • Allow to run in background and async

You can't use keyword as part of the name

Doesn't work:

input "hello"

part of "in" keyword

def define()
end

define part of def keyword

Whole keyword check need to be refactored. Probably using assertion to test if the final name is a keyword.

Add get* and post*

Those will be special case of get and post that will get output as text even if the response is JSON or XML.

Prevent infinite loops in playground

There should be some kind of guard jus for playground, that will stop long running loops.

Just made mistake and wrote:

let x = 10
while x > 0 do
  echo "NUM: $x"
  x = x + 1 # there should be minus here
end

and it frozen the browser.

Create UMD file

Create dist directory with a file that can be used in the browser (for the playground).

Chaining methods

[1, 0, 2, 3, 0, 4].map(square).filter(identity)

arr.map(square).filter(identity)

Create a blog

  • Create Jekyll Eleventy blog
  • Write Quick Intro to the language and its history
  • Use storytelling for first blog entry

Add support for tab completion

Add a way to set completion. Came up with a nice API.

Maybe:

completion ["foo", "bar", "baz"]

let commands = ["foo", "bar", "baz"]

completion lambda(string)
   return commands
end

Use ES Modules and Compile output code into ES5

The output HTML should use ES Modules with code as-is and files compiled to ES5 for old browsers.

The goal is to make the game work in IE11. Not many people use it, but some other browsers may not support all the features, like old smartphones. There will be not that much work to support IE11, since jQuery Terminal works in IE11.

  • Compile output JS to ES5 with Babel
  • Use <script type="module" in html

Create interactive playground

It would be nice to have a code editor on one side and a game on the other.

  • Editor
  • Service worker
  • Favicon
  • A way to see generated JS code
  • reset button
  • ZIP download
  • Error messages

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.