@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,60 @@
|
|
|
1
|
+
# Project styles and languages in the game template
|
|
2
|
+
|
|
3
|
+
CLI 3.2.1 includes this template update and is prepared for publication. It adds
|
|
4
|
+
project-owned initialization without changing Core/UI APIs or migrating existing
|
|
5
|
+
projects. The empty template stays minimal.
|
|
6
|
+
|
|
7
|
+
## Files
|
|
8
|
+
|
|
9
|
+
- resource/config/style.json declares the primary font role and disabled-text color.
|
|
10
|
+
- resource/assets/fonts contains unmodified Chakra Petch regular (400) and bold (700)
|
|
11
|
+
files, with OFL.txt. Source: [Google Fonts](https://github.com/google/fonts/tree/main/ofl/chakrapetch).
|
|
12
|
+
- resource/config/locale.json enables English and selects en_US by default.
|
|
13
|
+
- resource/lang/lang_en_US.properties contains the scene title, button and descriptions.
|
|
14
|
+
- default.res.json registers locale_json and lang_en_US_properties in preload.
|
|
15
|
+
style.json and fonts are read directly and need no manifest entries.
|
|
16
|
+
|
|
17
|
+
## Startup order
|
|
18
|
+
|
|
19
|
+
1. StyleManager reads and validates the stylesheet through published ui-document.
|
|
20
|
+
2. It loads every configured FontFace; only after all succeed does it register
|
|
21
|
+
faces and publish the default CSS font family and numeric color palette.
|
|
22
|
+
3. Main sets TextField.default_fontFamily, then creates Player and the Preloader.
|
|
23
|
+
4. Main loads the manifest, theme and preload resources.
|
|
24
|
+
5. LocaleManager registers the enabled text files, selects the language and creates
|
|
25
|
+
the translated scene. Startup errors are reported through console.error.
|
|
26
|
+
|
|
27
|
+
This ordering includes loading-screen Labels in the project font. The loading
|
|
28
|
+
screen's startup messages stay in English because translations are not loaded yet.
|
|
29
|
+
Templates do not implement live font/theme/language replacement.
|
|
30
|
+
|
|
31
|
+
## Change fonts and colors
|
|
32
|
+
|
|
33
|
+
Font keys such as primary produce stable aliases such as kurot-primary. Replace
|
|
34
|
+
files and update style.json resource-relative paths, retaining weight 400 and
|
|
35
|
+
unique weights. Default skins inherit the configured font; explicit Label fontFamily
|
|
36
|
+
values still override it. Existing stylesheet files must contain valid font definitions.
|
|
37
|
+
Keep the font's applicable license with any replacement distribution.
|
|
38
|
+
|
|
39
|
+
Label state colors use textColor.disabled="@style:colors:disabled-text". The CLI
|
|
40
|
+
compiles these references into numbers. Dynamic application code reads the same
|
|
41
|
+
palette through StyleManager.getColor('disabled-text'); enabled state behavior and
|
|
42
|
+
restoration of a normal color remain application responsibilities.
|
|
43
|
+
|
|
44
|
+
## Add languages
|
|
45
|
+
|
|
46
|
+
Use the Editor's language window to add a code, create its properties file and
|
|
47
|
+
update locale.json/default.res.json together. Only English is initially enabled.
|
|
48
|
+
Manual additions must use lang_<code>_properties text resources in preload.
|
|
49
|
+
|
|
50
|
+
LocaleManager accepts the project default or URL ?lang=fr / ?lang=fr_FR / ?lang=fr-FR.
|
|
51
|
+
A full code match wins, then a matching base language, then the configured default.
|
|
52
|
+
The default may be empty. Absent configuration or an empty language list clears registrations;
|
|
53
|
+
enabled languages with unavailable text resources or an invalid default fail before
|
|
54
|
+
publishing the new set. The last successful set is retained on initialization failure.
|
|
55
|
+
|
|
56
|
+
getString(key, ...args) reads the current translation, then English, then the key.
|
|
57
|
+
An explicitly empty translation remains empty. The simple properties format uses
|
|
58
|
+
one key=value per line, #/! comments, common escapes including newline/Unicode,
|
|
59
|
+
and {0}, {1} placeholders. Continuation lines and Java properties' colon-only
|
|
60
|
+
separators are not supported. UI translation is explicit; it is not an engine binding.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Label text compilation
|
|
2
2
|
|
|
3
|
-
CLI 3.1
|
|
3
|
+
CLI 3.2.1 consumes ui-document 0.10.x and compiles KUI text-fitting properties
|
|
4
4
|
through the existing UIDocument → SkinIR → ESM factory pipeline. The semantic
|
|
5
5
|
document format remains version 2.
|
|
6
6
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kurot/cli",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "Kurot CLI - build tool for Kurot Editor KUI XML workflows",
|
|
5
5
|
"author": "Kelvin <kyia.x52@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"kurot": "tsx src/index.ts"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@kurot/ui-document": "^0.
|
|
31
|
+
"@kurot/ui-document": "^0.10.0",
|
|
32
32
|
"commander": "^13.0.0",
|
|
33
33
|
"esbuild": "^0.25.0"
|
|
34
34
|
},
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2018 The Chakra Petch Project Authors (https://github.com/m4rc1e/Chakra-Petch.git)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"fonts": {
|
|
4
|
+
"default": "primary",
|
|
5
|
+
"families": {
|
|
6
|
+
"primary": {
|
|
7
|
+
"fallback": ["Arial", "sans-serif"],
|
|
8
|
+
"faces": [
|
|
9
|
+
{ "url": "assets/fonts/ChakraPetch-Regular.ttf", "weight": 400 },
|
|
10
|
+
{ "url": "assets/fonts/ChakraPetch-Bold.ttf", "weight": 700 }
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"colors": { "disabled-text": "#999999" }
|
|
16
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"groups": [
|
|
3
3
|
{
|
|
4
|
-
"keys": "eui",
|
|
4
|
+
"keys": "eui,locale_json,lang_en_US_properties",
|
|
5
5
|
"name": "preload"
|
|
6
6
|
}
|
|
7
7
|
],
|
|
@@ -10,6 +10,16 @@
|
|
|
10
10
|
"name": "eui",
|
|
11
11
|
"type": "sheet",
|
|
12
12
|
"url": "assets/ui/eui/eui.json"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "locale_json",
|
|
16
|
+
"type": "json",
|
|
17
|
+
"url": "config/locale.json"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"name": "lang_en_US_properties",
|
|
21
|
+
"type": "text",
|
|
22
|
+
"url": "lang/lang_en_US.properties"
|
|
13
23
|
}
|
|
14
24
|
]
|
|
15
25
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
2
|
<Skin xmlns="https://kurot.dev/ui/1" class="skins.ButtonSkin" states="disabled,down,up" minHeight="50" minWidth="100">
|
|
3
3
|
<Image height="100%" scale9Grid="1,3,8,8" source="button_up_png" width="100%" alpha.disabled="0.5" source.down="button_down_png" />
|
|
4
|
-
<Label id="labelDisplay" bottom="8" left="8" right="8" size="20" textAlign="center" textColor="#FFFFFF" top="8" verticalAlign="middle" />
|
|
4
|
+
<Label id="labelDisplay" bottom="8" left="8" right="8" size="20" textAlign="center" textColor="#FFFFFF" textColor.disabled="@style:colors:disabled-text" top="8" verticalAlign="middle" />
|
|
5
5
|
<Image id="iconDisplay" horizontalCenter="0" verticalCenter="0" />
|
|
6
6
|
</Skin>
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
<HorizontalLayout verticalAlign="middle" />
|
|
6
6
|
</layout>
|
|
7
7
|
<Image alpha="1" fillMode="scale" source="checkbox_unselect_png" alpha.disabled="0.5" source.disabledAndSelected="checkbox_select_disabled_png" alpha.down="0.7" source.downAndSelected="checkbox_select_down_png" source.upAndSelected="checkbox_select_up_png" />
|
|
8
|
-
<Label id="labelDisplay"
|
|
8
|
+
<Label id="labelDisplay" size="20" textAlign="center" textColor="#707070" verticalAlign="middle" />
|
|
9
9
|
</Group>
|
|
10
10
|
</Skin>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
2
|
<Skin xmlns="https://kurot.dev/ui/1" class="skins.ComboBoxSkin" states="disabled,normal,open" minHeight="36" minWidth="100">
|
|
3
3
|
<Rect fillColor="#1A1A2E" height="36" strokeColor="#0F3460" strokeWeight="1" width="100%" fillColor.disabled="#16213E" strokeColor.disabled="#4A5459" fillColor.open="#16213E" strokeColor.open="#6C5CE7" />
|
|
4
|
-
<Label id="labelDisplay" height="36" left="10" right="36" size="14" textColor="#DFE6E9" top="0" verticalAlign="middle" textColor.disabled="
|
|
4
|
+
<Label id="labelDisplay" height="36" left="10" right="36" size="14" textColor="#DFE6E9" top="0" verticalAlign="middle" textColor.disabled="@style:colors:disabled-text" />
|
|
5
5
|
<Label height="36" right="4" size="10" text="▼" textAlign="center" textColor="#636E72" top="0" verticalAlign="middle" width="24" textColor.open="#6C5CE7" />
|
|
6
6
|
<Scroller id="dropDown" height="180" left="0" right="0" top="36" visible="false">
|
|
7
7
|
<List id="list" height="180" width="100%" />
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
2
|
<Skin xmlns="https://kurot.dev/ui/1" class="skins.ItemRendererSkin" states="disabled,down,up" minHeight="50" minWidth="100">
|
|
3
3
|
<Image height="100%" scale9Grid="1,3,8,8" source="button_up_png" width="100%" alpha.disabled="0.5" source.down="button_down_png" />
|
|
4
|
-
<Label id="labelDisplay" bottom="8"
|
|
4
|
+
<Label id="labelDisplay" bottom="8" left="8" right="8" size="20" textAlign="center" textColor="#FFFFFF" top="8" verticalAlign="middle" />
|
|
5
5
|
</Skin>
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<Image bottom="0" left="0" right="0" scale9Grid="2,2,12,12" source="border_png" top="0" />
|
|
4
4
|
<Group id="moveArea" height="45" left="0" right="0" top="0">
|
|
5
5
|
<Image bottom="0" left="0" right="0" scale9Grid="2,2,12,12" source="header_png" top="0" />
|
|
6
|
-
<Label id="titleDisplay"
|
|
6
|
+
<Label id="titleDisplay" left="15" right="5" size="20" textColor="#FFFFFF" verticalCenter="0" wordWrap="false" />
|
|
7
7
|
</Group>
|
|
8
8
|
<Button id="closeButton" bottom="5" horizontalCenter="0" label="close" />
|
|
9
9
|
</Skin>
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
<Skin xmlns="https://kurot.dev/ui/1" class="skins.ProgressBarSkin" minHeight="18" minWidth="30">
|
|
3
3
|
<Image height="100%" scale9Grid="1,1,4,4" source="track_pb_png" verticalCenter="0" width="100%" />
|
|
4
4
|
<Image id="thumb" height="100%" scale9Grid="1,1,4,4" source="thumb_pb_png" width="100%" />
|
|
5
|
-
<Label id="labelDisplay"
|
|
5
|
+
<Label id="labelDisplay" horizontalCenter="0" size="15" textAlign="center" textColor="#707070" verticalAlign="middle" verticalCenter="0" />
|
|
6
6
|
</Skin>
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
<HorizontalLayout verticalAlign="middle" />
|
|
6
6
|
</layout>
|
|
7
7
|
<Image alpha="1" fillMode="scale" source="radiobutton_unselect_png" alpha.disabled="0.5" source.disabledAndSelected="radiobutton_select_disabled_png" alpha.down="0.7" source.downAndSelected="radiobutton_select_down_png" source.upAndSelected="radiobutton_select_up_png" />
|
|
8
|
-
<Label id="labelDisplay"
|
|
8
|
+
<Label id="labelDisplay" size="20" textAlign="center" textColor="#707070" verticalAlign="middle" />
|
|
9
9
|
</Group>
|
|
10
10
|
</Skin>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
2
|
<Skin xmlns="https://kurot.dev/ui/1" class="skins.TextInputSkin" states="disabled,disabledWithPrompt,normal,normalWithPrompt" minHeight="40" minWidth="300">
|
|
3
3
|
<Rect fillColor="#FFFFFF" height="100%" width="100%" alpha.disabled="0.5" />
|
|
4
|
-
<EditableText id="textDisplay" height="24" left="10" right="10" size="20" textColor="#000000" verticalAlign="middle" verticalCenter="0" textColor.disabled="
|
|
4
|
+
<EditableText id="textDisplay" height="24" left="10" right="10" size="20" textColor="#000000" verticalAlign="middle" verticalCenter="0" textColor.disabled="@style:colors:disabled-text" />
|
|
5
5
|
<Label id="promptDisplay" height="24" left="10" multiline="false" right="10" size="20" textColor="#A9A9A9" touchEnabled="false" verticalAlign="middle" verticalCenter="0" visible="false" wordWrap="false" visible.disabledWithPrompt="true" visible.normalWithPrompt="true" />
|
|
6
6
|
</Skin>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
2
|
<Skin xmlns="https://kurot.dev/ui/1" class="skins.ToggleButtonSkin" states="disabled,disabledAndSelected,down,downAndSelected,up,upAndSelected" minHeight="50" minWidth="100">
|
|
3
3
|
<Rect fillColor="#636E72" height="100%" strokeColor="#4A5459" strokeWeight="1" width="100%" fillColor.disabled="#2D3436" fillColor.disabledAndSelected="#2D3436" fillColor.down="#4A5459" fillColor.downAndSelected="#5A4BD1" fillColor.upAndSelected="#6C5CE7" />
|
|
4
|
-
<Label id="labelDisplay" bottom="8" left="8" right="8" size="16" textAlign="center" textColor="#DFE6E9" top="8" verticalAlign="middle" textColor.disabled="
|
|
4
|
+
<Label id="labelDisplay" bottom="8" left="8" right="8" size="16" textAlign="center" textColor="#DFE6E9" top="8" verticalAlign="middle" textColor.disabled="@style:colors:disabled-text" textColor.upAndSelected="#FFFFFF" />
|
|
5
5
|
</Skin>
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* preload 完成后注册项目翻译。URL 的 lang 优先,缺失翻译回退英语,再回退键名。
|
|
3
|
+
* 不监听 UI、不自动重写文本;界面创建时主动调用 getString。
|
|
4
|
+
*/
|
|
5
|
+
export class LocaleManager {
|
|
6
|
+
private static _locales = new Map<string, ReadonlyMap<string, string>>();
|
|
7
|
+
private static _currentLocale = '';
|
|
8
|
+
|
|
9
|
+
public static get currentLocale(): string {
|
|
10
|
+
return this._currentLocale;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 先验证整份配置及语言资源,成功后一起替换,避免加载失败留下半套翻译。
|
|
15
|
+
*/
|
|
16
|
+
public static init(config: unknown, readResource: (name: string) => unknown, requestedLocale = ''): void {
|
|
17
|
+
const locales = new Map<string, ReadonlyMap<string, string>>();
|
|
18
|
+
let defaultLocale = '';
|
|
19
|
+
if (config !== undefined) {
|
|
20
|
+
if (!isRecord(config) || !Array.isArray(config.locale)) {
|
|
21
|
+
throw new Error('locale.json must contain a locale array.');
|
|
22
|
+
}
|
|
23
|
+
for (const entry of config.locale as unknown[]) {
|
|
24
|
+
if (
|
|
25
|
+
!isRecord(entry) ||
|
|
26
|
+
typeof entry.code !== 'string' ||
|
|
27
|
+
!/^[a-z]{2}_[A-Z]{2}$/.test(entry.code) ||
|
|
28
|
+
typeof entry.name !== 'string' ||
|
|
29
|
+
entry.name.trim() === ''
|
|
30
|
+
) {
|
|
31
|
+
throw new Error('Each project language must have a language code and name.');
|
|
32
|
+
}
|
|
33
|
+
if (locales.has(entry.code)) {
|
|
34
|
+
throw new Error(`Duplicate project language: ${entry.code}.`);
|
|
35
|
+
}
|
|
36
|
+
const source = readResource(`lang_${entry.code}_properties`);
|
|
37
|
+
if (typeof source !== 'string') {
|
|
38
|
+
throw new Error(`Language resource is unavailable: ${entry.code}.`);
|
|
39
|
+
}
|
|
40
|
+
locales.set(entry.code, this._parse(source));
|
|
41
|
+
}
|
|
42
|
+
const configuredDefault =
|
|
43
|
+
config.defaultLocale === undefined ? (locales.has('en_US') ? 'en_US' : '') : config.defaultLocale;
|
|
44
|
+
if (
|
|
45
|
+
typeof configuredDefault !== 'string' ||
|
|
46
|
+
(configuredDefault !== '' && !locales.has(configuredDefault))
|
|
47
|
+
) {
|
|
48
|
+
throw new Error('defaultLocale must name an enabled language or be empty.');
|
|
49
|
+
}
|
|
50
|
+
defaultLocale = configuredDefault;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const normalized = requestedLocale.trim().replace(/-/g, '_').toLowerCase();
|
|
54
|
+
const codes = [...locales.keys()];
|
|
55
|
+
const exact = codes.find(code => code.toLowerCase() === normalized);
|
|
56
|
+
const base = normalized.split('_')[0];
|
|
57
|
+
this._currentLocale = exact ?? codes.find(code => code.toLowerCase().split('_')[0] === base) ?? defaultLocale;
|
|
58
|
+
this._locales = locales;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public static getString(key: string, ...args: Array<string | number>): string {
|
|
62
|
+
const text = this._locales.get(this._currentLocale)?.get(key) ?? this._locales.get('en_US')?.get(key) ?? key;
|
|
63
|
+
return text.replace(/\{(\d+)\}/g, (placeholder: string, index: string) => {
|
|
64
|
+
const argument = args[Number(index)];
|
|
65
|
+
return argument === undefined ? placeholder : String(argument);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private static _parse(source: string): ReadonlyMap<string, string> {
|
|
70
|
+
const values = new Map<string, string>();
|
|
71
|
+
for (const line of source.split(/\r?\n/)) {
|
|
72
|
+
const content = line.trim();
|
|
73
|
+
if (!content || content.startsWith('#') || content.startsWith('!')) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const split = line.indexOf('=');
|
|
77
|
+
if (split < 0) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const key = line.slice(0, split).trim();
|
|
81
|
+
if (key) {
|
|
82
|
+
values.set(key, this._decodeValue(line.slice(split + 1).trim()));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return values;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private static _decodeValue(value: string): string {
|
|
89
|
+
return value.replace(/\\(u[0-9a-fA-F]{4}|[nrt\\=: ])/g, (_match: string, escape: string) => {
|
|
90
|
+
if (escape.startsWith('u')) {
|
|
91
|
+
return String.fromCharCode(Number.parseInt(escape.slice(1), 16));
|
|
92
|
+
}
|
|
93
|
+
switch (escape) {
|
|
94
|
+
case 'n':
|
|
95
|
+
return '\n';
|
|
96
|
+
case 'r':
|
|
97
|
+
return '\r';
|
|
98
|
+
case 't':
|
|
99
|
+
return '\t';
|
|
100
|
+
default:
|
|
101
|
+
return escape;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
108
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
109
|
+
}
|
|
@@ -5,15 +5,18 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Lifecycle: constructor → ADDED_TO_STAGE → $onAddToStage → runGame → load → createGameScene → startAnimation
|
|
7
7
|
*/
|
|
8
|
-
import { createPlayer, Event, resource } from '@kurot/core';
|
|
8
|
+
import { createPlayer, Event, resource, TextField } from '@kurot/core';
|
|
9
9
|
import { Button, Label, Rect, Theme, UILayer, setAssetAdapter } from '@kurot/ui';
|
|
10
10
|
import { Tween } from '@kurot/game';
|
|
11
11
|
import { AssetAdapter } from '@/AssetAdapter';
|
|
12
12
|
import { LifecycleHandler } from '@/LifecycleHandler';
|
|
13
13
|
import { Preloader } from '@/Preloader';
|
|
14
|
+
import { LocaleManager } from '@/LocaleManager';
|
|
15
|
+
import { StyleManager } from '@/StyleManager';
|
|
14
16
|
|
|
15
17
|
class Main extends UILayer {
|
|
16
18
|
private readonly _preloader = new Preloader();
|
|
19
|
+
private _description!: Label;
|
|
17
20
|
|
|
18
21
|
createChildren(): void {
|
|
19
22
|
super.createChildren();
|
|
@@ -24,25 +27,25 @@ class Main extends UILayer {
|
|
|
24
27
|
setAssetAdapter(new AssetAdapter());
|
|
25
28
|
LifecycleHandler.init(stage);
|
|
26
29
|
|
|
27
|
-
void this.
|
|
30
|
+
void this._runGame().catch(error => {
|
|
28
31
|
console.error('[Main] Unable to start game:', error);
|
|
29
32
|
});
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
private async
|
|
33
|
-
await this.
|
|
34
|
-
await this.
|
|
35
|
+
private async _runGame(): Promise<void> {
|
|
36
|
+
await this._createPreloader();
|
|
37
|
+
await this._load();
|
|
35
38
|
this._preloader.destroy();
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
39
|
+
this._createGameScene();
|
|
40
|
+
this._startAnimation();
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
private async
|
|
41
|
-
await this.
|
|
43
|
+
private async _load(): Promise<void> {
|
|
44
|
+
await this._updatePreloader('Loading resource configuration...', 1, 2);
|
|
42
45
|
await resource.loadConfig('resource/default.res.json', 'resource/');
|
|
43
46
|
|
|
44
|
-
await this.
|
|
45
|
-
await this.
|
|
47
|
+
await this._updatePreloader('Loading theme...', 2, 2);
|
|
48
|
+
await this._loadTheme();
|
|
46
49
|
|
|
47
50
|
if (resource.hasGroup('preload')) {
|
|
48
51
|
this._preloader.updateText('Loading resources...');
|
|
@@ -50,39 +53,44 @@ class Main extends UILayer {
|
|
|
50
53
|
this._preloader.onProgress(loaded, total);
|
|
51
54
|
});
|
|
52
55
|
}
|
|
56
|
+
|
|
57
|
+
// 翻译依赖 preload 中的文本资源;加载完毕后再创建业务界面。
|
|
58
|
+
LocaleManager.init(
|
|
59
|
+
resource.get('locale_json'),
|
|
60
|
+
name => resource.get(name),
|
|
61
|
+
new URLSearchParams(window.location.search).get('lang') ?? '',
|
|
62
|
+
);
|
|
53
63
|
}
|
|
54
64
|
|
|
55
|
-
private async
|
|
65
|
+
private async _createPreloader(): Promise<void> {
|
|
56
66
|
await this._preloader.init();
|
|
57
67
|
this.addChild(this._preloader);
|
|
58
68
|
}
|
|
59
69
|
|
|
60
|
-
private async
|
|
70
|
+
private async _updatePreloader(message: string, current: number, total: number): Promise<void> {
|
|
61
71
|
this._preloader.updateText(message);
|
|
62
72
|
this._preloader.updateProgress(current, total);
|
|
63
|
-
await this.
|
|
73
|
+
await this._wait(0.1);
|
|
64
74
|
}
|
|
65
75
|
|
|
66
|
-
private async
|
|
76
|
+
private async _loadTheme(): Promise<void> {
|
|
67
77
|
// Load the theme and its default UI skin mappings.
|
|
68
78
|
const theme = new Theme('resource/default.thm.json');
|
|
69
79
|
await new Promise<void>(resolve => theme.addEventListener(Event.COMPLETE, () => resolve()));
|
|
70
80
|
}
|
|
71
81
|
|
|
72
|
-
private
|
|
82
|
+
private _wait(timeout: number): Promise<void> {
|
|
73
83
|
return new Promise<void>(resolve => {
|
|
74
84
|
setTimeout(resolve, timeout * 1000);
|
|
75
85
|
});
|
|
76
86
|
}
|
|
77
87
|
|
|
78
|
-
private textfield!: Label;
|
|
79
|
-
|
|
80
88
|
/**
|
|
81
89
|
* Create the game scene.
|
|
82
90
|
*
|
|
83
91
|
* Build a responsive view with EUI components and constraint-based layout.
|
|
84
92
|
*/
|
|
85
|
-
private
|
|
93
|
+
private _createGameScene(): void {
|
|
86
94
|
// Responsive background
|
|
87
95
|
const sky = new Rect();
|
|
88
96
|
sky.left = 0;
|
|
@@ -111,7 +119,7 @@ class Main extends UILayer {
|
|
|
111
119
|
colorLabel.height = 48;
|
|
112
120
|
colorLabel.textAlign = 'center';
|
|
113
121
|
colorLabel.verticalAlign = 'middle';
|
|
114
|
-
colorLabel.text = '
|
|
122
|
+
colorLabel.text = LocaleManager.getString('label.title');
|
|
115
123
|
colorLabel.size = 36;
|
|
116
124
|
this.addChild(colorLabel);
|
|
117
125
|
|
|
@@ -127,11 +135,11 @@ class Main extends UILayer {
|
|
|
127
135
|
textfield.verticalAlign = 'middle';
|
|
128
136
|
textfield.size = 24;
|
|
129
137
|
textfield.textColor = 0xffffff;
|
|
130
|
-
this.
|
|
138
|
+
this._description = textfield;
|
|
131
139
|
|
|
132
140
|
// UI button using the default theme
|
|
133
141
|
const button = new Button();
|
|
134
|
-
button.label = '
|
|
142
|
+
button.label = LocaleManager.getString('label.button');
|
|
135
143
|
button.horizontalCenter = 0;
|
|
136
144
|
button.top = 200;
|
|
137
145
|
button.width = 200;
|
|
@@ -141,16 +149,20 @@ class Main extends UILayer {
|
|
|
141
149
|
/**
|
|
142
150
|
* Play a looping text fade animation.
|
|
143
151
|
*/
|
|
144
|
-
private
|
|
145
|
-
const texts = [
|
|
152
|
+
private _startAnimation(): void {
|
|
153
|
+
const texts = [
|
|
154
|
+
LocaleManager.getString('label.description.open_source'),
|
|
155
|
+
LocaleManager.getString('label.description.push_forward'),
|
|
156
|
+
LocaleManager.getString('label.description.engine'),
|
|
157
|
+
];
|
|
146
158
|
let count = -1;
|
|
147
159
|
const change = () => {
|
|
148
160
|
count++;
|
|
149
161
|
if (count >= texts.length) {
|
|
150
162
|
count = 0;
|
|
151
163
|
}
|
|
152
|
-
this.
|
|
153
|
-
const tw = Tween.get(this.
|
|
164
|
+
this._description.text = texts[count];
|
|
165
|
+
const tw = Tween.get(this._description);
|
|
154
166
|
tw.to({ alpha: 1 }, 200);
|
|
155
167
|
tw.wait(2000);
|
|
156
168
|
tw.to({ alpha: 0 }, 200);
|
|
@@ -161,12 +173,24 @@ class Main extends UILayer {
|
|
|
161
173
|
}
|
|
162
174
|
|
|
163
175
|
// ── Bootstrap ─────────────────────────────────────────────────────────────
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
176
|
+
async function start(): Promise<void> {
|
|
177
|
+
// 包括 Preloader 在内的所有 Label 首次测量都使用已就绪的项目字体。
|
|
178
|
+
await StyleManager.init();
|
|
179
|
+
TextField.default_fontFamily = StyleManager.fontFamily;
|
|
180
|
+
const canvas = document.getElementById('gameCanvas');
|
|
181
|
+
if (!(canvas instanceof HTMLCanvasElement)) {
|
|
182
|
+
throw new Error('Missing gameCanvas.');
|
|
183
|
+
}
|
|
184
|
+
const app = createPlayer({
|
|
185
|
+
canvas,
|
|
186
|
+
contentWidth: 640,
|
|
187
|
+
contentHeight: 1136,
|
|
188
|
+
scaleMode: 'showAll',
|
|
189
|
+
frameRate: 60,
|
|
190
|
+
});
|
|
191
|
+
app.start(new Main());
|
|
192
|
+
}
|
|
171
193
|
|
|
172
|
-
|
|
194
|
+
void start().catch(error => {
|
|
195
|
+
console.error('[Main] Unable to start project:', error);
|
|
196
|
+
});
|