Ejemplo n.º 1
0
def scaled(textmap: Textmap, factor: float) -> Textmap:
    """ Scales the x and y coordinates of every thing and vertex in the textmap. """

    sectors = {Sector(
        s.heightfloor,
        s.heightceiling,
        s.texturefloor,
        s.textureceiling,
        xscalefloor=factor * s.xscalefloor,
        yscalefloor=factor * s.yscalefloor,
        xscaleceiling=factor * s.xscaleceiling,
        yscaleceiling=factor * s.yscaleceiling,
    ) for s in textmap.sectors}
    sidedefs = {Sidedef(
        sd.texturemiddle,
        factor * sd.offsetx,
        factor * sd.offsety
    ) for sd in textmap.sidedefs}
    vertices = {Vertex(factor * v.x, factor * v.y) for v in textmap.vertices}
    linedefs = textmap.linedefs
    things = [Thing(t.type, factor * t.x, factor * t.y) for t in textmap.things]

    return Textmap(
        vertices=vertices,
        linedefs=linedefs,
        sidedefs=sidedefs,
        sectors=sectors,
        things=things,
    )
Ejemplo n.º 2
0
 def textmap(self, sectors, linedefs, vertices, sidedefs):
     return Textmap(
         namespace="zdoom",
         vertices=frozenset(vertices),
         sidedefs=frozenset(sidedefs),
         linedefs=frozenset(linedefs),
         sectors=frozenset(sectors),
         things=(Thing(1, 32.0, 32.0),))
Ejemplo n.º 3
0
def sample_spanning_textmap():
    vertices = [
        Vertex(0, 0),
        Vertex(0, 128),
        Vertex(192, 128),
        Vertex(192, 0),
    ]
    return Textmap(vertices=set(vertices), )
Ejemplo n.º 4
0
 def textmap(self, vertices, sectors, sidedefs, linedefs, things) -> Textmap:
     return Textmap(
         namespace="zdoom",
         vertices=frozenset(vertices),
         sectors=frozenset(sectors),
         sidedefs=frozenset(sidedefs),
         linedefs=frozenset(linedefs),
         things=things
     )
Ejemplo n.º 5
0
    def _add_sectors(self, textmap: Textmap):
        cycle_count = len(textmap.cycles())  # TODO memoization

        sector_list = [
            Block("sector", self._s2blocklist(s)) for s in textmap.sectors
        ]
        sector_list *= cycle_count

        return sector_list
Ejemplo n.º 6
0
 def textmap(self, sectors, sidedefs, linedefs, things) -> Textmap:
     vertices = {ld.v1 for ld in linedefs}.union({ld.v2 for ld in linedefs})
     return Textmap(
         namespace="zdoom",
         vertices=vertices,
         sectors=frozenset(sectors),
         sidedefs=frozenset(sidedefs),
         linedefs=frozenset(linedefs),
         things=things
     )
Ejemplo n.º 7
0
def sample_textmap(sample_vertices, sample_sectors, sample_sidedefs,
                   sample_linedefs):
    things = (Thing(1, 32, 32), )
    return Textmap(
        vertices=set(v for row in sample_vertices for v in row),
        sectors=set(sample_sectors),
        sidedefs=set(sample_sidedefs),
        linedefs=set(sample_linedefs),
        things=things,
    )
Ejemplo n.º 8
0
def asciimap2textmap(asciimap: List[str]) -> Textmap:
    asciimap = [line.strip() for line in asciimap]
    asciimap = [line for line in asciimap if line]
    vertices = _asciimap2vertices(asciimap)
    sectors = _asciimap2sectors(asciimap)
    sidedefs = _sectors2sidedefs(sectors)
    linedefs = generate_linedefs(vertices, sidedefs)
    things = [Thing(1, 0.5 * xscale, 0.5 * yscale)]
    textmap = Textmap(
        vertices=vertices,
        sectors=sectors,
        sidedefs=sidedefs,
        linedefs=linedefs,
        things=things,
    )
    return textmap
Ejemplo n.º 9
0
    def _add_sidedefs(self, textmap: Textmap):
        vertices = {
            v: i
            for i, v in enumerate(
                sorted(textmap.vertices, key=lambda e: (e.y, e.x)))
        }

        linedefs = {(vertices[ld.v1], vertices[ld.v2], ld)
                    for ld in textmap.linedefs}

        linedefs = [
            ld for sdid, (
                v1, v2,
                ld) in enumerate(sorted(linedefs, key=lambda e: (e[0], e[1])))
        ]

        cycles = textmap.cycles()

        cycles_sides = {self._linedef_orientation(c) for c in cycles}

        sidedefs = self._to_sidedefs(cycles_sides, linedefs)

        return sidedefs + self._add_sectors(textmap)
Ejemplo n.º 10
0
#!/usr/bin/env python3

import pytest

from pyudmf.model.textmap import Textmap, Vertex, Thing
from pyudmf.ops.scaler import scaled


@pytest.mark.parametrize("textmap, expected", [
    (Textmap(), Textmap()),
    (Textmap(vertices={Vertex(10.0, 16.0)}),
     Textmap(vertices={Vertex(5.0, 8.0)})),
    (Textmap(things=[Thing(1, 20.0, 7.0)]),
     Textmap(things=[Thing(1, 10.0, 3.5)])),
])
def test_scaled(textmap, expected):
    returned = scaled(textmap, 0.5)
    assert returned == expected