-
Notifications
You must be signed in to change notification settings - Fork 5
/
generateMapData.html
83 lines (76 loc) · 4.17 KB
/
generateMapData.html
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
<html>
<script src="js/rawmapdata.js"></script>
<script>
mapData = scenesRaw; //Set scenes as the top level objects
var subData = new Array({name: "rooms", data: roomsRaw}, {name: "setups", data: setupsRaw});
var actorData = new Array({name: "enemy", data: enemies, current: 0}, {name: "nature", data: nature, current: 0}, {name: "container", data: containers, current: 0});
var actorCurrent = [0,0,0];
for(h in subData) { //Loop through both rooms and setups
for(i in subData[h].data) { //Within each room/setup
var entry = subData[h].data[i];
var sceneID = JSON.parse(JSON.stringify(entry.sceneID)); //Make a copy of scene ID before we delete it from entry
delete entry.sceneID; //Clear out repeat data (stored in parent scene)
delete entry.sceneName;
if(typeof mapData[sceneID][subData[h].name] === "undefined") { //Make new object array for rooms/setups within scene if it doesn't exist
mapData[sceneID][subData[h].name] = new Array();
}
var newLength = mapData[sceneID][subData[h].name].push(entry); //Add room/setup to the scene
var addedRoom = mapData[sceneID][subData[h].name][newLength - 1];
if(h == 0) { //For rooms
for(actorType in actorData){
insertActor(addedRoom, actorType);
}
}
}
}
function insertActor(addedRoom, actorType) {
var actors = actorData[actorType].data;
var type = actorData[actorType].name;
while(actorCurrent[actorType] < actors.length && actors[actorCurrent[actorType]].scene == sceneID && actors[actorCurrent[actorType]].room == entry.id) { //Check if current actor we're on is in this scene>room
if(typeof addedRoom[type] === "undefined") { //Make new object array for actors within room if it doesn't exist
addedRoom[type] = new Array();
}
var newActor = actors[actorCurrent[actorType]];
delete newActor.scene; //Clear out repeat data (stored in parents)
delete newActor.room;
addedRoom[type].push(newActor); //Add actor to room
if(typeof addedRoom[type + "Counts"] === "undefined") { //Make new object array for actor counts within room if it doesn't exist
addedRoom[type + "Counts"] = new Array();
}
var exists = false;
if(type == "enemy" && (newActor.id == 75 || newActor.id == 76 || newActor.id == 77)) { //Convert various types of Gold Skulltula to just normal type
newActor.id = 74;
}
for(var j in addedRoom[type + "Counts"]) { //Loop through room's already counted enemies
if(addedRoom[type + "Counts"][j].id == newActor.id) { //If actor has already been added at least once
addedRoom[type + "Counts"][j].count++; //Increment count
exists = true;
break;
}
}
if(!exists) { //If actor wasn't found in the scene count list already
addedRoom[type + "Counts"].push({id: newActor.id, count: 1});
}
if(typeof mapData[sceneID][type + "Counts"] === "undefined") { //Make new object array for actor counts within scene if it doesn't exist
mapData[sceneID][type + "Counts"] = new Array();
}
exists = false;
for(var j in mapData[sceneID][type + "Counts"]) { //Loop through scene's already counted actors
if(mapData[sceneID][type + "Counts"][j].id == newActor.id) { //If actor has already been added at least once
mapData[sceneID][type + "Counts"][j].count++; //Increment count
exists = true;
break;
}
}
if(!exists) { //If actor wasn't found in the scene count list already
mapData[sceneID][type + "Counts"].push({id: newActor.id, count: 1});
}
actorCurrent[actorType]++; //Actor array is pre-ordered by scene>room>setup, so we're simply stepping through them until we get to the next scene>room
}
if(typeof addedRoom[type] !== "undefined") { //Sort actors by setup if room has them
addedRoom[type].sort(function(a,b){return a.setup - b.setup;});
}
}
document.write(JSON.stringify(mapData));
</script>
</html>