-
Notifications
You must be signed in to change notification settings - Fork 3
/
auto_object.ts
149 lines (130 loc) · 4.67 KB
/
auto_object.ts
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import fs from 'fs';
import path from 'path';
const beco = require('./beco');
const yaml = require('js-yaml');
import * as util from './app/util';
let parseArgs = require('minimist');
let argv = parseArgs(process.argv);
if (!argv.a) {
console.log("Error: Must specify a path to directory with ActorLink YAML files");
console.log(" e.g. % ts-node auto_object.ts -a ../botw/Actor")
console.log(" YAML data files are available from https://github.com/leoetlino/botw");
process.exit(1);
}
const botwData = argv.a;
const uType = new yaml.Type('!u', {
kind: 'scalar', instanceOf: String,
resolve: function(data: any) { return true; },
construct: function(data: any) { return data; },
});
let schema = yaml.DEFAULT_SCHEMA.extend([uType]);
function readYAML(filePath: string) {
let doc: any = null;
try {
doc = yaml.load(fs.readFileSync(filePath, 'utf-8'), { schema: schema });
} catch (e) {
console.log(e);
process.exit(1);
}
return doc;
}
function real_name(x: string): string {
if (x in names) {
return names[x];
}
console.log("Missing ", x);
return x;
}
// Check if the Item has Auto Placement in an Area
function isAutoItem(area: any, atype: string) {
if (atype == "Insect") {
return area.NonAutoPlacementInsect == false;
} else if (atype == "Animal") {
return area.NonAutoPlacementAnimal == false;
} else if (atype == "Bird") {
return area.NonAutoPlacementBird == false;
} else if (atype == "Material") {
return area.NonAutoPlacementMaterial == false;
} else if (atype == "Enemy") {
return area.NonAutoPlacementEnemy == false;
} else if (atype == "Fish") {
return area.NonAutoPlacementFish == false;
} else if (atype == "Safe") {
return area.NonEnemySearchPlayer == true;
}
return null;
}
// Get Item parts for an Area
function itemParts(area: any, atype: string) {
let x: number = area.Translate.X;
let z: number = area.Translate.Z;
let num = fieldArea.getCurrentAreaNum(x, z);
if (atype == "Insect") {
return ndata[num].Insect;
} else if (atype == "Animal") {
return ndata[num].Animal;
} else if (atype == "Bird") {
return ndata[num].Bird;
} else if (atype == "Enemy") {
return ndata[num].Enemy;
} else if (atype == "Fish") {
return ndata[num].Fish;
} else if (atype == "Material") {
return ndata[num].AutoPlacementMaterial;
} else if (atype == "Safe") {
return [];
}
return null;
}
// Create and write Auto Placement data for each
function getAutoPlacements(stat: any, atype: string) {
let color = "pink";
let out: any = {};
stat.NonAutoPlacement
.filter((area: any) => isAutoItem(area, atype))
.filter((area: any) => itemParts(area, atype))
.forEach((area: any, n: number) => {
let parts = itemParts(area, atype);
let x: number = area.Translate.X;
let z: number = area.Translate.Z;
let sx: number = area.Scale.X;
let sz = area.Scale.Z;
let sy = area.Scale.Y;
let angle = area.RotateY;
let shape: string = area.Shape;
let num: number = fieldArea.getCurrentAreaNum(x, z);
parts.forEach((item: any) => { item.real_name = real_name(item.name); });
let geom: any = {
shape: shape,
loc: [area.Translate.X, area.Translate.Y, area.Translate.Z],
scale: [area.Scale.X, area.Scale.Y, area.Scale.Z],
rotate: [0, angle, 0],
color: color,
field_map_area: num,
type: atype,
items: parts,
};
out[n] = geom;
});
let filename = `Auto${atype}.json`;
console.log(`Writing ${filename} ... ${Object.keys(out).length}`);
fs.writeFileSync(filename, JSON.stringify(out), 'utf8');
}
// Read in FieldMapArea, AreaData, Static.mubin, and names.json
// - stat.NonAutoPlacement contains Areas (Map/MainField/Static.mubin.yml)
// - fieldArea contains the mapping from location to fieldAreaNum (content/ecosystem/FieldMapArea.beco)
// - data contains the Item Probabilities for Spawning (Ecosystem/AreaData.yml)
const fieldArea = new beco.Beco(path.join(util.APP_ROOT, 'content', 'ecosystem', 'FieldMapArea.beco'));
let data = readYAML(path.join(botwData, '..', 'Ecosystem', 'AreaData.yml'));
let stat = readYAML(path.join(botwData, '..', 'Map', 'MainField', 'Static.mubin.yml'));
let names: any = JSON.parse(fs.readFileSync(path.join(util.APP_ROOT, 'content', 'names.json'), 'utf8'));
// These names are not in names.json
names['Animal_Insect_EP'] = 'Sunset Firefly';
names['BrokenSnowBall'] = 'Broken SnowBall';
// Create [areaNumber] = areaData
let ndata: any = {};
data.forEach((v: any) => {
ndata[v.AreaNumber] = v;
});
let items = ["Animal", "Bird", "Enemy", "Fish", "Insect", "Material", "Safe"];
items.forEach(item => getAutoPlacements(stat, item));