Elma NPM package

Advertise your levels, contests, sites etc.

Moderator: Moporators

Post Reply
User avatar
skint0r
39mins club
Posts: 768
Joined: 16 Jun 2002, 07:36
Location: Oslo, Norway

Elma NPM package

Post by skint0r »

Somewhat usable version of this is finally ready, source code here: https://github.com/elmadev/node-elma
NPM page: https://www.npmjs.com/package/node-elma (some retard using elma name for absolutely nothing, thx...)

It is pretty bad code all over and it's the first time trying to make promise-based functions and shit. Feel free to make changes if you think something sucks.

What?
If you dunno what it is based on name you probably do not care about this at all or will have any use for it, but it's a package for npm meant to be used with Node.js to read and write Elma files, both levels and replays.
Why?
Mostly for fun, but I think it's nice to have libraries to deal with Elma files for as many languages as possible and to have something everyone can use and contribute to instead of making million own shits. Also made with the intention of possibly being used with the new EOL site in the works, since it will be backed by Node.js.
How?
It is mostly pretty simple and intuitive I hope, and you can inspect the objects at any point to figure out what it contains anyway. There are some very simplified documentation in the links above too. But simple example could be like:

Code: Select all

const elma = require('node-elma')

elma.Level.load('c:/idiotelmadir/lev/ret00044.lev').then(level => {
  // do things with 'level' here
}).catch(error => console.log(error))
The resulting object from that particular level would be something like:

Code: Select all

{
  "version": "Elma",
  "link": 3072917268,
  "integrity": [
    -170445.64686103535,
    185596.64686103535,
    184364.64686103535,
    186930.64686103535
  ],
  "lgr": "DEFAULT",
  "name": "Unnamed",
  "ground": "ground",
  "sky": "sky",
  "polygons": [
    {
      "grass": false,
      "vertices": [
        {
          "x": -24,
          "y": -8
        },
        {
          "x": 20.390839694656492,
          "y": -8.562595419847328
        },
        {
          "x": 19.94198473282443,
          "y": 7.564122137404581
        },
        {
          "x": -15.48549618320611,
          "y": 7.33969465648855
        },
        {
          "x": -16.703816793893132,
          "y": 8.269465648854961
        },
        {
          "x": -20.26259541984733,
          "y": 7.5
        },
        {
          "x": -22.795419847328247,
          "y": 5.287786259541985
        },
        {
          "x": -24,
          "y": 2
        }
      ]
    }
  ],
  "objects": [
    {
      "x": 18.851908396946563,
      "y": 6.98702290076336,
      "type": "exit"
    },
    {
      "x": -23.56488549618321,
      "y": 1.7610687022900748,
      "type": "start"
    }
  ],
  "pictures": [],
  "top10": {
    "single": [
      {
        "time": 871,
        "name1": "skint0r",
        "name2": "idiot"
      }
    ],
    "multi": []
  }
}
Then there's some utility functions like formatting that time from top10 list (which are not actually in milliseconds or hundredths but actually a stupid string representation as a number, gg balazs..):

Code: Select all

elma.util.formatTime(level.top10.single[0].time)
would then print: 00:08,71

Dunno what else explain since pretty obvious most things hopefully if you use brain little, but feel free to ask if unsure either here or irc or discord or wherever.
Prestigious member of 14.6x Tutor14 club
sunl
Kuski
Posts: 346
Joined: 27 Jul 2013, 16:23

Re: Elma NPM package

Post by sunl »

Please add to http://wiki.elmaonline.net/Technical so that we can keep everything accessible and findable :) Can link mopo topic if want.
Post Reply