Skip to content
/ bzw Public

Wrapper for BZW object creation and file population

Notifications You must be signed in to change notification settings

tainn/bzw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 

Repository files navigation

bzw

A package that allows for simple BZW object creation and file population.

It features no hard restrictions, meaning that any object can be created with any attribute, even if the object itself does not exist. As such this package is merely an extension to creating maps by hand, making it more compact, better organized, and allowing the inclusion of logic while building BZW objects.

Install

Fetch the latest version of the package:

python3 -m pip install git+https://github.com/tainn/bzw.git@0.3.2

Quick reference

A hands-on reference of available methods and their usability:

from bzw import Bzw

# instantiate
world = Bzw("my-map")

# create objects
world.create(
    "meshbox",
    position=(0, 0, 20),
    rotation=45,
    size=(10, 10, 10),
    color=(0.2, 0.2, 0.2, 0.9),
)

# define groups
world.define("tower")
world.create(...)
world.define(end=True)

# include files
world.include("/path/to/file.bzw")

# add comments
world.comment("This is a comment")

# indent with spaces
world.indent(2)

# add empty lines
world.emptyline(2)

# dump to file
world.dump()

# output to stdout
world.output()

Dump and output

Since v3.0, only the lazy IO approach is supported, in order to ensure a complete end state in case of runtime errors.

This means that the final call of the dump method is required to write the in-memory string content to the end file. The output method can also be called to print the creation to stdout instead of writing it to a file.

from bzw import Bzw

world = Bzw("my-map")

...

world.output()
world.dump()

Reserved keywords

When creating objects whose fields are named the same as Python's reserved keywords, we can add a trailing underscore to the passed kwarg, which is then appropriately parsed during runtime.

In the example below, the from_ kwarg is transformed into the from field, omitting the underscore. Note that all leading and trailing underscores will be ignored in a similar fashion.

world.create(
    "link",
    from_="east:f",
    to="west:b",
)

Logic

By utilizing some form of logic, one line doesn't have to equal just one object creation. The following example creates nine different objects under some key:

for i in range(-4, 5):
    world.create(
        "meshbox",
        position=(i * 40, i * 40, 0),
        rotation=i * 10,
        size=(10, 10, 10 * abs(i) + 10),
    )

About

Wrapper for BZW object creation and file population

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages