@cabin-icarus/tooltip_generator 1.7.15 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -0
- package/fsWatcher.ts +67 -34
- package/install.ts +1 -1
- package/localizationCompiler.ts +57 -23
- package/localizationInterfaces.d.ts +1 -0
- package/package.json +2 -2
- package/Helper.ts +0 -4
package/README.md
CHANGED
|
@@ -37,3 +37,42 @@ To test: in the resource folder, go to `resource/localization`, open `localizati
|
|
|
37
37
|
```
|
|
38
38
|
* Save as any name like `dota_ts.sublime-build`
|
|
39
39
|
* Have `fsWatcher.ts` or `package.json` or any other file from the project open -> press Ctrl + Shift + B -> select `dota_ts` -> console opens and it is run, is closed with esc, will still continue to compile everything until sublime is closed.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Include use
|
|
43
|
+
```ts
|
|
44
|
+
Folder Tree
|
|
45
|
+
- resource/langs/addon_schinese.txt kv: "hello" "hello china!"
|
|
46
|
+
- resource/langs/addon_english.txt kv: "hello" "hello english!"
|
|
47
|
+
- resource/langs/addon_russian.txt kv: "hello" "hello russian!"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
export function GenerateLocalizationData(): LocalizationData
|
|
52
|
+
{
|
|
53
|
+
const info: LocalizationData =
|
|
54
|
+
{
|
|
55
|
+
Include:new Map()
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
info.Include.set(Language.Schinese, [
|
|
60
|
+
"langs/addon_schinese.txt",
|
|
61
|
+
])
|
|
62
|
+
|
|
63
|
+
info.Include.set(Language.English, [
|
|
64
|
+
"langs/addon_english.txt",
|
|
65
|
+
])
|
|
66
|
+
|
|
67
|
+
info.Include.set(Language.Russian, [
|
|
68
|
+
"langs/addon_russian.txt",
|
|
69
|
+
])
|
|
70
|
+
|
|
71
|
+
return info
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
out file:
|
|
75
|
+
- resource/addon_schinese.txt kv: "hello" "hello china!"
|
|
76
|
+
- resource/addon_english.txt kv: "hello" "hello english!"
|
|
77
|
+
- resource/addon_russian.txt kv: "hello" "hello russian!"
|
|
78
|
+
```
|
package/fsWatcher.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
+
const path = require("path");
|
|
2
3
|
import { LocalizationCompiler } from './localizationCompiler';
|
|
3
4
|
const watch = require("node-watch");
|
|
4
5
|
|
|
@@ -6,57 +7,69 @@ let completeData: {[path: string]: LocalizationData} = {};
|
|
|
6
7
|
const resourcePath = "node_modules/~resource";
|
|
7
8
|
const generatorPath = "node_modules/~generator";
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
const folderPath = resourcePath + "/localization";
|
|
10
11
|
|
|
11
|
-
let watcher = watch([
|
|
12
|
+
let watcher = watch([folderPath], {recursive: true})
|
|
12
13
|
watcher.on("change", (eventType ?: 'update' | 'remove' | undefined, filePath ?: string) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
14
|
+
if (!filePath) return;
|
|
15
|
+
if (filePath.includes("localizationCompiler.ts")) {
|
|
16
|
+
compiler = loadCompiler();
|
|
17
|
+
}
|
|
18
|
+
let match = /(node_modules[\\/])?(.*[\/|\\](.+)).ts/g.exec(filePath);
|
|
19
|
+
if (eventType == "update" && filePath && match) {
|
|
20
|
+
const curpath = match[2];
|
|
21
|
+
const data = getDataFromFile(curpath + ".ts");
|
|
22
|
+
if (data) {
|
|
23
|
+
completeData[curpath] = data;
|
|
24
|
+
combineData();
|
|
25
|
+
}
|
|
26
|
+
} else if (eventType == "remove" && match) {
|
|
27
|
+
if (completeData.hasOwnProperty(match[2])) {
|
|
28
|
+
delete completeData[match[2]];
|
|
29
|
+
combineData();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
31
32
|
})
|
|
32
33
|
|
|
33
34
|
// not really neccessarry:
|
|
34
35
|
watcher.on("error", (error: Error) => {
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
console.log("\x1b[31m%s\x1b[0m", "Something went wrong!");
|
|
37
|
+
console.log(error);
|
|
37
38
|
})
|
|
38
39
|
|
|
39
40
|
watcher.on("ready", () => {
|
|
40
|
-
|
|
41
|
+
console.log("\x1b[32m%s\x1b[0m", "Ready!");
|
|
42
|
+
|
|
43
|
+
const files = __getAllFiles(folderPath);
|
|
44
|
+
|
|
45
|
+
Promise.all(files.map(x =>
|
|
46
|
+
{
|
|
47
|
+
const temp = fs.readFileSync(x);
|
|
48
|
+
fs.writeFile(x, ' ', err =>
|
|
49
|
+
{
|
|
50
|
+
fs.writeFileSync(x, temp);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
))
|
|
41
54
|
})
|
|
42
55
|
|
|
43
56
|
let compiler = loadCompiler();
|
|
44
57
|
|
|
45
58
|
function getDataFromFile(filePath: string): LocalizationData | undefined {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
if (!fs.existsSync("node_modules/" + filePath)){
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
delete require.cache[require.resolve(filePath)]
|
|
63
|
+
let file = require(filePath);
|
|
64
|
+
if (file["GenerateLocalizationData"]) {
|
|
65
|
+
const localizationArr: LocalizationData = file["GenerateLocalizationData"]();
|
|
66
|
+
return localizationArr;
|
|
67
|
+
}
|
|
68
|
+
return;
|
|
56
69
|
}
|
|
57
70
|
|
|
58
71
|
function combineData() {
|
|
59
|
-
|
|
72
|
+
compiler.OnLocalizationDataChanged(completeData);
|
|
60
73
|
}
|
|
61
74
|
|
|
62
75
|
function loadCompiler(): LocalizationCompiler
|
|
@@ -67,3 +80,23 @@ function loadCompiler(): LocalizationCompiler
|
|
|
67
80
|
const compilerClass: new () => LocalizationCompiler = require("~generator/localizationCompiler").LocalizationCompiler;
|
|
68
81
|
return new compilerClass();
|
|
69
82
|
}
|
|
83
|
+
|
|
84
|
+
const __getAllFiles = (dirPath: string, arrayOfFiles?: string[]) =>
|
|
85
|
+
{
|
|
86
|
+
const files = fs.readdirSync(dirPath)
|
|
87
|
+
|
|
88
|
+
arrayOfFiles = arrayOfFiles ?? []
|
|
89
|
+
|
|
90
|
+
files.forEach(function (file)
|
|
91
|
+
{
|
|
92
|
+
if (fs.statSync(dirPath + "/" + file).isDirectory())
|
|
93
|
+
{
|
|
94
|
+
arrayOfFiles = __getAllFiles(path.join(dirPath, file), arrayOfFiles)
|
|
95
|
+
} else
|
|
96
|
+
{
|
|
97
|
+
arrayOfFiles?.push(path.join(dirPath, file))
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
return arrayOfFiles
|
|
102
|
+
}
|
package/install.ts
CHANGED
|
@@ -10,7 +10,7 @@ interface packageSnippet {
|
|
|
10
10
|
|
|
11
11
|
// define package insertions
|
|
12
12
|
const devScripts = [
|
|
13
|
-
["dev:runlocalizationWatcher", "ts-node node_modules/~generator/fsWatcher.ts"]
|
|
13
|
+
["dev:runlocalizationWatcher", "ts-node -P node_modules/~resource/tsconfig.json node_modules/~generator/fsWatcher.ts"]
|
|
14
14
|
]
|
|
15
15
|
const initSCript = ["init", "link-module-alias && ts-node node_modules/~generator/init.ts"]
|
|
16
16
|
const aliases = [
|
package/localizationCompiler.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
-
import { KVObject, serialize } from 'valve-kv'
|
|
3
|
+
import { KVObject, serialize,deserializeFile } from 'valve-kv'
|
|
4
4
|
import { Language } from "~resource/languages"
|
|
5
5
|
|
|
6
6
|
export class LocalizationCompiler
|
|
7
7
|
{
|
|
8
|
-
|
|
8
|
+
folderPath: string = path.join("node_modules/~resource");
|
|
9
|
+
addon_filepath: string = path.join(this.folderPath, "addon_");
|
|
9
10
|
filepath_format: string = ".txt";
|
|
10
11
|
currentWrites: Set<string> = new Set();
|
|
11
12
|
writeTimeout?: NodeJS.Timeout;
|
|
@@ -29,7 +30,7 @@ export class LocalizationCompiler
|
|
|
29
30
|
text = text.replace(/\{(\w*)}($|[^%])/g, "%$1%$2")
|
|
30
31
|
text = text.replace(/\{(\w*)}%/g, "%$1%%%");
|
|
31
32
|
text = text.replace(/%\{(\w*)}/g, "%%%$1%");
|
|
32
|
-
|
|
33
|
+
|
|
33
34
|
return text;
|
|
34
35
|
}
|
|
35
36
|
}
|
|
@@ -43,12 +44,14 @@ export class LocalizationCompiler
|
|
|
43
44
|
//let Talents: Array<HeroTalents> = new Array<HeroTalents>();
|
|
44
45
|
|
|
45
46
|
const localization_info: LocalizationData =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
{
|
|
48
|
+
AbilityArray: Abilities,
|
|
49
|
+
ModifierArray: Modifiers,
|
|
50
|
+
StandardArray: StandardTooltips,
|
|
51
|
+
// TalentArray: Talents,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const refMap: Map<Language, string[]> = new Map<Language, string[]>();
|
|
52
55
|
|
|
53
56
|
for (const [key, data] of Object.entries(allData)) {
|
|
54
57
|
if (data.AbilityArray) {
|
|
@@ -60,16 +63,29 @@ export class LocalizationCompiler
|
|
|
60
63
|
if (data.StandardArray) {
|
|
61
64
|
Array.prototype.push.apply(StandardTooltips, data.StandardArray);
|
|
62
65
|
}
|
|
66
|
+
if (data.Include)
|
|
67
|
+
{
|
|
68
|
+
for (const [lang, includes] of data.Include.entries())
|
|
69
|
+
{
|
|
70
|
+
if (!refMap.has(lang)) {
|
|
71
|
+
refMap.set(lang, []);
|
|
72
|
+
}
|
|
73
|
+
const existingIncludes = refMap.get(lang);
|
|
74
|
+
if (existingIncludes) {
|
|
75
|
+
existingIncludes.push(...includes);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
63
79
|
}
|
|
64
80
|
|
|
65
81
|
// Generate information for every language
|
|
66
82
|
const languages = Object.values(Language).filter(v => typeof v !== "number");
|
|
67
83
|
for (const language of languages)
|
|
68
|
-
{
|
|
84
|
+
{
|
|
69
85
|
if (language !== Language.None)
|
|
70
86
|
{
|
|
71
87
|
const tokens: KVObject = this.GenerateContentStringForLanguage(language, localization_info);
|
|
72
|
-
this.WriteContentToAddonFile(language, tokens);
|
|
88
|
+
this.WriteContentToAddonFile(language, tokens, refMap.get(language));
|
|
73
89
|
}
|
|
74
90
|
}
|
|
75
91
|
}
|
|
@@ -96,7 +112,7 @@ export class LocalizationCompiler
|
|
|
96
112
|
}
|
|
97
113
|
}
|
|
98
114
|
|
|
99
|
-
tokens[standardLocalization.classname] = standard_tooltip_string;
|
|
115
|
+
tokens[standardLocalization.classname] = standard_tooltip_string;
|
|
100
116
|
}
|
|
101
117
|
}
|
|
102
118
|
|
|
@@ -138,7 +154,7 @@ export class LocalizationCompiler
|
|
|
138
154
|
// Check for reimagined effect overrides
|
|
139
155
|
//if (language_override.reimagined_effects_override)
|
|
140
156
|
//{
|
|
141
|
-
|
|
157
|
+
//reimagined_effects = language_override.reimagined_effects_override;
|
|
142
158
|
//}
|
|
143
159
|
|
|
144
160
|
// Check for lore override
|
|
@@ -178,20 +194,20 @@ export class LocalizationCompiler
|
|
|
178
194
|
if (ability_name)
|
|
179
195
|
{
|
|
180
196
|
tokens[ability_string] = ability_name;
|
|
181
|
-
}
|
|
197
|
+
}
|
|
182
198
|
|
|
183
199
|
// Add description localization
|
|
184
200
|
if (ability_description)
|
|
185
201
|
{
|
|
186
202
|
ability_description = this.TransformForLocalization(ability_description, false);
|
|
187
203
|
tokens[`${ability_string}_description`] = ability_description;
|
|
188
|
-
}
|
|
204
|
+
}
|
|
189
205
|
|
|
190
206
|
// Lore, if any
|
|
191
207
|
if (ability_lore)
|
|
192
208
|
{
|
|
193
209
|
const transformed_lore = this.TransformForLocalization(ability_lore, false);
|
|
194
|
-
tokens[`${ability_string}_Lore`] = transformed_lore;
|
|
210
|
+
tokens[`${ability_string}_Lore`] = transformed_lore;
|
|
195
211
|
}
|
|
196
212
|
|
|
197
213
|
// Notes, if any
|
|
@@ -201,7 +217,7 @@ export class LocalizationCompiler
|
|
|
201
217
|
for (const note of ability_notes)
|
|
202
218
|
{
|
|
203
219
|
const transformed_note = this.TransformForLocalization(note, false);
|
|
204
|
-
tokens[`${ability_string}_Note${counter}`] = transformed_note;
|
|
220
|
+
tokens[`${ability_string}_Note${counter}`] = transformed_note;
|
|
205
221
|
|
|
206
222
|
counter++;
|
|
207
223
|
}
|
|
@@ -211,14 +227,14 @@ export class LocalizationCompiler
|
|
|
211
227
|
if (scepter_description)
|
|
212
228
|
{
|
|
213
229
|
const ability_scepter_description = this.TransformForLocalization(scepter_description, false);
|
|
214
|
-
tokens[`${ability_string}_scepter_description`] = ability_scepter_description;
|
|
230
|
+
tokens[`${ability_string}_scepter_description`] = ability_scepter_description;
|
|
215
231
|
}
|
|
216
232
|
|
|
217
233
|
// Shard, if any
|
|
218
234
|
if (shard_description)
|
|
219
235
|
{
|
|
220
236
|
const ability_shard_description = this.TransformForLocalization(shard_description, false);
|
|
221
|
-
tokens[`${ability_string}_shard_description`] = ability_shard_description;
|
|
237
|
+
tokens[`${ability_string}_shard_description`] = ability_shard_description;
|
|
222
238
|
}
|
|
223
239
|
|
|
224
240
|
// Ability specials, if any
|
|
@@ -240,7 +256,7 @@ export class LocalizationCompiler
|
|
|
240
256
|
|
|
241
257
|
ability_special_text += ability_special.text;
|
|
242
258
|
|
|
243
|
-
tokens[`${ability_string}_${ability_special.ability_special}`] = ability_special_text;
|
|
259
|
+
tokens[`${ability_string}_${ability_special.ability_special}`] = ability_special_text;
|
|
244
260
|
}
|
|
245
261
|
}
|
|
246
262
|
}
|
|
@@ -281,21 +297,21 @@ export class LocalizationCompiler
|
|
|
281
297
|
if (modifier_name)
|
|
282
298
|
{
|
|
283
299
|
tokens[modifier_string] = modifier_name;
|
|
284
|
-
}
|
|
300
|
+
}
|
|
285
301
|
|
|
286
302
|
// Add description to localization string
|
|
287
303
|
if (modifier_description)
|
|
288
304
|
{
|
|
289
305
|
modifier_description = this.TransformForLocalization(modifier_description, true);
|
|
290
306
|
tokens[`${modifier_string}_description`] = modifier_description;
|
|
291
|
-
}
|
|
307
|
+
}
|
|
292
308
|
}
|
|
293
309
|
}
|
|
294
310
|
|
|
295
311
|
return tokens;
|
|
296
312
|
}
|
|
297
313
|
|
|
298
|
-
WriteContentToAddonFile(language: string, tokens: KVObject)
|
|
314
|
+
WriteContentToAddonFile(language: string, tokens: KVObject, includes: string[] | undefined)
|
|
299
315
|
{
|
|
300
316
|
// Set based on language
|
|
301
317
|
const filepath = this.addon_filepath + language.toString() + this.filepath_format;
|
|
@@ -303,6 +319,24 @@ export class LocalizationCompiler
|
|
|
303
319
|
// Add the opening tokens
|
|
304
320
|
const kv = {lang: { Language: language, Tokens: tokens}}
|
|
305
321
|
|
|
322
|
+
if (includes && includes.length > 0)
|
|
323
|
+
{
|
|
324
|
+
for(const include of includes)
|
|
325
|
+
{
|
|
326
|
+
try {
|
|
327
|
+
const itemData = deserializeFile(path.join(this.folderPath, include), "utf-8");
|
|
328
|
+
if (itemData && itemData.lang && itemData.lang.Tokens)
|
|
329
|
+
{
|
|
330
|
+
Object.assign(kv.lang.Tokens, itemData.lang.Tokens);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
catch (e)
|
|
334
|
+
{
|
|
335
|
+
console.warn(`${include} file processing failed, please check whether the file encoding is utf-8 errorMsg:${e}`)
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
306
340
|
// Serialize!
|
|
307
341
|
let write_string = serialize(kv);
|
|
308
342
|
|
package/package.json
CHANGED
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"dev": "run-p dev:*",
|
|
44
|
-
"dev:runlocalizationWatcher": "ts-node node_modules/~generator/fsWatcher.ts",
|
|
44
|
+
"dev:runlocalizationWatcher": "ts-node -P node_modules/~resource/tsconfig.json node_modules/~generator/fsWatcher.ts",
|
|
45
45
|
"init": "link-module-alias && ts-node node_modules/~generator/init.ts"
|
|
46
46
|
},
|
|
47
|
-
"version": "1.
|
|
47
|
+
"version": "1.8.2"
|
|
48
48
|
}
|
package/Helper.ts
DELETED