-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
161 lines (132 loc) · 4.49 KB
/
index.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
153
154
155
156
157
158
159
160
161
const dotenv = require("dotenv").config();
const fs = require("fs");
function getFiles(dir, files_) {
files_ = files_ || [];
var files = fs.readdirSync(dir);
for (var i in files) {
var name = dir + "\\" + files[i];
if (fs.statSync(name).isDirectory()) {
getFiles(name, files_);
} else {
files_.push(name);
}
}
return files_;
}
function addQuestCurio(path, curioList) {
var { goals } = require(path);
for (const quest of goals) {
if (quest.type != "gather" && quest.type != "activate") continue;
var curioName = `${quest.data.curio_name}_quest_${quest.type}`;
if (quest.id.startsWith("inventory_activate_")) curioName += "_with";
var usableItem =
quest.starting_items && quest.starting_items[0]
? quest.starting_items[0]
: {};
curioList[curioName] = {
interactions: usableItem,
};
}
return curioList;
}
function addLibraryCurio(path, curioList) {
const inputFile = fs.readFileSync(path, "UTF8").toString();
const fileLines = inputFile.split("\n");
var curioHeaderLine = 0;
var lastCurioId = "";
for (let i = 0; i < fileLines.length; i++) {
// Single csv line
const values = fileLines[i].split(",");
if (values.length < 16) continue;
// i == header line of new curio
if (values[2].length && values[2] == "ID STRING") {
curioHeaderLine = i;
}
// values[2] - curio id
if (i == curioHeaderLine + 1 && values[2].length) {
lastCurioId = values[2];
curioList[lastCurioId] = {
interactions: {},
};
}
// possible item interactions with the curio
// values[4] - usable item id
// values[16] - id of outcome image for the tracker
if (i >= curioHeaderLine + 11 && values[4].length && values[16].length) {
const item_values = values[4].split("#");
const item_id = item_values[0] || item_values[1] || "";
// adding unknown items to usableItems list
if (!usableItems[item_id]) {
usableItems[item_id] = item_values[1] || "supply";
console.log(
`New usable detected: { ${item_id}: "${usableItems[item_id]}" }`
);
}
const item_type = item_values[1] || usableItems[item_id];
curioList[lastCurioId].interactions[item_id] = {
item_type: item_type,
curio_tracker_id: values[16],
};
}
}
return curioList;
}
function getCurioList(ddPath) {
// array of paths to all files in Darkest Dungeon folder
const paths = getFiles(ddPath);
var curioList = {};
for (const path of paths) {
if (path.endsWith("quest.types.json")) {
console.log(`Input: ${path}`);
addQuestCurio(path, curioList);
continue;
}
if (path.endsWith("curio_type_library.csv")) {
console.log(`Input: ${path}`);
addLibraryCurio(path, curioList);
continue;
}
}
return curioList;
}
// all vanilla quest curios with their respective quest items
// quest curio are either activated without any item or with a specific quest item
// items of quest_item type don't have quest tracker icon, so they aren't added to usable items list
// quest curios don't have to appear in curio libraries, but if they do, everything will still work fine
function getCurioTracker(curioList) {
var curio_tracker = {
// __revision_dont_touch: 1683488768,
base_root: { version: 1, tracked_results: {} },
};
var num = 0;
for (const curio in curioList)
for (const usable in usableItems) {
const type_hash = curioList[curio].item_type || usableItems[usable];
const tracker_id =
(curioList[curio].interactions[usable] &&
curioList[curio].interactions[usable].curio_tracker_id) ||
"no_effect";
curio_tracker.base_root.tracked_results[num++] = {
prop_name_id: `###${curio}`,
item_type_hash: `###${type_hash}`,
item_id_hash: type_hash == usable ? "" : `###${usable}`, // empty id for items with special type
curio_tracker_id: tracker_id,
};
}
return curio_tracker;
}
// all vanilla items that can be used on curios from the inventory
// id: type
const usableItems = require("./data/usable_items.json");
// list of all curios and their interactable items if there are any
const curioList = getCurioList(process.env.DDPATH);
const curioTracker = getCurioTracker(curioList);
const curioTrackerName = "curio_tracker.json";
fs.writeFile(
`bin\\${curioTrackerName}`,
JSON.stringify(curioTracker, null, 2),
(err) => {
if (err) throw err;
console.log(`Output: \\bin\\${curioTrackerName}`);
}
);