/
magica_rooms.py
106 lines (88 loc) · 4.07 KB
/
magica_rooms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
import argparse
import random
import logging
from redeclipse import prefabs
# We must override this ASAP since everyone else (e.g. prefabs) also imports the TEXMAN from prefab.
# from redeclipse.textures import DefaultThemedTextureManager, PrimaryThemedTextureManager, RainbowPukeTextureManager
# prefabs.TEXMAN = RainbowPukeTextureManager()
# Back to our normally scheduled imports.
from redeclipse.cli import parse
from redeclipse.entities import Sunlight
from redeclipse.magicavoxel.writer import to_magicavoxel
from redeclipse.prefabs import STARTING_POSITION
from redeclipse.prefabs import castle, dungeon, spacestation, original # noqa
from redeclipse.upm import UnusedPositionManager
from redeclipse.vector.orientations import EAST
from redeclipse.voxel import VoxelWorld
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
def main(mpz_in, mpz_out, size=2**8, seed=42, rooms=200, debug=False, magica=None):
random.seed(seed)
mymap = parse(mpz_in.name)
v = VoxelWorld(size=size)
possible_rooms = [
# # Original
original.spawn_room,
# # Castle
# castle.castle_gate, castle.castle_gate_simple,
castle.castle_large, castle.castle_wall_corner,
castle.castle_wall_end_cliff, castle.castle_wall_entry,
castle.castle_wall_section, castle.castle_wall_section_long,
castle.castle_wall_section_long_damaged,
castle.castle_wall_section_tjoint, castle.castle_wall_tower,
castle.wooden_bridge,
# # Dungeon
# dungeon.dungeon_2x2, dungeon.dungeon_junction, dungeon.dungeon_stair2,
# dungeon.dungeon_walkway, dungeon.dungeon_walkway3,
# # Space
# spacestation.station_tube1, spacestation.station_tube3, spacestation.station_tube_jumpx,
# spacestation.station_tubeX, spacestation.station_endcap, spacestation.station_right, spacestation.station_ring,
# spacestation.station_ring_vertical, spacestation.station_sphere, spacestation.station_sphere_slice,
# spacestation.station_stair2,
]
possible_endcaps = [castle.castle_wall_end_cliff, castle.castle_wall_section_endcap]
# Initialize
upm = UnusedPositionManager(size, mirror=4)
# Insert a starting room. We move it vertically downward from center since
# we have no way to build stairs downwards yet.
# We use the spawn room as our base starting room
Room = castle.castle_small_deis
b = Room(pos=STARTING_POSITION, orientation=EAST)
[m.render(v, mymap) for m in upm.register_room(b)]
# Convert rooms to int
rooms = int(rooms)
sunlight = Sunlight(
red=128,
green=128,
blue=128,
offset=45, # top
)
mymap.ents.append(sunlight)
upm.place_rooms(v, mymap, debug, possible_rooms, rooms=rooms)
# Apply endcaps
for room in upm.endcap(debug=debug, possible_endcaps=possible_endcaps):
room.render(v, mymap)
# from redeclipse.aftereffects import box_outline
# box_outline(v, height=48)
# Emit config + textures
# mymap.skybox(MinecraftSky('/home/hxr/games/redeclipse-1.5.3/'))
if magica:
to_magicavoxel(v, magica, prefabs.TEXMAN)
if mpz_out:
prefabs.TEXMAN.emit_conf(mpz_out)
prefabs.TEXMAN.copy_data()
mymap.world = v.to_octree()
mymap.world[0].octsav = 0
mymap.write(mpz_out.name)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Add trees to map')
parser.add_argument('mpz_in', type=argparse.FileType('r'), help='Input .mpz file')
parser.add_argument('--mpz_out', type=argparse.FileType('w'), help='Output .mpz file')
parser.add_argument('--magica', type=argparse.FileType('wb'), help='Output .vox file')
parser.add_argument('--size', default=2**8, type=int, help="World size. Danger!")
parser.add_argument('--seed', default=42, type=int, help="Random seed")
parser.add_argument('--rooms', default=200, type=int, help="Number of rooms to place")
parser.add_argument('--debug', action='store_true', help="Debugging")
args = parser.parse_args()
main(**vars(args))