forked from Fast-64/fast64
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathrooms.py
More file actions
113 lines (90 loc) · 3.82 KB
/
Copy pathrooms.py
File metadata and controls
113 lines (90 loc) · 3.82 KB
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
107
108
109
110
111
112
113
from dataclasses import dataclass
from mathutils import Matrix
from bpy.types import Object
from ....utility import PluginError, CData, indent, writeXMLData
from ...oot_utility import getObjectList
from ...oot_model_classes import OOTModel
from ..room import Room
@dataclass
class RoomEntries:
name: str
entries: list[Room]
@staticmethod
def new(name: str, sceneName: str, model: OOTModel, sceneObj: Object, transform: Matrix, saveTexturesAsPNG: bool):
"""Returns the room list from empty objects with the type 'Room'"""
roomDict: dict[int, Room] = {}
roomObjs = getObjectList(sceneObj.children_recursive, "EMPTY", "Room")
if len(roomObjs) == 0:
raise PluginError("ERROR: The scene has no child empties with the 'Room' empty type.")
for roomObj in roomObjs:
roomHeader = roomObj.ootRoomHeader
roomIndex = roomHeader.roomIndex
if roomIndex in roomDict:
raise PluginError(f"ERROR: Room index {roomIndex} used more than once!")
roomName = f"{sceneName}_room_{roomIndex}"
roomDict[roomIndex] = Room.new(
roomName,
transform,
sceneObj,
roomObj,
roomHeader.roomShape,
model.addSubModel(
OOTModel(
f"{roomName}_dl",
model.DLFormat,
None,
)
),
roomIndex,
sceneName,
saveTexturesAsPNG,
)
for i in range(min(roomDict.keys()), len(roomDict)):
if i not in roomDict:
raise PluginError(f"Room indices are not consecutive. Missing room index: {i}")
return RoomEntries(name, [roomDict[i] for i in range(min(roomDict.keys()), len(roomDict))])
def getCmd(self):
"""Returns the room list scene command"""
return indent + f"SCENE_CMD_ROOM_LIST({len(self.entries)}, {self.name}),\n"
def getC(self, useDummyRoomList: bool):
"""Returns the ``CData`` containing the room list array"""
roomList = CData()
listName = f"RomFile {self.name}[]"
# generating segment rom names for every room
segNames = []
for i in range(len(self.entries)):
roomName = self.entries[i].name
segNames.append((f"_{roomName}SegmentRomStart", f"_{roomName}SegmentRomEnd"))
# .h
roomList.header += f"extern {listName};\n"
if not useDummyRoomList:
# Write externs for rom segments
roomList.header += "".join(
f"extern u8 {startName}[];\n" + f"extern u8 {stopName}[];\n" for startName, stopName in segNames
)
# .c
roomList.source = listName + " = {\n"
if useDummyRoomList:
roomList.source = (
"// Dummy room list\n" + roomList.source + ((indent + "{ NULL, NULL },\n") * len(self.entries))
)
else:
roomList.source += (
" },\n".join(
indent + "{ " + f"(uintptr_t){startName}, (uintptr_t){stopName}" for startName, stopName in segNames
)
+ " },\n"
)
roomList.source += "};\n\n"
return roomList
def getXML(self, useDummyRoomList: bool, dirPath):
"""Returns the XML ``str`` containing the room list data"""
data = "<RoomList>\n"
for entry in self.entries:
filePath = os.join(dirPath, entry.name)
## TODO: figure out VromStart/VromEnd
entryPathData = indent * 1 + f"<RoomEntry Path='{filePath}' VromStart='0' VromEnd='0'/>\n"
data += entryPathData
#writeXMLData()
data += "</RoomList>\n"
return data