zois-core 2.1.1 → 2.2.1

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/dist/ui.js CHANGED
@@ -204,63 +204,107 @@ function getPreviousSubscreen() {
204
204
  }
205
205
  class BaseSubscreen {
206
206
  setSubscreen = setSubscreen;
207
+ setPreviousSubscreen = setPreviousSubscreen;
207
208
  get currentSubscreen() {
208
209
  return getCurrentSubscreen();
209
210
  }
210
211
  get previousSubscreen() {
211
212
  return getPreviousSubscreen();
212
213
  }
214
+ /**
215
+ * Called each frame.
216
+ *
217
+ * You probably want to override {@link onRun}, **do not** override `run` if you don't understand what you're doing.
218
+ */
213
219
  run() {
214
- }
220
+ this.onRun?.();
221
+ }
222
+ /**
223
+ * Called once after `setSubscreen()`.
224
+ * Responsible for how the subscreen will load.
225
+ *
226
+ * You probably want to override {@link onLoad}, **do not** override `load` if you don't understand what you're doing.
227
+ *
228
+ * Override {@link onLoad} for creating UI elements.
229
+ */
215
230
  load() {
216
231
  setSizeUnitVariable();
217
- this.createButton({
218
- x: 1815,
219
- y: 75,
220
- width: 90,
221
- height: 90,
222
- icon: dataUrlSvgWithColor(exitIcon, { fill: cssVar("--tmd-text", "black") }),
223
- tooltip: {
224
- position: "left",
225
- text: "Back"
226
- },
227
- modules: {
228
- base: [
229
- new StyleModule({
230
- zIndex: "10"
231
- })
232
- ]
233
- }
234
- }).addEventListener("click", () => this.exit());
235
- if (this.name) {
236
- this.createText({
237
- text: this.name,
238
- x: 100,
239
- y: 60,
240
- fontSize: 8
241
- }).style.cssText += "max-width: 85%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0.1em;";
242
- }
232
+ this.createExitButton();
233
+ if (this.name) this.createSubscreenTitle();
234
+ this.onLoad?.();
243
235
  eventBus?.emit("subscreenLoaded", {
244
236
  subscreen: this
245
237
  });
246
238
  }
239
+ /**
240
+ * Called once when subscreen is being unloaded.
241
+ *
242
+ * You probably want to override {@link onUnload}, **do not** override `unload` if you don't understand what you're doing.
243
+ */
247
244
  unload() {
245
+ this.onUnload?.();
248
246
  eventBus?.emit("subscreenUnloaded", {
249
247
  subscreen: this
250
248
  });
251
249
  }
250
+ /**
251
+ * Called after user clicks.
252
+ *
253
+ * You probably want to override {@link onClick}, **do not** override `click` if you don't understand what you're doing.
254
+ */
252
255
  click() {
253
- }
256
+ this.onClick?.();
257
+ }
258
+ /**
259
+ * Called after user presses `Esc` or clicks on exit button.
260
+ *
261
+ * Not called after subscreen unloading with `setSubscreen()`
262
+ *
263
+ * You probably want to override {@link onExit}, **do not** override `exit` if you don't understand what you're doing.
264
+ */
254
265
  exit() {
266
+ this.onExit?.();
255
267
  setPreviousSubscreen();
256
268
  }
257
269
  update() {
258
270
  }
271
+ /**
272
+ * Called after screen size change.
273
+ *
274
+ * You probably want to override {@link onResize}, **do not** override `resize` if you don't understand what you're doing.
275
+ */
259
276
  resize() {
260
277
  setSizeUnitVariable();
278
+ this.onResize?.();
261
279
  }
