Skip to content

Latest commit

 

History

History
138 lines (92 loc) · 2.29 KB

README.md

File metadata and controls

138 lines (92 loc) · 2.29 KB

Elma Python Library

Travis PyPI Licence

Elma Python Library is a python library for manipulating Elasto Mania files. Currently, it supports simple level, replay, LGR and state.dat manipulation and level rendering.

Documentation

Documentation is available at elma-python-library.readthedocs.org.

Installation

pip install elma

Usage

Creating a simple level

from elma import Level, Obj, Picture, Point, Polygon

level = Level()
level.name = 'My first level'
level.polygons = [
    Polygon([Point(-10, -10),
             Point(10, -10),
             Point(10, 10),
             Point(-10, 10)]),
]
level.objects = [
    Obj(Point(0, 0), Obj.START),
    Obj(Point(0, 10), Obj.FOOD, gravity=Obj.GRAVITY_UP),
    Obj(Point(0, 0), Obj.FLOWER),
]
level.pictures = [
    Picture(Point(2, 8), picture_name='flag'),
]

The above snippet defines a simple level that looks like this:

Loading a level from a file

from elma import Level

level = Level.load('mylevel.lev')

Saving a level to a file

level.save('mylevel.lev')

Merging level top10s

from elma import Level

level1 = Level.load('mylevel1.lev')
level2 = Level.load('mylevel2.lev')

if level1 == level2:
    level1.top10.merge(level2.top10)
    level1.save('mylevel.lev')

Loading a replay from a file

from elma import Replay

replay = Replay.load('myreplay.rec')

Saving a replay to a file

replay.save('myreplay.rec')

Reading a state.dat and creating stats.txt

from elma import State
state = State.load('state.dat')
print(state)  # prints the players and their total times
with open('stats.txt', 'w') as f:
    f.write(state.stats_txt())

Development setup

virtualenv venv
. venv/bin/activate
make setup

Running tests

make test

Linting

To lint the project, do:

make lint

Type checking

To run static type checking with mypy, do:

make mypy

Contributing

Pull requests welcome!