@cabin-icarus/tooltip_generator 1.8.0 → 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 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
@@ -39,6 +39,18 @@ watcher.on("error", (error: Error) => {
39
39
 
40
40
  watcher.on("ready", () => {
41
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
+ ))
42
54
  })
43
55
 
44
56
  let compiler = loadCompiler();
@@ -87,16 +99,4 @@ const __getAllFiles = (dirPath: string, arrayOfFiles?: string[]) =>
87
99
  })
88
100
 
89
101
  return arrayOfFiles
90
- }
91
-
92
- const files = __getAllFiles(folderPath);
93
-
94
- Promise.all(files.map(x =>
95
- {
96
- const temp = fs.readFileSync(x);
97
- fs.writeFile(x, ' ', err =>
98
- {
99
- fs.writeFileSync(x, temp);
100
- });
101
- }
102
- ))
102
+ }
@@ -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
- addon_filepath: string = path.join("node_modules/~resource", "addon_");
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
- AbilityArray: Abilities,
48
- ModifierArray: Modifiers,
49
- StandardArray: StandardTooltips,
50
- // TalentArray: Talents,
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
- //reimagined_effects = language_override.reimagined_effects_override;
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
 
@@ -99,6 +99,7 @@ declare global
99
99
  AbilityArray?: Array<AbilityLocalization>;
100
100
  ModifierArray?: Array<ModifierLocalization>;
101
101
  StandardArray?: Array<StandardLocalization>;
102
+ Include?:Map<Language, string[]>;
102
103
  //TalentArray?: Array<HeroTalents>;
103
104
  }
104
105
 
package/package.json CHANGED
@@ -44,5 +44,5 @@
44
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.8.0"
47
+ "version": "1.8.2"
48
48
  }