262
- setPreviousSubscreen() {
263
- setPreviousSubscreen();
280
+ createExitButton() {
281
+ this.createButton({
282
+ x: 1815,
283
+ y: 75,
284
+ width: 90,
285
+ height: 90,
286
+ icon: dataUrlSvgWithColor(exitIcon, { fill: cssVar("--tmd-text", "black") }),
287
+ tooltip: {
288
+ position: "left",
289
+ text: "Back"
290
+ },
291
+ modules: {
292
+ base: [
293
+ new StyleModule({
294
+ zIndex: "10"
295
+ })
296
+ ]
297
+ },
298
+ onClick: () => this.exit()
299
+ });
300
+ }
301
+ createSubscreenTitle() {
302
+ this.createText({
303
+ text: this.name,
304
+ x: 100,
305
+ y: 60,
306
+ fontSize: 8
307
+ }).style.cssText += "max-width: 85%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0.1em;";
264
308
  }
265
309
  create(shard) {
266
310
  const htmlElement = shard.mount();
@@ -355,11 +399,6 @@ class BaseSubscreen {
355
399
  return htmlElement;
356
400
  }
357
401
  }
358
- const subscreenHooks = {};
359
- function hookSubscreen(subscreenName, hook) {
360
- if (!subscreenHooks[subscreenName]) subscreenHooks[subscreenName] = [];
361
- subscreenHooks[subscreenName].push(hook);
362
- }
363
402
  export {
364
403
  BaseSubscreen,
365
404
  addDynamicClass,
@@ -374,7 +413,6 @@ export {
374
413
  getRelativeX,
375
414
  getRelativeY,
376
415
  hexToRgb,
377
- hookSubscreen,
378
416
  recolorSVG,
379
417
  setFontFamily,
380
418
  setFontSize,
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "zois-core",
3
- "version": "2.1.1",
3
+ "version": "2.2.1",
4
4
  "description": "The core for the my mods, which contains a shared code reused in all my mods",
5
5
  "bin": {
6
- "zois-core": "scripts/zois-core.mjs"
6
+ "zois-core": "dist/scripts/zois-core.js"
7
7
  },
8
8
  "author": "Zoi",
9
9
  "license": "MIT",
@@ -87,6 +87,7 @@
87
87
  "esbuild-plugin-copy": "^2.1.1",
88
88
  "glob": "^13.0.6",
89
89
  "nodemon": "^3.1.14",
90
+ "simple-git": "^3.36.0",
90
91
  "typescript": "^5.9.3"
91
92
  },
92
93
  "scripts": {
@@ -1,126 +0,0 @@
1
- import fs from "fs/promises";
2
- import path from "path";
3
- import chalk from 'chalk';
4
- import { Octokit } from "@octokit/rest";
5
-
6
- const octokit = new Octokit();
7
- const args = process.argv.slice(2);
8
- const command = args[0];
9
-
10
- function getArg(name) {
11
- const arg = args.find((a) => a.startsWith("--" + name));
12
- if (arg) return arg.slice(name.length + 3);
13
- return null;
14
- }
15
-
16
- switch (command) {
17
- case "generate-changelog": {
18
- generateChangelog().catch((err) => {
19
- console.log(chalk.red("Script failed:"), err.message);
20
- process.exit(1);
21
- });
22
- break;
23
- }
24
- default: {
25
- console.log(chalk.red("Unknown command"), `"${chalk.cyan(command)}"`);
26
- console.log("Available commands:")
27
- console.log(`• ${chalk.cyan("generate-changelog")} — Generate changelog bundle`)
28
- }
29
- }
30
-
31
- async function getCommitsSince(owner, repo, sinceSha, perPage = 50) {
32
- const commits = [];
33
- let page = 1;
34
- let hasMore = true;
35
-
36
- try {
37
- while (hasMore) {
38
- const { data } = await octokit.rest.repos.listCommits({
39
- owner,
40
- repo,
41
- sha: "HEAD",
42
- per_page: perPage,
43
- page: page,
44
- });
45
-
46
- if (data.length === 0) break;
47
-
48
- const startIndex = data.findIndex((commit) => commit.sha === sinceSha);
49
-
50
- if (startIndex !== -1) {
51
- commits.push(...data.slice(0, startIndex + 1));
52
- break;
53
- } else {
54
- commits.push(...data);
55
- }
56
-
57
- page++;
58
- hasMore = data.length === perPage;
59
- }
60
-
61
- return commits.map((commit) => ({
62
- sha: commit.sha,
63
- message: commit.commit.message,
64
- date: commit.commit.author.date,
65
- author: {
66
- name: commit.author?.login || commit.commit.author.name,
67
- avatar_url: commit.author?.avatar_url,
68
- html_url: commit.author?.html_url,
69
- },
70
- committer: {
71
- name: commit.committer?.login || commit.commit.committer.name,
72
- avatar_url: commit.committer?.avatar_url,
73
- }
74
- }));
75
-
76
- } catch (error) {
77
- console.log(chalk.red("Error getting commits:"), error.message);
78
- throw error;
79
- }
80
- }
81
-
82
- async function generateChangelog() {
83
- const owner = getArg("owner");
84
- if (!owner) {
85
- console.log(chalk.red("--owner argument not specified"));
86
- process.exit(1);
87
- }
88
- const repo = getArg("repo");
89
- if (!repo) {
90
- console.log(chalk.red("--repo argument not specified"));
91
- process.exit(1);
92
- }
93
- const fromCommit = getArg("from");
94
- if (!fromCommit) {
95
- console.log(chalk.red("--from argument not specified"));
96
- process.exit(1);
97
- }
98
- console.log(`Generating changelog from commit ${chalk.cyan(fromCommit)}...`);
99
-
100
- const commits = await getCommitsSince(owner, repo, fromCommit);
101
-
102
- const resultToWrite = {
103
- generated_at: (new Date()).toISOString(),
104
- changes: commits.map((c) => ({
105
- message: c.message,
106
- sha: c.sha,
107
- author: {
108
- name: c.author.name,
109
- avatar_url: c.author.avatar_url ?? "https://avatars.githubusercontent.com/" + c.author.name,
110
- },
111
- date: c.date,
112
- tags: [],
113
- commit_url: `https://github.com/${owner}/${repo}/commit/${c.sha}`
114
- }))
115
- };
116
-
117
- const outputPath = path.join(process.cwd(), "changelog.json");
118
-
119
- await fs.writeFile(
120
- outputPath,
121
- JSON.stringify(resultToWrite, null, 2),
122
- "utf-8"
123
- );
124
-
125
- console.log(`Generated changelog.json. (${commits.length} commits)`);
126
- }