Namby Pamby Magicians

    convolvr-ecs
    TypeScript icon, indicating that this package has built-in type declarations

    1.5.29 • Public • Published

    ECS Language · npm version License: MIT Discord

    Entity Control Script interpreter with api for Convolvr.

    Install

    npm install --save convolvr-ecs

    Transpile into your favorite language!

    ecs -t js main.ecs > main.js
    ecs -t java main.ecs > main.java
    ecs -t c main.ecs > main.c

    Install your favorite Un-Parser:

    import { ECS } from 'convolvr-ecs';
    import { Java } from 'convolvr-ecc';
     
    const augmentedAST: ParseResult = ECS.parse("for(x, 1000) { print(x * x); }");
    const javaCode: string = ECS.transpile(augmentedAST, Java)
     

    CLI usage:

    ecs some-file.ecs
    ecs # to enter interactive mode 
    npm start -- program.ecs # to run without npm link(ing) 

    Use with an Entity-Component System:

    Component c = Component(); /* current component */
     
    c.addComponent(new Component({
     attrs: { 
          geometry: { shape: "box", size: [2,2,2]}
          material: { color: 255 }  
     } 
    })); 
     
    c.events().staticCollisions.hit(fn( hitTelemetry ){    
          c.actions().chat.send("Robot: Owch!");
          c.actions.movement.setVelocity([0, -1, 0]);
    });

    ^^^ See "WebWorker usage", below for implementation details.

    JS module usage:

    import { ECS } from 'convolvr-ecs';
     
    const vm = ECS.makeRuntimeEnvironment(), 
          env = vm.makeEnvironment();
     
    vm.parseAndEvaluate(
          "print('hello')", 
          env, 
          (errs) => console.warn(errs)
    )

    WebWorker usage:

    Send command to ECS Web Worker

    Handle response from ECS Web Worker

    Hacking the interpreter:

    git clone git@github.com:convolvr/ecs.git
    cd ecs && npm install && npm run-script build
    # npm start to start interactive mode 

    For the server-side implementation, check out https://github.com/SpaceHexagon/ecs

    TODO: finish writing this readme

    class Salad {
     Saladfn() { },
     private sauce: "ceaser",
     final lettuce: "iceberg",
     static toppings: ["bacon""chicken""parmesean"],
     describe: fn() {
      return this.sauce + "" + join(this.toppings, ",") 
     },
     toss: fn() { 
       let toppings = this.toppings;
       this.toppings = [ toppings[1], toppings[2], toppings[0] ]; 
     }
    }
    let dinner = new Salad();
     
    dinner.describe();
    dinner.toss();
    let colors = [" ", "`", ".", "'", ",", "-", "+", "/", "\""=""L""H"" ""#""@"];
    let size = terminal.getDimensions();
    for (y, size[1]) {
     let s = "-";
     let idx = 0;
     for (x, size[0]-1) {
       if ((x/2 + y/2) % 10 <5) {
        idx = (x/1+y)%4;
       }
       if ((x/2 - y/2)% 10 <5) {
        idx = 2+(x*y) % 9;
       }
       s = s + colors[idx];
      }
      print(s);
     }
    -..................................................................................................
    -.',-+/\=L.''''''''' `-+/\=L.',--------- `/\=L.',-+///////// `=L.',-+/\========= `.',-+/\=L........
    -.,+\L'-/=.,+++++++ `.'L'-/=.,+\LLLLLLL `.'-/=.,+\L'------- `.'=.,+\L'-/======= `.',+\L'-/=.,,,,,,,
    -.-\.-\.-\.-\..... `.' `\.-\.-\.-\\\\\ `.' `-\.-\.-\.----- `.' `.-\.-\.-\..... `.' `\.-\.-\.-\\\\\
    -.+L-=,\'/.+L-=== `.' `.'\'/.+L-=,\\\ `.' `.'/.+L-=,\'/// `.' `.'+L-=,\'/.+++ `.' `.'-=,\'/.+L--- `
    -./'\,=-L+./'\,= `.' `.' `L+./'\,=-L `.' `.' `./'\,=-L+. `.' `.' `'\,=-L+./' `.' `.' `,=-L+./'\, `.
    -.\-.\-.\-.\-.\-..' `.' ```-.\-.\-.\-.' `.' ```\-.\-.\-.\.' `.' ```.\-.\-.\-..' `.' ```-.\-.\-.\-.'
    -.=/-'L\+,.=/-'L\+ `.' `````.=/-'L\+,. `.' `````/-'L\+,.=/ `.' `````'L\+,.=/-' `.' `````\+,.=/-'L\
    -.L=\/+-,'.L=\/+-,'.' ```````L=\/+-,'.L.' ```````\/+-,'.L=\.' ```````+-,'.L=\/+.' ```````,'.L=\/+-,
    -................... `````````.......... `````````.......... `````````.......... `````````.........
    -.',-+/\=L.',-+/\=L.'''''''''''-+/\=L.',-----------/\=L.',-+///////////=L.',-+/\===========.',-+/\=
    -.,+\L'-/=.,+\L'-/=.,+++++++++ `L'-/=.,+\LLLLLLLLL `-/=.,+\L'--------- `=.,+\L'-/========= `,+\L'-/
    -.-\.-\.-\.-\.-\.-\.-\....... `.'\.-\.-\.-\\\\\\\ `.'-\.-\.-\.------- `.'.-\.-\.-\....... `.'\.-\.-
    -.+L-=,\'/.+L-=,\'/.+L-===== `.' `\'/.+L-=,\\\\\ `.' `/.+L-=,\'///// `.' `+L-=,\'/.+++++ `.' `-=,\'
    -./'\,=-L+./'\,=-L+./'\,=== `.' `.'L+./'\,=-LLL `.' `.'./'\,=-L+... `.' `.''\,=-L+./''' `.' `.',=-L
    -.\-.\-.\-.\-.\-.\-.\-.\-. `.' `.' `-.\-.\-.\- `.' `.' `\-.\-.\-.\ `.' `.' `.\-.\-.\-. `.' `.' `-.\
    -.=/-'L\+,.=/-'L\+,.=/-'L\+.' `.' ```.=/-'L\+,..' `.' ```/-'L\+,.=/.' `.' ```'L\+,.=/-'.' `.' ```\+
    -.L=\/+-,'.L=\/+-,'.L=\/+-,' `.' `````L=\/+-,'.L `.' `````\/+-,'.L=\ `.' `````+-,'.L=\/+ `.' `````,
    -.............................' ```````...........' ```````...........' ```````...........' ```````
    -.',-+/\=L.',-+/\=L.',-+/\=L.' `````````-+/\=L.',- `````````/\=L.',-+/ `````````=L.',-+/\= ````````
    -.,+\L'-/=.,+\L'-/=.,+\L'-/=.,+++++++++++L'-/=.,+\LLLLLLLLLLL-/=.,+\L'-----------=.,+\L'-/=========
    -.-\.-\.-\.-\.-\.-\.-\.-\.-\.-\......... `\.-\.-\.-\\\\\\\\\ `-\.-\.-\.--------- `.-\.-\.-\........
    -.+L-=,\'/.+L-=,\'/.+L-=,\'/.+L-======= `.'\'/.+L-=,\\\\\\\ `.'/.+L-=,\'/////// `.'+L-=,\'/.+++++++
    -./'\,=-L+./'\,=-L+./'\,=-L+./'\,===== `.' `L+./'\,=-LLLLL `.' `./'\,=-L+..... `.' `'\,=-L+./'''''
    -.\-.\-.\-.\-.\-.\-.\-.\-.\-.\-.\-... `.' `.'-.\-.\-.\--- `.' `.'\-.\-.\-.\\\ `.' `.'.\-.\-.\-... `
    -.=/-'L\+,.=/-'L\+,.=/-'L\+,.=/-'L\+ `.' `.' `.=/-'L\+,. `.' `.' `/-'L\+,.=/ `.' `.' `'L\+,.=/-' `.
    -.L=\/+-,'.L=\/+-,'.L=\/+-,'.L=\/+-,'.' `.' ```L=\/+-,'.L.' `.' ```\/+-,'.L=\.' `.' ```+-,'.L=\/+.'
    -..................................... `.' `````.......... `.' `````.......... `.' `````..........
    

    Fractal example: https://tinyurl.com/y228w9qm

    const colors = split('.,.,.,-,-,_,+,+,/,=,L,7,H,%,#,@', ',');
    for(x, 120) {
     string out = "";
     for(y, 200) {
            int i=0;
            float cx=-2+x/50;
            float cy=-2+y/150;
            float zx=0;
            float zy=0;
            while(i<255&&(zx*zx-zy*zy)<4){
      float xt=zx*zy;
              zx=zx*zx+zy*zy+cx;
                zy=2*xt+cy;
                i = i + 1;
            }
            out = out + colors[i%12];
     }
     print(out);
    }

    Install

    npm i convolvr-ecs

    DownloadsWeekly Downloads

    3

    Version

    1.5.29

    License

    MIT

    Unpacked Size

    434 kB

    Total Files

    206

    Last publish

    Collaborators

    • spacehexagon