-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddItemsToMapSave.js
152 lines (139 loc) · 4.23 KB
/
AddItemsToMapSave.js
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
150
151
152
const fs = require("fs");
const path = require("path");
const uuidv4 = require("uuid").v4;
const items = {
sandbags: {
origin: 2,
name: "Objects/Sandbags/Sandbags_Wall_Straight",
transform: {
left: {
x: 1,
y: 0,
z: 0,
},
up: {
x: 0,
y: 1,
z: 0,
},
forward: {
x: 0,
y: 0,
z: 1,
},
trans: {
x: 14.253,
y: -5000,
z: -31.83,
},
},
guid: "82C92C4A-348D-858A-C9C7-D262F31D4D33",
blueprintCtrRef: {
partitionGuid: "41864ADA-4E14-11E0-910C-967BA89DB923",
typeName: "ObjectBlueprint",
instanceGuid: "C68519A0-10A8-2B56-42B6-B69F75306F44",
name: "Objects/Sandbags/Sandbags_Wall_Straight",
},
},
razorwire: {
guid: "EC3E4D59-2583-491B-9B28-CEDEFFA922EA",
transform: {
left: {
x: 1,
y: 0,
z: 0,
},
up: {
x: 0,
y: 0,
z: -1,
},
forward: {
x: 0,
y: 1,
z: 0,
},
trans: {
x: 100.604,
y: -6000,
z: -91.209,
},
},
origin: 2,
name: "Props/StreetProps/RazorWire_01/RazorWire_01",
blueprintCtrRef: {
typeName: "ObjectBlueprint",
instanceGuid: "90F7C75D-FC31-11DD-9978-FE37F49D451C",
partitionGuid: "90F7C75C-FC31-11DD-9978-FE37F49D451C",
name: "Props/StreetProps/RazorWire_01/RazorWire_01",
},
},
};
(() => {
const args = process.argv.slice(2);
console.log(args);
const itemObjectToAdd = items[args[0]];
const itemCount = items[args[1]] || 200;
if (itemCount <= 0) {
console.error("Please enter itemCount greater than 0");
return;
}
if (itemObjectToAdd === undefined) {
console.error("That item is not supported");
return;
}
var dir = path.resolve(__dirname, args[0]);
if (!fs.existsSync(dir)) {
console.log(dir);
fs.mkdirSync(dir);
fs.mkdirSync(path.resolve(dir, "before"));
fs.mkdirSync(path.resolve(dir, "after"));
console.log("Making Directories");
return;
}
try {
const sourcePathName = path.resolve(dir, "before");
const outputPathName = path.resolve(dir, "after");
const mapSaveNames = fs.readdirSync(sourcePathName);
mapSaveNames.forEach((fileName) => {
const info = JSON.parse(
fs.readFileSync(path.join(sourcePathName, fileName))
);
if (info.data[0] === undefined) {
console.log(`${fileName} has no objects.`);
return;
}
const guids = {};
const newItemsArray = [];
let existingObjectsCount = 0;
for (let i = 0; i < info.data.length; i++) {
const item = info.data[i];
guids[item.guid] = true;
if (item.name === itemObjectToAdd.name) {
existingObjectsCount++;
}
}
if (existingObjectsCount >= itemCount) {
console.log(
`${fileName} already has ${itemCount} of ${itemObjectToAdd.name}`
);
return;
}
for (let i = 0; i < itemCount; i++) {
let newObjectGuid = uuidv4().toUpperCase();
while (guids[newObjectGuid] !== undefined) {
newObjectGuid = uuidv4().toUpperCase();
}
guids[newObjectGuid] = true;
newItemsArray.push({ ...itemObjectToAdd, guid: newObjectGuid });
}
info.data.push(...newItemsArray);
fs.writeFileSync(
path.join(outputPathName, fileName),
JSON.stringify(info, null, "\t")
);
});
} catch (e) {
console.log(e);
}
})();