Coder Social home page Coder Social logo

pywm's Introduction

pywannamaker

A python package for parsing and serializing I Wanna Maker maps from and back to their XML format.

Usage

Importing the pywannamaker module imports all required submodules.

Opening maps

Several functions load and parse a map.

  • parseFile does so from a file object or file path.
  • parseLocal opens a map with the provided name in the actual game maps folder (specified in config.py).
  • parseString opens a map from the provided string.

Worth noting is that each of these functions can correctly open any non-param element, meaning you can e.g. store individual objects in files.

Saving

  • Map.serialize returns the map string.
  • Map.save saves the map to the provided file path.
  • Map.saveLocal saves the name in the game maps folder with the provided name

Object structure

  • Map
    • properties: Properties
    • objects: [Object]
  • Properties
    • name: str
    • version: str
    • tileset: str
    • tileset2: str
    • bg: str
    • spikes: str
    • spikes2: str
    • width: str
    • height: str
    • colors: str
    • scroll_mode: str
    • music: str
  • Object
    • type: int
    • x: int
    • y: int
    • sprite_angle: int
    • name: str - empty string if unnamed
    • params: dict[str, str]
    • events: [Event]
    • children: [Object]
    • linked: [Object]
  • Event
    • event_index: int
    • params: dict[str, str]
    • events: [Event]

Examples

import pywannamaker as pywm
m = pywm.Map()
m.saveLocal('empty.map')

Creates a new map and saves it.

import pywannamaker as pywm
m = pywm.parseLocal('input.map')
for o in m.objects:
    o.x = float(m.properties.width) - o.x

Mirrors a level horizontally

from pywannamaker import Object, Event, ObjectType, EventType, ActionType
cannon = Object(ObjectType.CANNON, 400, 304)
onmetronome = Event(EventType.ONMETRONOMETICK)
onmetronome.params['frames'] = 25
onmetronome.events.append(Event(ActionType.FIRECANNON))
cannon.events.append(onmetronome)

Creates a new cannon object, and gives it an On metronome -> Fire event.

import pywannamaker as pywm
m = pywm.parseLocal('input.map')
target = None
for o in m.objects:
    if o.name == 'target':
        target = o
        break

Find an object in a map according to its name. Note this does not check any child objects. e.g. objects inside cannons

pywm's People

Contributors

iwverve avatar

Watchers

 avatar

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.