sapdon 3.0.2 → 3.0.3
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/cli/build.d.ts +7 -0
- package/dist/cli/build.js +234 -0
- package/dist/cli/dev-server/client.d.ts +2 -0
- package/dist/cli/dev-server/client.js +21 -0
- package/dist/cli/dev-server/config.d.ts +3 -0
- package/dist/cli/dev-server/config.js +3 -0
- package/dist/cli/dev-server/handles.d.ts +4 -0
- package/dist/cli/dev-server/handles.js +5 -0
- package/dist/cli/dev-server/hmr.d.ts +1 -0
- package/dist/cli/dev-server/hmr.js +13 -0
- package/dist/cli/dev-server/index.d.ts +4 -0
- package/dist/cli/dev-server/index.js +17 -0
- package/dist/cli/dev-server/server.d.ts +14 -0
- package/dist/cli/dev-server/server.js +59 -0
- package/dist/cli/dev-server/syncFiles.d.ts +3 -0
- package/dist/cli/dev-server/syncFiles.js +37 -0
- package/dist/cli/index.d.ts +23 -0
- package/dist/cli/index.js +1 -0
- package/dist/cli/init.d.ts +9 -0
- package/dist/cli/init.js +80 -0
- package/dist/cli/load.d.ts +3 -0
- package/dist/cli/load.js +94 -0
- package/dist/cli/start.d.ts +2 -0
- package/dist/cli/start.js +2 -0
- package/dist/cli/tools/textureSet.d.ts +13 -0
- package/dist/cli/tools/textureSet.js +103 -0
- package/dist/cli/utils.d.ts +13 -0
- package/dist/cli/utils.js +89 -0
- package/dist/core/addon/biome.d.ts +22 -0
- package/dist/core/addon/biome.js +27 -0
- package/dist/core/addon/block/block.d.ts +41 -0
- package/dist/core/addon/block/block.js +46 -0
- package/dist/core/addon/controllers/animationController.d.ts +43 -0
- package/dist/core/addon/controllers/animationController.js +73 -0
- package/dist/core/addon/entity/clientEntity.d.ts +107 -0
- package/dist/core/addon/entity/clientEntity.js +149 -0
- package/dist/core/addon/entity/entity.d.ts +42 -0
- package/dist/core/addon/entity/entity.js +50 -0
- package/dist/core/addon/feature/oreFeature.d.ts +19 -0
- package/dist/core/addon/feature/oreFeature.js +24 -0
- package/dist/core/addon/featureRule.d.ts +20 -0
- package/dist/core/addon/featureRule.js +25 -0
- package/dist/core/addon/item/attachable.d.ts +94 -0
- package/dist/core/addon/item/attachable.js +134 -0
- package/dist/core/addon/item/item.d.ts +19 -0
- package/dist/core/addon/item/item.js +26 -0
- package/dist/core/addon/manifest.d.ts +49 -0
- package/dist/core/addon/manifest.js +65 -0
- package/dist/core/addon/menuCategory.d.ts +6 -0
- package/dist/core/addon/menuCategory.js +7 -0
- package/dist/core/addon/recipe/baseRecipe.d.ts +12 -0
- package/dist/core/addon/recipe/baseRecipe.js +23 -0
- package/dist/core/addon/recipe/data.d.ts +66 -0
- package/dist/core/addon/recipe/data.js +74 -0
- package/dist/core/addon/recipe/furnace.d.ts +17 -0
- package/dist/core/addon/recipe/furnace.js +43 -0
- package/dist/core/addon/recipe/shaped.d.ts +26 -0
- package/dist/core/addon/recipe/shaped.js +53 -0
- package/dist/core/addon/recipe/shapeless.d.ts +18 -0
- package/dist/core/addon/recipe/shapeless.js +36 -0
- package/dist/core/biome/biome.d.ts +14 -0
- package/dist/core/biome/biome.js +23 -0
- package/dist/core/biome/biomeComponent.d.ts +46 -0
- package/dist/core/biome/biomeComponent.js +77 -0
- package/dist/core/block/basicBlock.d.ts +48 -0
- package/dist/core/block/basicBlock.js +105 -0
- package/dist/core/block/block.d.ts +32 -0
- package/dist/core/block/block.js +92 -0
- package/dist/core/block/blockComponent.d.ts +187 -0
- package/dist/core/block/blockComponent.js +500 -0
- package/dist/core/block/cropBlock.d.ts +4 -0
- package/dist/core/block/cropBlock.js +27 -0
- package/dist/core/block/geometryBlock.d.ts +12 -0
- package/dist/core/block/geometryBlock.js +16 -0
- package/dist/core/block/oreBlock.d.ts +9 -0
- package/dist/core/block/oreBlock.js +25 -0
- package/dist/core/block/rotatableBlock.d.ts +27 -0
- package/dist/core/block/rotatableBlock.js +107 -0
- package/dist/core/block/tileBlock.d.ts +17 -0
- package/dist/core/block/tileBlock.js +125 -0
- package/dist/core/entity/basicEntity.d.ts +111 -0
- package/dist/core/entity/basicEntity.js +170 -0
- package/dist/core/entity/behavior/followMob.d.ts +12 -0
- package/dist/core/entity/behavior/followMob.js +35 -0
- package/dist/core/entity/behavior/followParent.d.ts +7 -0
- package/dist/core/entity/behavior/followParent.js +15 -0
- package/dist/core/entity/behavior/randomStroll.d.ts +31 -0
- package/dist/core/entity/behavior/randomStroll.js +63 -0
- package/dist/core/entity/behavior/tempt.d.ts +73 -0
- package/dist/core/entity/behavior/tempt.js +134 -0
- package/dist/core/entity/bundles/basicBundle.d.ts +13 -0
- package/dist/core/entity/bundles/basicBundle.js +45 -0
- package/dist/core/entity/clientEntity.d.ts +20 -0
- package/dist/core/entity/clientEntity.js +37 -0
- package/dist/core/entity/componets/entityComponet.d.ts +202 -0
- package/dist/core/entity/componets/entityComponet.js +347 -0
- package/dist/core/entity/data/nativeEntityData.d.ts +9 -0
- package/dist/core/entity/data/nativeEntityData.js +38 -0
- package/dist/core/entity/entity.d.ts +15 -0
- package/dist/core/entity/entity.js +18 -0
- package/dist/core/entity/nativeEntity.d.ts +8 -0
- package/dist/core/entity/nativeEntity.js +28 -0
- package/dist/core/entity/navigation/walk.d.ts +23 -0
- package/dist/core/entity/navigation/walk.js +56 -0
- package/dist/core/entity/projectile.d.ts +3 -0
- package/dist/core/entity/projectile.js +7 -0
- package/dist/core/factory/biomeFactory.d.ts +4 -0
- package/dist/core/factory/biomeFactory.js +13 -0
- package/dist/core/factory/blockFactory.d.ts +34 -0
- package/dist/core/factory/blockFactory.js +143 -0
- package/dist/core/factory/entityFactory.d.ts +17 -0
- package/dist/core/factory/entityFactory.js +75 -0
- package/dist/core/factory/featureFactory.d.ts +6 -0
- package/dist/core/factory/featureFactory.js +23 -0
- package/dist/core/factory/itemExtra.d.ts +8 -0
- package/dist/core/factory/itemExtra.js +9 -0
- package/dist/core/factory/itemFactory.d.ts +27 -0
- package/dist/core/factory/itemFactory.js +112 -0
- package/dist/core/factory/recipeFactory.d.ts +18 -0
- package/dist/core/factory/recipeFactory.js +39 -0
- package/dist/core/factory/uiFactory.d.ts +12 -0
- package/dist/core/factory/uiFactory.js +32 -0
- package/dist/core/feature/oreFeature.d.ts +10 -0
- package/dist/core/feature/oreFeature.js +11 -0
- package/dist/core/feature-rule/condition/biomeFilter.d.ts +26 -0
- package/dist/core/feature-rule/condition/biomeFilter.js +36 -0
- package/dist/core/feature-rule/condition/featureConditions.d.ts +27 -0
- package/dist/core/feature-rule/condition/featureConditions.js +37 -0
- package/dist/core/feature-rule/distribution/coordinateDistribution.d.ts +17 -0
- package/dist/core/feature-rule/distribution/coordinateDistribution.js +23 -0
- package/dist/core/feature-rule/distribution/featureDistribution.d.ts +31 -0
- package/dist/core/feature-rule/distribution/featureDistribution.js +41 -0
- package/dist/core/feature-rule/featureRule.d.ts +17 -0
- package/dist/core/feature-rule/featureRule.js +26 -0
- package/dist/core/index.d.ts +2062 -0
- package/dist/core/index.js +1 -0
- package/dist/core/item/armor.d.ts +21 -0
- package/dist/core/item/armor.js +90 -0
- package/dist/core/item/attachable.d.ts +6 -0
- package/dist/core/item/attachable.js +26 -0
- package/dist/core/item/food.d.ts +24 -0
- package/dist/core/item/food.js +38 -0
- package/dist/core/item/item.d.ts +36 -0
- package/dist/core/item/item.js +69 -0
- package/dist/core/item/itemComponents.d.ts +113 -0
- package/dist/core/item/itemComponents.js +225 -0
- package/dist/core/registry.d.ts +12 -0
- package/dist/core/registry.js +16 -0
- package/dist/core/texture.d.ts +18 -0
- package/dist/core/texture.js +38 -0
- package/dist/core/ui/buttonMapping.d.ts +97 -0
- package/dist/core/ui/buttonMapping.js +132 -0
- package/dist/core/ui/dataBindingObject.d.ts +97 -0
- package/dist/core/ui/dataBindingObject.js +134 -0
- package/dist/core/ui/elements/button.d.ts +21 -0
- package/dist/core/ui/elements/button.js +101 -0
- package/dist/core/ui/elements/collectionPanel.d.ts +12 -0
- package/dist/core/ui/elements/collectionPanel.js +53 -0
- package/dist/core/ui/elements/grid.d.ts +8 -0
- package/dist/core/ui/elements/grid.js +33 -0
- package/dist/core/ui/elements/image.d.ts +13 -0
- package/dist/core/ui/elements/image.js +55 -0
- package/dist/core/ui/elements/label.d.ts +14 -0
- package/dist/core/ui/elements/label.js +61 -0
- package/dist/core/ui/elements/panel.d.ts +11 -0
- package/dist/core/ui/elements/panel.js +49 -0
- package/dist/core/ui/elements/scrollingPanel.d.ts +14 -0
- package/dist/core/ui/elements/scrollingPanel.js +59 -0
- package/dist/core/ui/elements/stackPanel.d.ts +14 -0
- package/dist/core/ui/elements/stackPanel.js +37 -0
- package/dist/core/ui/elements/uiElement.d.ts +53 -0
- package/dist/core/ui/elements/uiElement.js +129 -0
- package/dist/core/ui/properties/control.d.ts +214 -0
- package/dist/core/ui/properties/control.js +286 -0
- package/dist/core/ui/properties/dataBinding.d.ts +6 -0
- package/dist/core/ui/properties/dataBinding.js +16 -0
- package/dist/core/ui/properties/factory.d.ts +37 -0
- package/dist/core/ui/properties/factory.js +62 -0
- package/dist/core/ui/properties/gridProp.d.ts +65 -0
- package/dist/core/ui/properties/gridProp.js +90 -0
- package/dist/core/ui/properties/input.d.ts +97 -0
- package/dist/core/ui/properties/input.js +134 -0
- package/dist/core/ui/properties/layout.d.ts +105 -0
- package/dist/core/ui/properties/layout.js +145 -0
- package/dist/core/ui/properties/scrollView.d.ts +105 -0
- package/dist/core/ui/properties/scrollView.js +145 -0
- package/dist/core/ui/properties/sound.d.ts +47 -0
- package/dist/core/ui/properties/sound.js +66 -0
- package/dist/core/ui/properties/sprite.d.ts +161 -0
- package/dist/core/ui/properties/sprite.js +222 -0
- package/dist/core/ui/properties/text.d.ts +135 -0
- package/dist/core/ui/properties/text.js +187 -0
- package/dist/core/ui/registry/uiSystemRegistry.d.ts +8 -0
- package/dist/core/ui/registry/uiSystemRegistry.js +26 -0
- package/dist/core/ui/systems/chest.d.ts +5 -0
- package/dist/core/ui/systems/chest.js +21 -0
- package/dist/core/ui/systems/containerUISystem.d.ts +67 -0
- package/dist/core/ui/systems/containerUISystem.js +214 -0
- package/dist/core/ui/systems/guidebook.d.ts +9 -0
- package/dist/core/ui/systems/guidebook.js +206 -0
- package/dist/core/ui/systems/serverForm.d.ts +13 -0
- package/dist/core/ui/systems/serverForm.js +116 -0
- package/dist/core/ui/systems/system.d.ts +16 -0
- package/dist/core/ui/systems/system.js +37 -0
- package/dist/oc/index.d.ts +142 -0
- package/dist/oc/index.js +1 -0
- package/doc/sapdon-ts.md +35 -1
- package/package.json +6 -8
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { ButtonMapping } from "../buttonMapping.js";
|
|
2
|
+
import { DataBindingObject } from "../dataBindingObject.js";
|
|
3
|
+
import { Button } from "../elements/button.js";
|
|
4
|
+
import { Image } from "../elements/image.js";
|
|
5
|
+
import { Label } from "../elements/label.js";
|
|
6
|
+
import { Panel } from "../elements/panel.js";
|
|
7
|
+
import { StackPanel } from "../elements/stackPanel.js";
|
|
8
|
+
import { UIElement } from "../elements/uiElement.js";
|
|
9
|
+
import { Control } from "../properties/control.js";
|
|
10
|
+
import { Input } from "../properties/input.js";
|
|
11
|
+
import { Layout } from "../properties/layout.js";
|
|
12
|
+
import { Sprite } from "../properties/sprite.js";
|
|
13
|
+
import { Text } from "../properties/text.js";
|
|
14
|
+
import { ServerUISystem } from "./serverForm.js";
|
|
15
|
+
import { UISystem } from "./system.js";
|
|
16
|
+
//表单按钮模板
|
|
17
|
+
const form_button_template = new Button("form_button_template", "common.button");
|
|
18
|
+
form_button_template.addVariable("default_texture|default", "");
|
|
19
|
+
form_button_template.addVariable("hover_texture|default", "");
|
|
20
|
+
form_button_template.addVariable("pressed_texture|default", "");
|
|
21
|
+
form_button_template.addVariable("binding_button_text|default", "");
|
|
22
|
+
form_button_template.dataBinding.addDataBinding(new DataBindingObject().setBindingType("collection_details")
|
|
23
|
+
.setBindingCollectionName("form_buttons"));
|
|
24
|
+
form_button_template.dataBinding.addDataBinding(new DataBindingObject().setBindingType("collection")
|
|
25
|
+
.setBindingCollectionName("form_buttons")
|
|
26
|
+
.setBindingName("#form_button_text"));
|
|
27
|
+
form_button_template.dataBinding.addDataBinding(new DataBindingObject().setBindingType("view")
|
|
28
|
+
.setSourcePropertyName("($binding_button_text = #form_button_text)")
|
|
29
|
+
.setTargetPropertyName("#visible"));
|
|
30
|
+
form_button_template.addControls([
|
|
31
|
+
new Image("default").setSprite(new Sprite().setTexture("$default_texture")),
|
|
32
|
+
new Image("hover").setSprite(new Sprite().setTexture("$hover_texture")),
|
|
33
|
+
new Image("pressed").setSprite(new Sprite().setTexture("$pressed_texture"))
|
|
34
|
+
]);
|
|
35
|
+
//f
|
|
36
|
+
const form_button_panel = new Panel("form_button_factory").enableDebug();
|
|
37
|
+
form_button_panel.addProp("type", "collection_panel");
|
|
38
|
+
form_button_panel.factory.setName("buttons").setControlName("$button_control");
|
|
39
|
+
form_button_panel.addProp("collection_name", "form_buttons");
|
|
40
|
+
form_button_panel.dataBinding.addDataBinding(new DataBindingObject().setBindingName("#form_button_length")
|
|
41
|
+
.setBindingNameOverride("#collection_length"));
|
|
42
|
+
const page_template = new StackPanel("page_template").setOrientation("horizontal")
|
|
43
|
+
.addVariable("page_left_content | default", "")
|
|
44
|
+
.addVariable("page_right_content | default", "")
|
|
45
|
+
.setLayout(new Layout().setSize(["90%", "90%"]))
|
|
46
|
+
.addStack(["50%", "100%"], new UIElement("page_left", undefined, "$page_left_content").serialize())
|
|
47
|
+
.addStack(["50%", "100%"], new UIElement("page_right", undefined, "$page_right_content").serialize());
|
|
48
|
+
page_template.dataBinding.addDataBinding(new DataBindingObject().setBindingType("view")
|
|
49
|
+
.setSourcePropertyName("($binding_text = #form_text)")
|
|
50
|
+
.setTargetPropertyName("#visible"));
|
|
51
|
+
export class Guidebook {
|
|
52
|
+
#bindingList = [];
|
|
53
|
+
constructor(identifier, path) {
|
|
54
|
+
this.system = new UISystem(identifier, path);
|
|
55
|
+
//init
|
|
56
|
+
this.#binding();
|
|
57
|
+
this.#addTemplate();
|
|
58
|
+
this.#updateSystem();
|
|
59
|
+
}
|
|
60
|
+
addPageBinding(page_name, left_control_name, right_control_name) {
|
|
61
|
+
this.#bindingList.push({
|
|
62
|
+
page_name: page_name,
|
|
63
|
+
left_control_name: left_control_name,
|
|
64
|
+
right_control_name: right_control_name
|
|
65
|
+
});
|
|
66
|
+
//更新系统
|
|
67
|
+
this.#updateSystem();
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
addPage(page_name, left_control, right_control) {
|
|
71
|
+
this.addPageBinding(page_name, left_control.name, right_control.name);
|
|
72
|
+
//添加元素
|
|
73
|
+
this.addElement(left_control);
|
|
74
|
+
this.addElement(right_control);
|
|
75
|
+
//更新系统
|
|
76
|
+
this.#updateSystem();
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
addElement(element) {
|
|
80
|
+
this.system.addElement(element);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
#binding() {
|
|
84
|
+
ServerUISystem.bindingTitlewithContent(this.system.name, `${this.system.namespace}.guidebook_root_panel`);
|
|
85
|
+
}
|
|
86
|
+
#addTemplate() {
|
|
87
|
+
this.addElement(form_button_template);
|
|
88
|
+
this.addElement(form_button_panel);
|
|
89
|
+
this.addElement(page_template);
|
|
90
|
+
//
|
|
91
|
+
this.#updateSystem();
|
|
92
|
+
}
|
|
93
|
+
#updateSystem() {
|
|
94
|
+
const guidebook_root_panel = new Panel("guidebook_root_panel");
|
|
95
|
+
//开启调试框
|
|
96
|
+
//guidebook_root_panel.enableDebug()
|
|
97
|
+
//设置布局属性
|
|
98
|
+
guidebook_root_panel.setLayout(new Layout().setSize([320, 207]));
|
|
99
|
+
//添加子元素
|
|
100
|
+
guidebook_root_panel.addControls([
|
|
101
|
+
//添加背景
|
|
102
|
+
new UIElement("book_background", undefined, "book.book_background"),
|
|
103
|
+
//添加书页
|
|
104
|
+
new StackPanel("book_page_stack_panel").setOrientation("horizontal")
|
|
105
|
+
.setLayout(new Layout().setSize([320, 207]))
|
|
106
|
+
.addVariable("page_size", [160, 207])
|
|
107
|
+
.addStack("$page_size", new Panel("book_left_panel").addControls([
|
|
108
|
+
{
|
|
109
|
+
"page_crease_image@book.page_crease_left_image": {
|
|
110
|
+
"size": ["100% - 40px", "100% - 14px"],
|
|
111
|
+
"offset": [0, -2]
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"page_edge_image@book.page_edge_left_image": {
|
|
116
|
+
"size": ["100% - 7px", "100% - 16px"],
|
|
117
|
+
"offset": [7, -1]
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
]).serialize())
|
|
121
|
+
.addStack("$page_size", new Panel("book_right_panel").addControls([
|
|
122
|
+
{
|
|
123
|
+
"page_crease_image@book.page_crease_right_image": {
|
|
124
|
+
"size": ["100% - 40px", "100% - 14px"],
|
|
125
|
+
"offset": [0, -2]
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"page_edge_image@book.page_edge_right_image": {
|
|
130
|
+
"size": ["100% - 7px", "100% - 16px"],
|
|
131
|
+
"offset": [-7, -1]
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
]).serialize()),
|
|
135
|
+
//添加书页内容
|
|
136
|
+
new Panel("page_content_root")
|
|
137
|
+
.setControl(new Control().setLayer(5))
|
|
138
|
+
.setLayout(new Layout().setSize(["90%", "90%"]))
|
|
139
|
+
.addControls([
|
|
140
|
+
new Panel("label_text_panel").setLayout(new Layout().setSize([32, 8]).setAnchorFrom("bottom_middle")
|
|
141
|
+
.setAnchorTo("bottom_middle")).addControl(new Label("page_content").setText(new Text().setText("#form_text").setColor([0, 0, 0]))),
|
|
142
|
+
...this.#bindingList.map(({ page_name, left_control_name, right_control_name }, index) => {
|
|
143
|
+
return new UIElement(`page_index_${index}`, undefined, "page_template")
|
|
144
|
+
.addVariable("binding_text", page_name)
|
|
145
|
+
.addVariable("page_left_content", left_control_name)
|
|
146
|
+
.addVariable("page_right_content", right_control_name);
|
|
147
|
+
})
|
|
148
|
+
/*
|
|
149
|
+
new UIElement("page_1",undefined,"page_template")
|
|
150
|
+
.addVariable("binding_text","page_index1")
|
|
151
|
+
.addVariable("page_left_content","page_left_content")
|
|
152
|
+
.addVariable("page_right_content","page_right_content"),
|
|
153
|
+
new UIElement("page_2",undefined,"page_template")
|
|
154
|
+
.addVariable("binding_text","page_index2")
|
|
155
|
+
.addVariable("page_left_content","page_left_content")
|
|
156
|
+
.addVariable("page_right_content","page_right_content"),
|
|
157
|
+
new UIElement("page_3",undefined,"page_template")
|
|
158
|
+
.addVariable("binding_text","page_index3")
|
|
159
|
+
.addVariable("page_left_content","page_left_content")
|
|
160
|
+
.addVariable("page_right_content","page_right_content")*/
|
|
161
|
+
]),
|
|
162
|
+
//添加关闭按钮
|
|
163
|
+
new Button("close_button").setLayout(new Layout().setSize([14, 14])
|
|
164
|
+
.setAnchorFrom("top_right")
|
|
165
|
+
.setAnchorTo("top_right"))
|
|
166
|
+
.setInput(new Input().setButtonMappings([
|
|
167
|
+
new ButtonMapping().setMappingType("pressed")
|
|
168
|
+
.setFromButtonId("button.menu_select")
|
|
169
|
+
.setToButtonId("button.menu_exit")
|
|
170
|
+
]))
|
|
171
|
+
.addControls([
|
|
172
|
+
new UIElement("default", undefined, "book.close_button_default"),
|
|
173
|
+
new UIElement("hover", undefined, "book.close_button_hover"),
|
|
174
|
+
new UIElement("pressed", undefined, "book.close_button_pressed"),
|
|
175
|
+
]),
|
|
176
|
+
//添加下一页按钮
|
|
177
|
+
new Panel("prev_button_panel").enableDebug()
|
|
178
|
+
.setControl(new Control().setLayer(5))
|
|
179
|
+
.setLayout(new Layout().setSize([24, 24])
|
|
180
|
+
.setOffset([7, -9])
|
|
181
|
+
.setAnchorFrom("bottom_left")
|
|
182
|
+
.setAnchorTo("bottom_left"))
|
|
183
|
+
.addControl(new UIElement("prev_button", undefined, "form_button_factory")
|
|
184
|
+
.addVariable("binding_button_text", "test1")
|
|
185
|
+
.addVariable("button_control", `${this.system.namespace}.form_button_template`)
|
|
186
|
+
.addVariable("pressed_button_name", "button.form_button_click")
|
|
187
|
+
.addVariable("default_texture", "textures/ui/book_pageleft_default")
|
|
188
|
+
.addVariable("hover_texture", "textures/ui/book_pageleft_hover")
|
|
189
|
+
.addVariable("pressed_texture", "textures/ui/book_pageleft_pressed")),
|
|
190
|
+
new Panel("next_button_panel").enableDebug()
|
|
191
|
+
.setControl(new Control().setLayer(5))
|
|
192
|
+
.setLayout(new Layout().setSize([24, 24])
|
|
193
|
+
.setOffset([-7, -9])
|
|
194
|
+
.setAnchorFrom("bottom_right")
|
|
195
|
+
.setAnchorTo("bottom_right"))
|
|
196
|
+
.addControl(new UIElement("next_button", undefined, "form_button_factory")
|
|
197
|
+
.addVariable("binding_button_text", "test2")
|
|
198
|
+
.addVariable("button_control", "sapdon_guidebook.form_button_template")
|
|
199
|
+
.addVariable("pressed_button_name", "button.form_button_click")
|
|
200
|
+
.addVariable("default_texture", "textures/ui/book_pageright_default")
|
|
201
|
+
.addVariable("hover_texture", "textures/ui/book_pageright_hover")
|
|
202
|
+
.addVariable("pressed_texture", "textures/ui/book_pageright_pressed"))
|
|
203
|
+
]);
|
|
204
|
+
this.addElement(guidebook_root_panel);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const ServerFormSystem: UISystem;
|
|
2
|
+
export const form_button_panel: Panel;
|
|
3
|
+
export class ServerUISystem {
|
|
4
|
+
static "__#4@#binding_map": Map<any, any>;
|
|
5
|
+
static "__#4@#binding_title_list": any[];
|
|
6
|
+
static addBindingTitle(title_name: any): void;
|
|
7
|
+
static getBindingTitleList(): any[];
|
|
8
|
+
static getBindingContentList(): any[];
|
|
9
|
+
static bindingTitlewithContent(title_name: any, content: any): void;
|
|
10
|
+
static "__#4@#updateServerFormSystem"(): void;
|
|
11
|
+
}
|
|
12
|
+
import { UISystem } from "./system.js";
|
|
13
|
+
import { Panel } from "../elements/panel.js";
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Modifications, UIElement } from "../elements/uiElement.js";
|
|
2
|
+
import { DataBindingObject } from "../dataBindingObject.js";
|
|
3
|
+
import { UISystem } from "./system.js";
|
|
4
|
+
import { Panel } from "../elements/panel.js";
|
|
5
|
+
import { Button } from "../elements/button.js";
|
|
6
|
+
import { Image } from "../elements/image.js";
|
|
7
|
+
import { Sprite } from "../properties/sprite.js";
|
|
8
|
+
export const ServerFormSystem = new UISystem("server_form:server_form", "ui/");
|
|
9
|
+
//表单按钮模板
|
|
10
|
+
const form_button_template = new Button("sapdon_form_button_template", "common.button");
|
|
11
|
+
form_button_template.addVariable("pressed_button_name", "button.form_button_click");
|
|
12
|
+
form_button_template.addVariable("default_texture|default", "textures/gui/newgui/buttons/borderless/light");
|
|
13
|
+
form_button_template.addVariable("hover_texture|default", "textures/gui/newgui/buttons/borderless/lighthover");
|
|
14
|
+
form_button_template.addVariable("pressed_texture|default", "textures/gui/newgui/buttons/borderless/lightpressed");
|
|
15
|
+
form_button_template.addVariable("binding_button_text|default", "");
|
|
16
|
+
form_button_template.dataBinding.addDataBinding(new DataBindingObject().setBindingType("collection_details")
|
|
17
|
+
.setBindingCollectionName("form_buttons"));
|
|
18
|
+
form_button_template.dataBinding.addDataBinding(new DataBindingObject().setBindingType("collection")
|
|
19
|
+
.setBindingCollectionName("form_buttons")
|
|
20
|
+
.setBindingName("#form_button_text"));
|
|
21
|
+
form_button_template.dataBinding.addDataBinding(new DataBindingObject().setBindingType("view")
|
|
22
|
+
.setSourcePropertyName("($binding_button_text = #form_button_text)")
|
|
23
|
+
.setTargetPropertyName("#visible"));
|
|
24
|
+
form_button_template.addControls([
|
|
25
|
+
new Image("default").setSprite(new Sprite().setTexture("$default_texture")),
|
|
26
|
+
new Image("hover").setSprite(new Sprite().setTexture("$hover_texture")),
|
|
27
|
+
new Image("pressed").setSprite(new Sprite().setTexture("$pressed_texture"))
|
|
28
|
+
]);
|
|
29
|
+
//f
|
|
30
|
+
export const form_button_panel = new Panel("sapdon_form_button_factory");
|
|
31
|
+
form_button_panel.addProp("type", "collection_panel");
|
|
32
|
+
form_button_panel.factory.setName("buttons").setControlName("sapdon_form_button_template");
|
|
33
|
+
form_button_panel.addProp("collection_name", "form_buttons");
|
|
34
|
+
form_button_panel.dataBinding.addDataBinding(new DataBindingObject().setBindingName("#form_button_length")
|
|
35
|
+
.setBindingNameOverride("#collection_length"));
|
|
36
|
+
ServerFormSystem.addElement(form_button_template);
|
|
37
|
+
ServerFormSystem.addElement(form_button_panel);
|
|
38
|
+
export class ServerUISystem {
|
|
39
|
+
static #binding_map = new Map();
|
|
40
|
+
static #binding_title_list = [];
|
|
41
|
+
static addBindingTitle(title_name) {
|
|
42
|
+
this.#binding_title_list.push(title_name);
|
|
43
|
+
}
|
|
44
|
+
static getBindingTitleList() {
|
|
45
|
+
//console.log("arrr:",Array.from(this.#binding_map.keys()))
|
|
46
|
+
return this.#binding_title_list.concat(Array.from(this.#binding_map.keys()));
|
|
47
|
+
}
|
|
48
|
+
static getBindingContentList() {
|
|
49
|
+
return Array.from(this.#binding_map.values());
|
|
50
|
+
}
|
|
51
|
+
static bindingTitlewithContent(title_name, content) {
|
|
52
|
+
//添加绑定
|
|
53
|
+
this.#binding_map.set(title_name, content);
|
|
54
|
+
this.#updateServerFormSystem();
|
|
55
|
+
}
|
|
56
|
+
static #updateServerFormSystem() {
|
|
57
|
+
//文本化处理
|
|
58
|
+
//console.log("ttttt:",this.getBindingTitleList())
|
|
59
|
+
const user_custom_ui_text = this.getBindingTitleList().map((title_name) => {
|
|
60
|
+
console.log("title_name", title_name);
|
|
61
|
+
return `'${title_name}'`;
|
|
62
|
+
}).join('-');
|
|
63
|
+
const long_form = new UIElement("long_form")
|
|
64
|
+
.addModification({
|
|
65
|
+
array_name: "bindings",
|
|
66
|
+
operation: Modifications.OPERATION.INSERT_BACK,
|
|
67
|
+
value: [
|
|
68
|
+
new DataBindingObject().setBindingName("#title_text"),
|
|
69
|
+
new DataBindingObject().setBindingType("view")
|
|
70
|
+
.setSourcePropertyName(`((#title_text - ${user_custom_ui_text}) = #title_text)`)
|
|
71
|
+
.setTargetPropertyName("#visible")
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
const custom_server_form_factory = new Panel("custom_server_form_factory");
|
|
75
|
+
custom_server_form_factory.factory.setName("server_form_factory") //工程名被绑定至表单,不可改动
|
|
76
|
+
.setControlIds({ "long_form": "@server_form.custom_root_panel" });
|
|
77
|
+
//加入自定义表单内容
|
|
78
|
+
const main_screen_content = new UIElement("main_screen_content")
|
|
79
|
+
.addModification({
|
|
80
|
+
array_name: "controls",
|
|
81
|
+
operation: Modifications.OPERATION.INSERT_BACK,
|
|
82
|
+
value: [
|
|
83
|
+
custom_server_form_factory.serialize()
|
|
84
|
+
]
|
|
85
|
+
});
|
|
86
|
+
//自定义ui模板
|
|
87
|
+
const custom_ui_template = new Panel("custom_ui_template");
|
|
88
|
+
custom_ui_template.dataBinding.addDataBinding(new DataBindingObject().setBindingName("#title_text")).addDataBinding(new DataBindingObject().setBindingType("view")
|
|
89
|
+
.setSourcePropertyName("(#title_text = $binding_text)")
|
|
90
|
+
.setTargetPropertyName("#visible"));
|
|
91
|
+
custom_ui_template.control.addControl(new UIElement("main", undefined, "$main_content").serialize());
|
|
92
|
+
//类似于 root ,决定什么时候加载自定义界面 ,不可改动
|
|
93
|
+
const custom_form_root = new Panel("custom_form_root");
|
|
94
|
+
//custom_form_root.addVariable("title_needs_to_contain",user_custom_ui_text)
|
|
95
|
+
custom_form_root.dataBinding.addDataBinding(new DataBindingObject().setBindingType("view")
|
|
96
|
+
.setSourceControlName("custom_root_panel")
|
|
97
|
+
.setSourcePropertyName(`(not ((#title_text - ${user_custom_ui_text}) = #title_text))`)
|
|
98
|
+
.setTargetPropertyName("#visible"));
|
|
99
|
+
//用户自定义ui内容绑定
|
|
100
|
+
this.#binding_map.forEach((content, key) => {
|
|
101
|
+
//加入 root
|
|
102
|
+
custom_form_root.control.addControl(new UIElement("custom_ui_" + key, undefined, "custom_ui_template")
|
|
103
|
+
.addVariable("main_content", content)
|
|
104
|
+
.addVariable("binding_text", key).serialize());
|
|
105
|
+
});
|
|
106
|
+
//类似于 sreen,必要,不可改动
|
|
107
|
+
const custom_root_panel = new Panel("custom_root_panel");
|
|
108
|
+
custom_root_panel.dataBinding.addDataBinding(new DataBindingObject().setBindingName("#title_text"));
|
|
109
|
+
custom_root_panel.control.addControl(custom_form_root.serialize());
|
|
110
|
+
ServerFormSystem
|
|
111
|
+
.addElement(custom_ui_template)
|
|
112
|
+
.addElement(long_form)
|
|
113
|
+
.addElement(custom_root_panel)
|
|
114
|
+
.addElement(main_screen_content);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class UISystem {
|
|
2
|
+
constructor(identifier: any, path: any);
|
|
3
|
+
identifier: any;
|
|
4
|
+
namespace: any;
|
|
5
|
+
name: any;
|
|
6
|
+
path: any;
|
|
7
|
+
elements: Map<any, any>;
|
|
8
|
+
animations: Map<any, any>;
|
|
9
|
+
addElement(element: any): this;
|
|
10
|
+
getElement(element_name: any): any;
|
|
11
|
+
addAnimation(name: any, value: any): void;
|
|
12
|
+
getAnimation(animation_name: any): any;
|
|
13
|
+
toJson(): {
|
|
14
|
+
namespace: any;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { UISystemRegistry } from "../registry/uiSystemRegistry.js";
|
|
2
|
+
// UI 文件核心类
|
|
3
|
+
export class UISystem {
|
|
4
|
+
constructor(identifier, path) {
|
|
5
|
+
this.identifier = identifier;
|
|
6
|
+
this.namespace = identifier.split(':')[0];
|
|
7
|
+
this.name = identifier.split(':')[1];
|
|
8
|
+
this.path = path;
|
|
9
|
+
this.elements = new Map();
|
|
10
|
+
this.animations = new Map();
|
|
11
|
+
UISystemRegistry.registerUISystem(this);
|
|
12
|
+
}
|
|
13
|
+
addElement(element) {
|
|
14
|
+
this.elements.set(element.id, element);
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
getElement(element_name) {
|
|
18
|
+
return this.elements.get(element_name);
|
|
19
|
+
}
|
|
20
|
+
addAnimation(name, value) {
|
|
21
|
+
this.animations.set(name, value);
|
|
22
|
+
}
|
|
23
|
+
getAnimation(animation_name) {
|
|
24
|
+
return this.animations.get(animation_name);
|
|
25
|
+
}
|
|
26
|
+
toJson() {
|
|
27
|
+
const ui = { namespace: this.namespace };
|
|
28
|
+
//序列化
|
|
29
|
+
this.elements.forEach((value, key) => {
|
|
30
|
+
//console.log("elements key:",key)
|
|
31
|
+
//console.log("elements value:",value);
|
|
32
|
+
ui[key] = value.serialize()[value.id];
|
|
33
|
+
});
|
|
34
|
+
//console.log("ui:",ui)
|
|
35
|
+
return ui;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import * as _minecraft_server from '@minecraft/server';
|
|
2
|
+
import { Entity, Player, InputButton } from '@minecraft/server';
|
|
3
|
+
|
|
4
|
+
declare class Optional<T = any> {
|
|
5
|
+
private value;
|
|
6
|
+
static none<T>(): Optional<T>;
|
|
7
|
+
static some<T>(value: T): Optional<T>;
|
|
8
|
+
constructor(value: T);
|
|
9
|
+
unwrap(): T;
|
|
10
|
+
isEmpty(): boolean;
|
|
11
|
+
orElse(other: T): T;
|
|
12
|
+
use(fn: (v: T) => void, self?: any): boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface Component {
|
|
16
|
+
onTick(manager: ComponentManager, en: Optional<Entity>): void;
|
|
17
|
+
detach(manager: ComponentManager): void;
|
|
18
|
+
getManager(): ComponentManager;
|
|
19
|
+
getEntity(): Optional<Entity>;
|
|
20
|
+
}
|
|
21
|
+
interface BasicComponent extends Component {
|
|
22
|
+
onAttach(manager: ComponentManager): boolean | void | Promise<boolean | void>;
|
|
23
|
+
onDetach(manager: ComponentManager): void | Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
declare const REFLECT_MANAGER: unique symbol;
|
|
26
|
+
declare const REFLECT_ENTITY: unique symbol;
|
|
27
|
+
declare class CustomComponent implements Component {
|
|
28
|
+
[REFLECT_MANAGER]?: ComponentManager;
|
|
29
|
+
[REFLECT_ENTITY]: Optional<Entity>;
|
|
30
|
+
onTick(manager: ComponentManager, en: Optional<Entity>): void;
|
|
31
|
+
detach(manager: ComponentManager): Promise<boolean>;
|
|
32
|
+
getManager(): ComponentManager;
|
|
33
|
+
getEntity(): Optional<Entity>;
|
|
34
|
+
}
|
|
35
|
+
declare class BaseComponent extends CustomComponent implements BasicComponent {
|
|
36
|
+
onAttach(manager: ComponentManager): boolean | void | Promise<boolean | void>;
|
|
37
|
+
onDetach(manager: ComponentManager): void | Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
interface ComponentCtor<T extends Component | BasicComponent = Component> {
|
|
40
|
+
new (...args: any[]): T;
|
|
41
|
+
}
|
|
42
|
+
declare class ComponentManager {
|
|
43
|
+
#private;
|
|
44
|
+
static profilerEnable: boolean;
|
|
45
|
+
static readonly global: ComponentManager;
|
|
46
|
+
getComponentUnsafe(ctor: ComponentCtor): Component | undefined;
|
|
47
|
+
getComponent<T extends Component>(ctor: ComponentCtor<T>): Optional<T>;
|
|
48
|
+
getComponents(...ctor: ComponentCtor[]): (Component | undefined)[];
|
|
49
|
+
attachComponent(...component: Component[]): Promise<Optional<Component>[]>;
|
|
50
|
+
getOrCreate<T extends Component>(ctor: ComponentCtor<T>, ...args: any[]): Promise<Optional<T>>;
|
|
51
|
+
detachComponent(ctor: ComponentCtor): Promise<boolean>;
|
|
52
|
+
clear(): void;
|
|
53
|
+
getComponentKeys(): MapIterator<ComponentCtor<Component>>;
|
|
54
|
+
has(ctor: ComponentCtor): boolean;
|
|
55
|
+
afterTick(fn: (en: Optional<Entity>) => void): void;
|
|
56
|
+
beforeTick(fn: (en: Optional<Entity>) => void): void;
|
|
57
|
+
handleTicks(en: Entity): void;
|
|
58
|
+
update<T extends Component>(ctor: ComponentCtor<T>, fn: (component: T) => void): boolean;
|
|
59
|
+
profiler(fn: Function, component?: Component, name?: string): any;
|
|
60
|
+
}
|
|
61
|
+
type RequireComponentsParam = ComponentCtor | [ComponentCtor, ...any[]];
|
|
62
|
+
declare const REQUIRED_COMPONENTS: unique symbol;
|
|
63
|
+
interface RequiredComponent extends BasicComponent {
|
|
64
|
+
getComponent<T extends Component>(ctor: ComponentCtor): T;
|
|
65
|
+
}
|
|
66
|
+
declare function RequireComponents(...params: RequireComponentsParam[]): {
|
|
67
|
+
new (): {
|
|
68
|
+
getComponent<T extends Component>(ctor: ComponentCtor): T;
|
|
69
|
+
[REQUIRED_COMPONENTS]: Map<ComponentCtor<Component>, Component>;
|
|
70
|
+
onAttach(manager: ComponentManager): boolean | void | Promise<boolean | void>;
|
|
71
|
+
onDetach(manager: ComponentManager): void | Promise<void>;
|
|
72
|
+
onTick(manager: ComponentManager, en: Optional<Entity>): void;
|
|
73
|
+
detach(manager: ComponentManager): Promise<boolean>;
|
|
74
|
+
getManager(): ComponentManager;
|
|
75
|
+
getEntity(): Optional<Entity>;
|
|
76
|
+
[REFLECT_MANAGER]?: ComponentManager;
|
|
77
|
+
[REFLECT_ENTITY]: Optional<Entity>;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
declare namespace oc {
|
|
81
|
+
function addEntity(entityId: string): ComponentManager;
|
|
82
|
+
function removeEntity(entityId: string): void;
|
|
83
|
+
function getManager(entityId: string): ComponentManager;
|
|
84
|
+
function tick(): void;
|
|
85
|
+
function start(): void;
|
|
86
|
+
function toPlayer(entity: Entity): Optional<Player>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
type ComponentDescriptor = string | ComponentCtor;
|
|
90
|
+
declare class Actor {
|
|
91
|
+
readonly target: Entity;
|
|
92
|
+
readonly manager: ComponentManager;
|
|
93
|
+
constructor(target: Entity, manager: ComponentManager);
|
|
94
|
+
static from(target: Entity, manager: ComponentManager): Actor;
|
|
95
|
+
/**
|
|
96
|
+
* 优先使用 `Actor.getComponent`
|
|
97
|
+
* @param ctors
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
getMinecraftComponent(...ids: string[]): (_minecraft_server.EntityComponent | undefined)[];
|
|
101
|
+
/**
|
|
102
|
+
* 优先使用 `Actor.getComponent`
|
|
103
|
+
* @param ctors
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
getCustomComponent(...ctors: ComponentCtor[]): (Component | undefined)[];
|
|
107
|
+
getComponent<T extends readonly ComponentDescriptor[] | []>(...descs: T): {
|
|
108
|
+
-readonly [K in keyof T]: Component;
|
|
109
|
+
};
|
|
110
|
+
addComponent(...components: Component[]): Promise<Optional<Component>[]>;
|
|
111
|
+
removeComponent(ctor: ComponentCtor): Promise<boolean>;
|
|
112
|
+
updateComponent<T extends Component>(ctor: ComponentCtor<T>, fn: (component: T) => void): boolean;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
declare enum InputChangeState {
|
|
116
|
+
Press = 0,
|
|
117
|
+
Release = 1,
|
|
118
|
+
None = 2
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* `@minecraft/server` version 2.0.0-beta
|
|
122
|
+
* 低于此版本请不要使用此组件
|
|
123
|
+
*/
|
|
124
|
+
declare class PlayerInputComponent extends BaseComponent {
|
|
125
|
+
[InputButton.Jump]: InputChangeState;
|
|
126
|
+
[InputButton.Sneak]: InputChangeState;
|
|
127
|
+
static setup(): void;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* `@minecraft/server` version 1.17.0-beta
|
|
131
|
+
* 有 1tick 延迟
|
|
132
|
+
* 条件允许请使用 `PlayerInputComponent`
|
|
133
|
+
*/
|
|
134
|
+
declare class PlayerInputCompatibilityComponent extends BaseComponent {
|
|
135
|
+
[InputButton.Jump]: InputChangeState;
|
|
136
|
+
[InputButton.Sneak]: InputChangeState;
|
|
137
|
+
private _lastJump;
|
|
138
|
+
private _lastSneak;
|
|
139
|
+
onTick(manager: ComponentManager, en: Optional<Entity>): void;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { Actor, BaseComponent, type BasicComponent, type Component, type ComponentCtor, type ComponentDescriptor, ComponentManager, CustomComponent, InputChangeState, Optional, PlayerInputCompatibilityComponent, PlayerInputComponent, RequireComponents, type RequiredComponent, oc };
|
package/dist/oc/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{world as t,system as e,InputButton as n,ButtonState as s}from"@minecraft/server";class o{target;manager;constructor(t,e){this.target=t,this.manager=e}static from(t,e){return new o(t,e)}getMinecraftComponent(...t){return t.map((t=>this.target.getComponent(t)))}getCustomComponent(...t){return this.manager.getComponents(...t)}getComponent(...t){return t.map((t=>"string"==typeof t?this.target.getComponent(t):this.manager.getComponentUnsafe(t)))}addComponent(...t){return this.manager.attachComponent(...t)}removeComponent(t){return this.manager.detachComponent(t)}updateComponent(t,e){return this.manager.update(t,e)}}class r{value;static none(){return new r(null)}static some(t){return new r(t)}constructor(t){this.value=t}unwrap(){if(!this.isEmpty())return this.value;throw new Error("Optional is empty")}isEmpty(){return void 0===this.value||null===this.value}orElse(t){return this.value??t}use(t,e){return!this.isEmpty()&&(t.call(e,this.value),!0)}}const a=Symbol("reflect-manager"),i=Symbol("reflect-entity");class c{[a];[i]=r.none();onTick(t,e){}detach(t){const e=Object.getPrototypeOf(this).constructor;return t.detachComponent(e)}getManager(){return this[a]}getEntity(){return this[i]}}class p extends c{onAttach(t){}onDetach(t){}}class u{static profilerEnable=!1;static global=new u;#t=new Map;#e=[];#n=[];getComponentUnsafe(t){return this.#t.get(t)}getComponent(t){return r.some(this.#t.get(t))}getComponents(...t){return t.map((t=>this.#t.get(t)))}async#s(t,e,n=!0){let s=!this.#t.get(t);if(!s&&n&&(await this.detachComponent(t),s=!0),l in e)for(const[t,n]of e[l])this.#s(t,n,!1);return s&&"onAttach"in e&&await e.onAttach(this),this.#t.set(t,e),r.some(e)}async attachComponent(...t){const e=[];for(const n of t)e.push(await this.#s(Object.getPrototypeOf(n).constructor,n));return e}async getOrCreate(t,...e){let n=this.#t.get(t);return n?r.some(n):this.#s(t,new t(...e))}async detachComponent(t){const e=this.#t.get(t);return e&&"onDetach"in e&&await e.onDetach(this),this.#t.delete(t)}clear(){this.#t.clear()}getComponentKeys(){return this.#t.keys()}has(t){return this.#t.has(t)}afterTick(t){this.#n.push(t)}beforeTick(t){this.#e.unshift(t)}handleTicks(t){for(const e of this.#e)this.profiler((()=>e.call(null,r.some(t))));this.#e.length=0;for(const e of this.#t.values()){e[i]||(e[i]=r.some(t)),e[a]||(e[a]=this);const{onTick:n}=e;n&&this.profiler((()=>n.call(e,this,r.some(t))),e)}for(const e of this.#n)this.profiler((()=>e.call(null,r.some(t))));this.#n.length=0}update(t,e){const n=this.#t.get(t);return!!n&&(e(n),!0)}profiler(t,e,n){if(!u.profilerEnable)return t();const s=e?Object.getPrototypeOf(e).constructor.name:"",o=n||(s?`${s}.${t.name}`:t.name),r=performance.now(),a=t();return console.log(`[Profiler] ${o} took ${performance.now()-r}ms`),a}}const l=Symbol("REQUIRED_COMPONENTS");function h(...t){return class extends p{[l]=new Map;constructor(){super();for(const e of t)if(Array.isArray(e)){const[t,...n]=e;this[l].set(t,Reflect.construct(t,n))}else this[l].set(e,Reflect.construct(e,[]))}getComponent(t){return this[l].get(t)}}}var m,f;!function(n){const s=new Map;function o(t){const e=new u;return s.set(t,e),e}function a(){for(const[e,n]of s.entries()){const s=t.getEntity(e);s&&n.handleTicks(s)}}n.addEntity=o,n.removeEntity=function(t){const e=t,n=s.get(e);n?.clear(),s.delete(e)},n.getManager=function(t){return s.get(t)??o(t)},n.tick=a,n.start=function(){e.runInterval(a)},n.toPlayer=function(e){return r.some(t.getAllPlayers().find((t=>t.id===e.id)))}}(m||(m={})),function(t){t[t.Press=0]="Press",t[t.Release=1]="Release",t[t.None=2]="None"}(f||(f={}));class g extends p{[n.Jump]=f.None;[n.Sneak]=f.None;static setup(){t.afterEvents.playerButtonInput.subscribe((t=>{const e=m.getManager(t.player.id);e.getComponent(g).use((n=>{n[t.button]=t.newButtonState===s.Pressed?f.Press:f.Release,e.afterTick((()=>{n[t.button]=f.None}))}))}))}}class d extends p{[n.Jump]=f.None;[n.Sneak]=f.None;_lastJump=s.Released;_lastSneak=s.Released;onTick(t,e){const o=m.toPlayer(e.unwrap()).unwrap(),r=o.inputInfo.getButtonState(n.Jump),a=o.inputInfo.getButtonState(n.Sneak);r===s.Pressed&&this._lastJump===s.Released?this[n.Jump]=f.Press:r===s.Released&&this._lastJump===s.Pressed?this[n.Jump]=f.Release:this[n.Jump]=f.None,a===s.Pressed&&this._lastSneak===s.Released?this[n.Sneak]=f.Press:a===s.Released&&this._lastSneak===s.Pressed?this[n.Sneak]=f.Release:this[n.Sneak]=f.None,this._lastJump=r,this._lastSneak=a}}export{o as Actor,p as BaseComponent,u as ComponentManager,c as CustomComponent,f as InputChangeState,r as Optional,d as PlayerInputCompatibilityComponent,g as PlayerInputComponent,h as RequireComponents,m as oc};
|
package/doc/sapdon-ts.md
CHANGED
|
@@ -10,7 +10,7 @@ ts版本拥有更好的类型提示,更严格的类型检查,也可以直接
|
|
|
10
10
|
比如我们需要注册一个物品,可能你会想去找它在哪,但在ts版本中,你只需要 `@sapdon/core` 就可以了
|
|
11
11
|
|
|
12
12
|
```ts
|
|
13
|
-
import { ItemAPI } from '@sapdon/core
|
|
13
|
+
import { ItemAPI } from '@sapdon/core'
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
如果你需要更高级的功能,比如你需要一个ts打包器,或者添加命令行的功能,你可以使用 `@sapdon/cli`
|
|
@@ -26,3 +26,37 @@ startDevServer(GRegistry, UISystemRegistry)
|
|
|
26
26
|
```
|
|
27
27
|
如果需要从js迁移到ts,删除 `startDevServer` 那行即可(不删也没事)
|
|
28
28
|
|
|
29
|
+
|
|
30
|
+
## OC (Object - Component)
|
|
31
|
+
sapdon通过 `@sapdon/oc` 为sapi提供了一些高级功能, 比如:
|
|
32
|
+
- 实体组件系统
|
|
33
|
+
- 组件间通信
|
|
34
|
+
|
|
35
|
+
传统的书写方式是通过事件和tick回调来实现功能, 而OC提供了更适合游戏的组件化开发方式
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { world, system } from '@minecraft/server'
|
|
39
|
+
import { oc, CustomComponent } from '@sapdon/oc'
|
|
40
|
+
|
|
41
|
+
world.afterEvents.worldInitialize.subscribe(oc.start)
|
|
42
|
+
|
|
43
|
+
class MyComponent extends CustomComponent {
|
|
44
|
+
onTick() {
|
|
45
|
+
world.sendMessage('tick')
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
是的, 我们得到了一个MyComponent, 它每刻都会给玩家发送 'tick'
|
|
51
|
+
但是如果你进入游戏, 会发现它毫无作用, 没错! 因为我们还没有把它到绑定在实体身上!
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const manager = oc.addEntity(id)
|
|
55
|
+
manager.attachComponent(new MyComponent())
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
这样就可以了, 我们已经把MyComponent绑定到了entityId为id的实体身上
|
|
59
|
+
|
|
60
|
+
你也可以动态增删改查组件! 这很方便!
|
|
61
|
+
|
|
62
|
+
如果你想看它到底是怎么回事,可以从 `examples/oc-core` 开始了解
|
package/package.json
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sapdon",
|
|
3
|
-
"version": "3.0.
|
|
4
|
-
"main": "dist/core/index.js",
|
|
5
|
-
"types": "dist/core/index.d.ts",
|
|
3
|
+
"version": "3.0.3",
|
|
6
4
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"build": "node dist/cli/index.js build",
|
|
10
|
-
"pub": "tsc && npm publish"
|
|
5
|
+
"build": "rollup -c",
|
|
6
|
+
"pub": "rollup -c && npm publish"
|
|
11
7
|
},
|
|
12
8
|
"keywords": [
|
|
13
9
|
"bedrock",
|
|
@@ -22,15 +18,17 @@
|
|
|
22
18
|
},
|
|
23
19
|
"description": "Sapdon is a Node.js toolkit designed for building Bedrock Edition Minecraft addon packs.",
|
|
24
20
|
"devDependencies": {
|
|
25
|
-
"@minecraft/server": "^1.
|
|
21
|
+
"@minecraft/server": "^2.0.0-beta.1.21.80-preview.20",
|
|
26
22
|
"@minecraft/server-ui": "^1.3.0",
|
|
27
23
|
"@rollup/plugin-commonjs": "^28.0.2",
|
|
28
24
|
"@rollup/plugin-json": "^6.1.0",
|
|
29
25
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
26
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
30
27
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
31
28
|
"@types/lodash": "^4.17.16",
|
|
32
29
|
"@types/node": "^22.13.8",
|
|
33
30
|
"rollup": "^4.30.1",
|
|
31
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
34
32
|
"rollup-plugin-typescript-paths": "^1.5.0",
|
|
35
33
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
36
34
|
"rollup-plugin-visualizer": "^5.14.0",
|