Skip to main content

Blueprint

Magical blueprints for procedural generation of content. Based roughly on http://www.squidi.net/mapmaker/musings/m100402.php

The essential idea is that you write subclasses of blueprint.Blueprint with fields that define the general parameters of their values (e.g. an integer between 0 and 10). When you instantiate a blueprint, you get a “mastered” blueprint with well-defined values for each field. Mastered blueprints may define special “generator” instance methods that build final objects from the master.

Think of it as prototypal inheritance for Python!

An example:

import blueprint

class Item(blueprint.Blueprint):
    value = 1
    tags = 'foo bar'


class Weapon(Item):
    name = 'Some Weapon'
    tags = 'dangerous equippable'
    damage = blueprint.RandomInt(1, 5)


class Spear(Weapon):
    tags = 'primitive piercing'
    name = 'Worn Spear'
    damage = blueprint.RandomInt(10, 15)
    value = blueprint.RandomInt(4, 6)


class PointedStick(Weapon):
    tags = 'primitive piercing'
    name = 'Pointed Stick'
    damage = 6
    value = 2


class Club(Weapon):
    tags = 'primitive crushing'
    name = 'Big Club'
    damage = blueprint.RandomInt(10, 15)
    value = 2


class Actor(blueprint.Blueprint):
    tags = 'active'


class CaveMan(Actor):
    name = 'Cave Man'
    weapon = blueprint.PickOne(
        Club, Spear, PointedStick
        )

And then:

>>> actor = CaveMan()
>>> actor
<CaveMan:
    name -- 'Cave Man'
    weapon -- <PointedStick:
        damage -- 6
        name -- 'Pointed Stick'
        value -- 2
        >
    >

Tags

Blueprints automatically organize themselves using tags. A direct descendant of Blueprint has its own tag repository (blueprint.taggables.TagRepository), which all its subclasses will share. So, in the above example, you can query Weapon.tag_repo.query(with_tags=(‘piercing’)) and receive set([Spear, PointedStick]).

Blueprints are also automatically tagged by their class name (and their ancestor superclass names!), with camel-cased words separated out. So CaveMan will automatically get the tags set([‘cave’, ‘man’, ‘actor’]).

This makes the following possible:

class MammothHunter(CaveMan):
    weapon = blueprint.PickFrom(
        blueprint.WithTags('pointed weapon')
        )

TODO

  • Better documentation. :)

Metadata

Release files for python-blueprint 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-blueprint 0.1
File Size Uploaded Provenance Actions
python-blueprint-0.1.tar.gz 11.4 kB Without provenance Details for python-blueprint-0.1.tar.gz

Release files / python-blueprint-0.1.tar.gz

Download URL python-blueprint-0.1.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
31e8f42811deb6c1c4bce376f9e3d01f89200d7135ba78c018a395d77b42dc2a
BLAKE2b-256 checksum
How to use checksums
c4d7269d1b045fdebff183b664b47aa932021ab4e48cf06709df7facc82df561
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for python-blueprint 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page