@kurot/cli 3.1.0 → 3.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/CHANGELOG.md +61 -0
- package/README.md +66 -11
- package/dist/core/dev-server.js +4 -1
- package/dist/core/dev-server.js.map +1 -1
- package/dist/core/kui/index.d.ts +2 -1
- package/dist/core/kui/index.d.ts.map +1 -1
- package/dist/core/kui/index.js +3 -3
- package/dist/core/kui/index.js.map +1 -1
- package/dist/core/kui/kui-parser.d.ts +1 -1
- package/dist/core/kui/kui-parser.d.ts.map +1 -1
- package/dist/core/kui/kui-parser.js +3 -3
- package/dist/core/kui/kui-parser.js.map +1 -1
- package/dist/core/kui/skin-module-builder.d.ts.map +1 -1
- package/dist/core/kui/skin-module-builder.js +14 -4
- package/dist/core/kui/skin-module-builder.js.map +1 -1
- package/dist/core/template.d.ts.map +1 -1
- package/dist/core/template.js +1 -0
- package/dist/core/template.js.map +1 -1
- package/docs/ai-context.md +33 -16
- package/docs/architecture.md +9 -1
- package/docs/game-template.md +60 -0
- package/docs/label-text-layout.md +1 -1
- package/package.json +2 -2
- package/templates/game/package.json +2 -1
- package/templates/game/resource/assets/fonts/ChakraPetch-Bold.ttf +0 -0
- package/templates/game/resource/assets/fonts/ChakraPetch-Regular.ttf +0 -0
- package/templates/game/resource/assets/fonts/OFL.txt +93 -0
- package/templates/game/resource/config/locale.json +4 -0
- package/templates/game/resource/config/style.json +16 -0
- package/templates/game/resource/default.res.json +11 -1
- package/templates/game/resource/lang/lang_en_US.properties +5 -0
- package/templates/game/resource/ui/skins/ButtonSkin.kui.xml +1 -1
- package/templates/game/resource/ui/skins/CheckBoxSkin.kui.xml +1 -1
- package/templates/game/resource/ui/skins/ComboBoxSkin.kui.xml +1 -1
- package/templates/game/resource/ui/skins/ItemRendererSkin.kui.xml +1 -1
- package/templates/game/resource/ui/skins/PanelSkin.kui.xml +1 -1
- package/templates/game/resource/ui/skins/ProgressBarSkin.kui.xml +1 -1
- package/templates/game/resource/ui/skins/RadioButtonSkin.kui.xml +1 -1
- package/templates/game/resource/ui/skins/TextInputSkin.kui.xml +1 -1
- package/templates/game/resource/ui/skins/ToggleButtonSkin.kui.xml +1 -1
- package/templates/game/src/LocaleManager.ts +109 -0
- package/templates/game/src/Main.ts +58 -34
- package/templates/game/src/StyleManager.ts +57 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { getUIStyleColor, getUIStyleFontAlias, getUIStyleFontFamily, parseUIStyleSheet } from '@kurot/ui-document';
|
|
2
|
+
import type { UIStyleFontFace } from '@kurot/ui-document';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 项目启动时加载固定样式表,字体全部就绪后再创建 Player 和 UI。
|
|
6
|
+
* 字体别名保持稳定,换字体文件不需要逐个修改皮肤。
|
|
7
|
+
*/
|
|
8
|
+
export class StyleManager {
|
|
9
|
+
private static _colors: Readonly<Record<string, number>> = Object.freeze({});
|
|
10
|
+
private static _fontFamily?: string;
|
|
11
|
+
|
|
12
|
+
public static get fontFamily(): string {
|
|
13
|
+
if (this._fontFamily === undefined) {
|
|
14
|
+
throw new Error('Project styles are not initialized.');
|
|
15
|
+
}
|
|
16
|
+
return this._fontFamily;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public static async init(): Promise<void> {
|
|
20
|
+
const resourceRoot = new URL('resource/', document.baseURI);
|
|
21
|
+
const response = await fetch(new URL('config/style.json', resourceRoot));
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
throw new Error(`Unable to load resource/config/style.json: HTTP ${response.status}.`);
|
|
24
|
+
}
|
|
25
|
+
const stylesheet = parseUIStyleSheet(await response.json());
|
|
26
|
+
const loading = Object.entries(stylesheet.fonts.families).flatMap(([key, family]) =>
|
|
27
|
+
family.faces.map(face => this._loadFace(key, face, resourceRoot)),
|
|
28
|
+
);
|
|
29
|
+
const faces = await Promise.all(loading);
|
|
30
|
+
|
|
31
|
+
// 全部成功后一次性发布,失败时不留下半套字体或新的默认值。
|
|
32
|
+
for (const face of faces) {
|
|
33
|
+
document.fonts.add(face);
|
|
34
|
+
}
|
|
35
|
+
this._fontFamily = getUIStyleFontFamily(stylesheet);
|
|
36
|
+
this._colors = stylesheet.colors;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 业务代码需要动态设置文字颜色时,读取与皮肤编译相同的颜色表。
|
|
41
|
+
*/
|
|
42
|
+
public static getColor(key: string): number {
|
|
43
|
+
return getUIStyleColor(this._colors, key);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private static async _loadFace(key: string, definition: UIStyleFontFace, resourceRoot: URL): Promise<FontFace> {
|
|
47
|
+
const url = new URL(definition.url.split('/').map(encodeURIComponent).join('/'), resourceRoot);
|
|
48
|
+
const face = new FontFace(getUIStyleFontAlias(key), `url("${url.href}")`, {
|
|
49
|
+
weight: String(definition.weight),
|
|
50
|
+
});
|
|
51
|
+
try {
|
|
52
|
+
return await face.load();
|
|
53
|
+
} catch (cause) {
|
|
54
|
+
throw new Error(`Unable to load project font ${key} (${definition.weight}): ${definition.url}.`, { cause });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|