keystonemc 3.2.4 → 4.0.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/README.md +1 -1
- package/dist/components-BZCbUNW6.js +133 -0
- package/dist/core/form/tsx/components/ActionForm.d.ts +12 -0
- package/dist/core/form/tsx/components/Button.d.ts +8 -0
- package/dist/core/form/tsx/components/Dropdown.d.ts +7 -0
- package/dist/core/form/tsx/components/ModalForm.d.ts +13 -0
- package/dist/core/form/tsx/components/Slider.d.ts +9 -0
- package/dist/core/form/tsx/components/Textfield.d.ts +7 -0
- package/dist/core/form/tsx/components/Toggle.d.ts +6 -0
- package/dist/core/form/tsx/components/index.d.ts +8 -0
- package/dist/core/form/tsx/runtime.d.ts +23 -0
- package/dist/form/component/index.js +95 -0
- package/dist/form/jsx-runtime/index.js +46 -0
- package/dist/index.js +41 -161
- package/dist/vite-plugin/behaviorPacker.d.ts +11 -0
- package/dist/vite-plugin/index.d.ts +3 -11
- package/dist/vite-plugin/index.js +15 -4
- package/dist/vite-plugin/supportJsx.d.ts +3 -0
- package/package.json +36 -1
package/README.md
CHANGED
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
1. core/ 配下でライブラリを更新
|
|
20
20
|
1. キリが良いところで push する
|
|
21
21
|
1. 動作確認は以下
|
|
22
|
-
1. keystone側で package.json の dependencies を書き換え
|
|
22
|
+
1. [keystone](https://github.com/XxPMMPERxX/Keystone)側で package.json の dependencies を書き換え
|
|
23
23
|
1. `"keystonemc": "github:XxPMMPERxX/KeystoneCore#<ブランチ名>"`
|
|
24
24
|
1. `npm install keystonemc` を実行するとブランチの最新の状態でインストールされる
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { ModalFormData, ActionFormData } from "@minecraft/server-ui";
|
|
2
|
+
class ModalForm {
|
|
3
|
+
constructor(config) {
|
|
4
|
+
this.config = config;
|
|
5
|
+
}
|
|
6
|
+
async send(player) {
|
|
7
|
+
const form = new ModalFormData().title(this.config.title);
|
|
8
|
+
for (const component of this.config.components) {
|
|
9
|
+
component.render(form);
|
|
10
|
+
}
|
|
11
|
+
const res = await form.show(player);
|
|
12
|
+
if (res.canceled) {
|
|
13
|
+
this.config.previousForm?.send(player);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
res.formValues?.forEach((value, index) => {
|
|
17
|
+
const component = this.config.components[index];
|
|
18
|
+
try {
|
|
19
|
+
component.handle?.(player, value);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.warn(`[ModalForm] handler error at index ${index}: ${e}`);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
this.config.handle?.(player, res.formValues);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function createModalForm(config) {
|
|
28
|
+
return new ModalForm(config);
|
|
29
|
+
}
|
|
30
|
+
class ActionForm {
|
|
31
|
+
constructor(config) {
|
|
32
|
+
this.config = config;
|
|
33
|
+
}
|
|
34
|
+
async send(player) {
|
|
35
|
+
const form = new ActionFormData().title(this.config.title);
|
|
36
|
+
if (this.config.body) {
|
|
37
|
+
form.body(this.config.body);
|
|
38
|
+
}
|
|
39
|
+
for (const btn of this.config.buttons) {
|
|
40
|
+
btn.render(form);
|
|
41
|
+
}
|
|
42
|
+
const res = await form.show(player);
|
|
43
|
+
if (res.canceled) {
|
|
44
|
+
this.config.previousForm?.send(player);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const index = res.selection;
|
|
48
|
+
if (index === void 0) return;
|
|
49
|
+
const button2 = this.config.buttons[index];
|
|
50
|
+
button2?.handle(player);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function createActionForm(config) {
|
|
54
|
+
return new ActionForm(config);
|
|
55
|
+
}
|
|
56
|
+
function toggle(opts) {
|
|
57
|
+
return {
|
|
58
|
+
render(form) {
|
|
59
|
+
form.toggle(opts.label, { defaultValue: opts.default });
|
|
60
|
+
},
|
|
61
|
+
handle(player, value) {
|
|
62
|
+
opts.handler?.(player, value);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function textField(opts) {
|
|
67
|
+
return {
|
|
68
|
+
render(form) {
|
|
69
|
+
form.textField(
|
|
70
|
+
opts.label,
|
|
71
|
+
opts.placeholder ?? "",
|
|
72
|
+
{ defaultValue: opts.default ?? "" }
|
|
73
|
+
);
|
|
74
|
+
},
|
|
75
|
+
handle(player, value) {
|
|
76
|
+
opts.handler?.(player, value);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function slider(opts) {
|
|
81
|
+
return {
|
|
82
|
+
render(form) {
|
|
83
|
+
form.slider(
|
|
84
|
+
opts.label,
|
|
85
|
+
opts.min,
|
|
86
|
+
opts.max,
|
|
87
|
+
{ valueStep: opts.step ?? 1, defaultValue: opts.default }
|
|
88
|
+
);
|
|
89
|
+
},
|
|
90
|
+
handle(player, value) {
|
|
91
|
+
opts.handler?.(player, value);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function dropdown(opts) {
|
|
96
|
+
return {
|
|
97
|
+
render(form) {
|
|
98
|
+
form.dropdown(
|
|
99
|
+
opts.label,
|
|
100
|
+
opts.options,
|
|
101
|
+
{ defaultValueIndex: opts.defaultIndex ?? 0 }
|
|
102
|
+
);
|
|
103
|
+
},
|
|
104
|
+
handle(player, value) {
|
|
105
|
+
opts.handler?.(player, value);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function button(opts) {
|
|
110
|
+
return {
|
|
111
|
+
render(form) {
|
|
112
|
+
if (opts.iconPath) {
|
|
113
|
+
form.button(opts.text, opts.iconPath);
|
|
114
|
+
} else {
|
|
115
|
+
form.button(opts.text);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
handle(player) {
|
|
119
|
+
opts.handler(player);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
export {
|
|
124
|
+
ActionForm as A,
|
|
125
|
+
ModalForm as M,
|
|
126
|
+
createActionForm as a,
|
|
127
|
+
textField as b,
|
|
128
|
+
createModalForm as c,
|
|
129
|
+
dropdown as d,
|
|
130
|
+
button as e,
|
|
131
|
+
slider as s,
|
|
132
|
+
toggle as t
|
|
133
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ActionButton } from '../../types';
|
|
2
|
+
import { ActionForm as ActionFormType } from '../../actionForm';
|
|
3
|
+
import { ModalForm } from '../../modalForm';
|
|
4
|
+
import { MessageForm } from '../../messageForm';
|
|
5
|
+
interface ActionFormProps {
|
|
6
|
+
title: string;
|
|
7
|
+
body?: string;
|
|
8
|
+
previousForm?: ModalForm | ActionFormType | MessageForm;
|
|
9
|
+
children?: ActionButton[];
|
|
10
|
+
}
|
|
11
|
+
export default function ActionForm({ title, body, previousForm, children, }: ActionFormProps): ActionFormType;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Player } from '@minecraft/server';
|
|
2
|
+
interface ActionButtonProps {
|
|
3
|
+
iconPath?: string;
|
|
4
|
+
children?: string | string[];
|
|
5
|
+
onClick?: (player: Player) => any;
|
|
6
|
+
}
|
|
7
|
+
export default function Button({ iconPath, children, onClick, }: ActionButtonProps): import('../../types').ActionButton;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ActionForm } from '../../actionForm';
|
|
2
|
+
import { MessageForm } from '../../messageForm';
|
|
3
|
+
import { ModalForm as ModalFormType } from '../../modalForm';
|
|
4
|
+
import { FormComponent } from '../../types';
|
|
5
|
+
import { Player } from '@minecraft/server';
|
|
6
|
+
interface ModalFormProps<T = any> {
|
|
7
|
+
title: string;
|
|
8
|
+
previousForm?: ModalFormType | ActionForm | MessageForm;
|
|
9
|
+
children?: FormComponent[];
|
|
10
|
+
onSubmit?: (player: Player, values?: T[] | undefined) => any;
|
|
11
|
+
}
|
|
12
|
+
export default function ModalForm({ title, previousForm, children, onSubmit, }: ModalFormProps): ModalFormType;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as ActionForm } from './ActionForm';
|
|
2
|
+
import { default as Button } from './Button';
|
|
3
|
+
import { default as ModalForm } from './ModalForm';
|
|
4
|
+
import { default as Slider } from './Slider';
|
|
5
|
+
import { default as Dropdown } from './Dropdown';
|
|
6
|
+
import { default as Textfield } from './Textfield';
|
|
7
|
+
import { default as Toggle } from './Toggle';
|
|
8
|
+
export { ActionForm, Button, ModalForm, Slider, Dropdown, Textfield, Toggle, };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSX Fragment 用の一意な識別子
|
|
3
|
+
*/
|
|
4
|
+
export declare const Fragment: unique symbol;
|
|
5
|
+
/**
|
|
6
|
+
* JSX で生成される要素の type
|
|
7
|
+
* - 関数コンポーネント
|
|
8
|
+
* - Fragment
|
|
9
|
+
*/
|
|
10
|
+
export type JSXElementType = ((props: any) => any) | typeof Fragment;
|
|
11
|
+
/**
|
|
12
|
+
* JSX のエントリポイント
|
|
13
|
+
*/
|
|
14
|
+
export declare function createElement(type: JSXElementType, props: any, ...children: any[]): any;
|
|
15
|
+
/**
|
|
16
|
+
* 本番モード用 JSX エントリポイント
|
|
17
|
+
*/
|
|
18
|
+
export declare function jsx(type: JSXElementType, props: any, _key?: unknown): any;
|
|
19
|
+
export { jsx as jsxs };
|
|
20
|
+
/**
|
|
21
|
+
* 開発モード用 JSX エントリポイント
|
|
22
|
+
*/
|
|
23
|
+
export declare function jsxDEV(type: JSXElementType, props: any, ..._deps: unknown[]): any;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { a as createActionForm, e as button, c as createModalForm, s as slider, d as dropdown, b as textField, t as toggle } from "../../components-BZCbUNW6.js";
|
|
2
|
+
function ActionForm({
|
|
3
|
+
title,
|
|
4
|
+
body,
|
|
5
|
+
previousForm,
|
|
6
|
+
children = []
|
|
7
|
+
}) {
|
|
8
|
+
return createActionForm({
|
|
9
|
+
title,
|
|
10
|
+
body,
|
|
11
|
+
previousForm,
|
|
12
|
+
buttons: children
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function Button({
|
|
16
|
+
iconPath = "",
|
|
17
|
+
children = [],
|
|
18
|
+
onClick = () => {
|
|
19
|
+
}
|
|
20
|
+
}) {
|
|
21
|
+
return button({
|
|
22
|
+
text: typeof children === "object" ? children.join("\n") : children,
|
|
23
|
+
iconPath,
|
|
24
|
+
handler: onClick
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function ModalForm({
|
|
28
|
+
title,
|
|
29
|
+
previousForm,
|
|
30
|
+
children = [],
|
|
31
|
+
onSubmit = () => {
|
|
32
|
+
}
|
|
33
|
+
}) {
|
|
34
|
+
return createModalForm({
|
|
35
|
+
title,
|
|
36
|
+
previousForm,
|
|
37
|
+
components: children,
|
|
38
|
+
handle: onSubmit
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function Slider({
|
|
42
|
+
label,
|
|
43
|
+
min,
|
|
44
|
+
max,
|
|
45
|
+
step,
|
|
46
|
+
defaultValue = min
|
|
47
|
+
}) {
|
|
48
|
+
return slider({
|
|
49
|
+
label,
|
|
50
|
+
min,
|
|
51
|
+
max,
|
|
52
|
+
step,
|
|
53
|
+
default: defaultValue
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function Dropdown({
|
|
57
|
+
label,
|
|
58
|
+
options,
|
|
59
|
+
defaultValueIndex
|
|
60
|
+
}) {
|
|
61
|
+
return dropdown({
|
|
62
|
+
label,
|
|
63
|
+
options,
|
|
64
|
+
defaultIndex: defaultValueIndex
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function Textfield({
|
|
68
|
+
label,
|
|
69
|
+
placeholder = "",
|
|
70
|
+
defaultValue = ""
|
|
71
|
+
}) {
|
|
72
|
+
return textField({
|
|
73
|
+
label,
|
|
74
|
+
placeholder,
|
|
75
|
+
default: defaultValue
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function Toggle({
|
|
79
|
+
label,
|
|
80
|
+
defaultValue = false
|
|
81
|
+
}) {
|
|
82
|
+
return toggle({
|
|
83
|
+
label,
|
|
84
|
+
default: defaultValue
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
ActionForm,
|
|
89
|
+
Button,
|
|
90
|
+
Dropdown,
|
|
91
|
+
ModalForm,
|
|
92
|
+
Slider,
|
|
93
|
+
Textfield,
|
|
94
|
+
Toggle
|
|
95
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const Fragment = /* @__PURE__ */ Symbol("Fragment");
|
|
2
|
+
function createElement(type, props, ...children) {
|
|
3
|
+
if (type === Fragment) {
|
|
4
|
+
return normalizeChildren(children);
|
|
5
|
+
}
|
|
6
|
+
if (typeof type !== "function") {
|
|
7
|
+
throw new Error("Invalid JSX element type");
|
|
8
|
+
}
|
|
9
|
+
return type({
|
|
10
|
+
...props ?? {},
|
|
11
|
+
children: normalizeChildren(children)
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function normalizeChildren(children) {
|
|
15
|
+
return children.flat(Infinity).filter(
|
|
16
|
+
(child) => child !== null && child !== void 0 && child !== false
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
function jsxInternal(type, props) {
|
|
20
|
+
const children = props?.children;
|
|
21
|
+
const restProps = { ...props };
|
|
22
|
+
delete restProps.children;
|
|
23
|
+
if (type === Fragment) {
|
|
24
|
+
return normalizeChildren(Array.isArray(children) ? children : [children]);
|
|
25
|
+
}
|
|
26
|
+
if (typeof type !== "function") {
|
|
27
|
+
throw new Error("Invalid JSX element type");
|
|
28
|
+
}
|
|
29
|
+
return type({
|
|
30
|
+
...restProps,
|
|
31
|
+
children: normalizeChildren(Array.isArray(children) ? children : [children])
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function jsx(type, props, _key) {
|
|
35
|
+
return jsxInternal(type, props);
|
|
36
|
+
}
|
|
37
|
+
function jsxDEV(type, props, ..._deps) {
|
|
38
|
+
return jsxInternal(type, props);
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
Fragment,
|
|
42
|
+
createElement,
|
|
43
|
+
jsx,
|
|
44
|
+
jsxDEV,
|
|
45
|
+
jsx as jsxs
|
|
46
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { world, system } from "@minecraft/server";
|
|
2
|
-
import {
|
|
2
|
+
import { A, M, e, a, c, d, s, b, t } from "./components-BZCbUNW6.js";
|
|
3
|
+
import { MessageFormData } from "@minecraft/server-ui";
|
|
3
4
|
class Keystone {
|
|
4
5
|
constructor() {
|
|
5
6
|
}
|
|
@@ -475,12 +476,12 @@ class Vector3 {
|
|
|
475
476
|
getIntermediateWithXValue(end, xValue) {
|
|
476
477
|
const dx = end.x - this.x;
|
|
477
478
|
if (dx === 0) return;
|
|
478
|
-
const
|
|
479
|
-
if (
|
|
479
|
+
const t2 = (xValue - this.x) / dx;
|
|
480
|
+
if (t2 < 0 || t2 > 1) return;
|
|
480
481
|
return new Vector3(
|
|
481
|
-
this.x + dx *
|
|
482
|
-
this.y + (end.y - this.y) *
|
|
483
|
-
this.z + (end.z - this.z) *
|
|
482
|
+
this.x + dx * t2,
|
|
483
|
+
this.y + (end.y - this.y) * t2,
|
|
484
|
+
this.z + (end.z - this.z) * t2
|
|
484
485
|
);
|
|
485
486
|
}
|
|
486
487
|
/**
|
|
@@ -492,12 +493,12 @@ class Vector3 {
|
|
|
492
493
|
getIntermediateWithYValue(end, yValue) {
|
|
493
494
|
const dy = end.y - this.y;
|
|
494
495
|
if (dy === 0) return;
|
|
495
|
-
const
|
|
496
|
-
if (
|
|
496
|
+
const t2 = (yValue - this.y) / dy;
|
|
497
|
+
if (t2 < 0 || t2 > 1) return;
|
|
497
498
|
return new Vector3(
|
|
498
|
-
this.x + (end.x - this.x) *
|
|
499
|
-
this.y + dy *
|
|
500
|
-
this.z + (end.z - this.z) *
|
|
499
|
+
this.x + (end.x - this.x) * t2,
|
|
500
|
+
this.y + dy * t2,
|
|
501
|
+
this.z + (end.z - this.z) * t2
|
|
501
502
|
);
|
|
502
503
|
}
|
|
503
504
|
/**
|
|
@@ -509,12 +510,12 @@ class Vector3 {
|
|
|
509
510
|
getIntermediateWithZValue(end, zValue) {
|
|
510
511
|
const dz = end.z - this.z;
|
|
511
512
|
if (dz === 0) return;
|
|
512
|
-
const
|
|
513
|
-
if (
|
|
513
|
+
const t2 = (zValue - this.z) / dz;
|
|
514
|
+
if (t2 < 0 || t2 > 1) return;
|
|
514
515
|
return new Vector3(
|
|
515
|
-
this.x + (end.x - this.x) *
|
|
516
|
-
this.y + (end.y - this.y) *
|
|
517
|
-
this.z + dz *
|
|
516
|
+
this.x + (end.x - this.x) * t2,
|
|
517
|
+
this.y + (end.y - this.y) * t2,
|
|
518
|
+
this.z + dz * t2
|
|
518
519
|
);
|
|
519
520
|
}
|
|
520
521
|
/**
|
|
@@ -805,7 +806,7 @@ function registerAfter(eventName, listener) {
|
|
|
805
806
|
}
|
|
806
807
|
const arr = afterListeners[eventName];
|
|
807
808
|
arr.push(listener);
|
|
808
|
-
arr.sort((
|
|
809
|
+
arr.sort((a2, b2) => (b2.priority ?? Priority.NORMAL) - (a2.priority ?? Priority.NORMAL));
|
|
809
810
|
}
|
|
810
811
|
function registerBefore(eventName, listener) {
|
|
811
812
|
if (!beforeListeners[eventName]) {
|
|
@@ -813,7 +814,7 @@ function registerBefore(eventName, listener) {
|
|
|
813
814
|
}
|
|
814
815
|
const arr = beforeListeners[eventName];
|
|
815
816
|
arr.push(listener);
|
|
816
|
-
arr.sort((
|
|
817
|
+
arr.sort((a2, b2) => (b2.priority ?? Priority.NORMAL) - (a2.priority ?? Priority.NORMAL));
|
|
817
818
|
}
|
|
818
819
|
function dispatchAfter(eventName, event) {
|
|
819
820
|
const arr = afterListeners[eventName];
|
|
@@ -821,8 +822,8 @@ function dispatchAfter(eventName, event) {
|
|
|
821
822
|
for (const listener of arr) {
|
|
822
823
|
try {
|
|
823
824
|
listener.handler(event);
|
|
824
|
-
} catch (
|
|
825
|
-
console.error(`[EventManager] after:${String(eventName)} handler threw:`,
|
|
825
|
+
} catch (e2) {
|
|
826
|
+
console.error(`[EventManager] after:${String(eventName)} handler threw:`, e2);
|
|
826
827
|
}
|
|
827
828
|
}
|
|
828
829
|
}
|
|
@@ -832,8 +833,8 @@ function dispatchBefore(eventName, event) {
|
|
|
832
833
|
for (const listener of arr) {
|
|
833
834
|
try {
|
|
834
835
|
listener.handler(event);
|
|
835
|
-
} catch (
|
|
836
|
-
console.error(`[EventManager] before:${String(eventName)} handler threw:`,
|
|
836
|
+
} catch (e2) {
|
|
837
|
+
console.error(`[EventManager] before:${String(eventName)} handler threw:`, e2);
|
|
837
838
|
}
|
|
838
839
|
}
|
|
839
840
|
}
|
|
@@ -922,7 +923,7 @@ class RepeatingTimer extends BaseTimer {
|
|
|
922
923
|
}
|
|
923
924
|
}
|
|
924
925
|
function repeating(opts) {
|
|
925
|
-
const
|
|
926
|
+
const t2 = new RepeatingTimer(
|
|
926
927
|
opts.run,
|
|
927
928
|
{
|
|
928
929
|
period: opts.every ?? 1,
|
|
@@ -932,8 +933,8 @@ function repeating(opts) {
|
|
|
932
933
|
},
|
|
933
934
|
opts.cancel
|
|
934
935
|
);
|
|
935
|
-
|
|
936
|
-
return
|
|
936
|
+
t2.start();
|
|
937
|
+
return t2;
|
|
937
938
|
}
|
|
938
939
|
class DelayedTimer extends BaseTimer {
|
|
939
940
|
constructor(delay, onRun, onCancel) {
|
|
@@ -966,9 +967,9 @@ class DelayedTimer extends BaseTimer {
|
|
|
966
967
|
}
|
|
967
968
|
}
|
|
968
969
|
function delayed(ticks, run, cancel) {
|
|
969
|
-
const
|
|
970
|
-
|
|
971
|
-
return
|
|
970
|
+
const t2 = new DelayedTimer(ticks, run, cancel);
|
|
971
|
+
t2.start();
|
|
972
|
+
return t2;
|
|
972
973
|
}
|
|
973
974
|
function sleep(ticks) {
|
|
974
975
|
return new Promise((resolve) => {
|
|
@@ -1018,7 +1019,7 @@ class UntilTimer extends BaseTimer {
|
|
|
1018
1019
|
}
|
|
1019
1020
|
}
|
|
1020
1021
|
function until(opts) {
|
|
1021
|
-
const
|
|
1022
|
+
const t2 = new UntilTimer(
|
|
1022
1023
|
opts.when,
|
|
1023
1024
|
opts.run,
|
|
1024
1025
|
opts.every ?? 1,
|
|
@@ -1026,8 +1027,8 @@ function until(opts) {
|
|
|
1026
1027
|
opts.onTimeout,
|
|
1027
1028
|
opts.cancel
|
|
1028
1029
|
);
|
|
1029
|
-
|
|
1030
|
-
return
|
|
1030
|
+
t2.start();
|
|
1031
|
+
return t2;
|
|
1031
1032
|
}
|
|
1032
1033
|
function waitUntil(condition, opts) {
|
|
1033
1034
|
return new Promise((resolve) => {
|
|
@@ -1040,60 +1041,6 @@ function waitUntil(condition, opts) {
|
|
|
1040
1041
|
});
|
|
1041
1042
|
});
|
|
1042
1043
|
}
|
|
1043
|
-
class ModalForm {
|
|
1044
|
-
constructor(config) {
|
|
1045
|
-
this.config = config;
|
|
1046
|
-
}
|
|
1047
|
-
async send(player) {
|
|
1048
|
-
const form = new ModalFormData().title(this.config.title);
|
|
1049
|
-
for (const component of this.config.components) {
|
|
1050
|
-
component.render(form);
|
|
1051
|
-
}
|
|
1052
|
-
const res = await form.show(player);
|
|
1053
|
-
if (res.canceled) {
|
|
1054
|
-
this.config.previousForm?.send(player);
|
|
1055
|
-
return;
|
|
1056
|
-
}
|
|
1057
|
-
res.formValues?.forEach((value, index) => {
|
|
1058
|
-
const component = this.config.components[index];
|
|
1059
|
-
try {
|
|
1060
|
-
component.handle?.(player, value);
|
|
1061
|
-
} catch (e) {
|
|
1062
|
-
console.warn(`[ModalForm] handler error at index ${index}: ${e}`);
|
|
1063
|
-
}
|
|
1064
|
-
});
|
|
1065
|
-
this.config.handle?.(player, res.formValues);
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
function createModalForm(config) {
|
|
1069
|
-
return new ModalForm(config);
|
|
1070
|
-
}
|
|
1071
|
-
class ActionForm {
|
|
1072
|
-
constructor(config) {
|
|
1073
|
-
this.config = config;
|
|
1074
|
-
}
|
|
1075
|
-
async send(player) {
|
|
1076
|
-
const form = new ActionFormData().title(this.config.title);
|
|
1077
|
-
if (this.config.body) {
|
|
1078
|
-
form.body(this.config.body);
|
|
1079
|
-
}
|
|
1080
|
-
for (const btn of this.config.buttons) {
|
|
1081
|
-
btn.render(form);
|
|
1082
|
-
}
|
|
1083
|
-
const res = await form.show(player);
|
|
1084
|
-
if (res.canceled) {
|
|
1085
|
-
this.config.previousForm?.send(player);
|
|
1086
|
-
return;
|
|
1087
|
-
}
|
|
1088
|
-
const index = res.selection;
|
|
1089
|
-
if (index === void 0) return;
|
|
1090
|
-
const button2 = this.config.buttons[index];
|
|
1091
|
-
button2?.handle(player);
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
function createActionForm(config) {
|
|
1095
|
-
return new ActionForm(config);
|
|
1096
|
-
}
|
|
1097
1044
|
class MessageForm {
|
|
1098
1045
|
constructor(config) {
|
|
1099
1046
|
this.config = config;
|
|
@@ -1115,97 +1062,30 @@ class MessageForm {
|
|
|
1115
1062
|
function createMessageForm(config) {
|
|
1116
1063
|
return new MessageForm(config);
|
|
1117
1064
|
}
|
|
1118
|
-
function toggle(opts) {
|
|
1119
|
-
return {
|
|
1120
|
-
render(form) {
|
|
1121
|
-
form.toggle(opts.label, { defaultValue: opts.default });
|
|
1122
|
-
},
|
|
1123
|
-
handle(player, value) {
|
|
1124
|
-
opts.handler?.(player, value);
|
|
1125
|
-
}
|
|
1126
|
-
};
|
|
1127
|
-
}
|
|
1128
|
-
function textField(opts) {
|
|
1129
|
-
return {
|
|
1130
|
-
render(form) {
|
|
1131
|
-
form.textField(
|
|
1132
|
-
opts.label,
|
|
1133
|
-
opts.placeholder ?? "",
|
|
1134
|
-
{ defaultValue: opts.default ?? "" }
|
|
1135
|
-
);
|
|
1136
|
-
},
|
|
1137
|
-
handle(player, value) {
|
|
1138
|
-
opts.handler?.(player, value);
|
|
1139
|
-
}
|
|
1140
|
-
};
|
|
1141
|
-
}
|
|
1142
|
-
function slider(opts) {
|
|
1143
|
-
return {
|
|
1144
|
-
render(form) {
|
|
1145
|
-
form.slider(
|
|
1146
|
-
opts.label,
|
|
1147
|
-
opts.min,
|
|
1148
|
-
opts.max,
|
|
1149
|
-
{ valueStep: opts.step ?? 1, defaultValue: opts.default }
|
|
1150
|
-
);
|
|
1151
|
-
},
|
|
1152
|
-
handle(player, value) {
|
|
1153
|
-
opts.handler?.(player, value);
|
|
1154
|
-
}
|
|
1155
|
-
};
|
|
1156
|
-
}
|
|
1157
|
-
function dropdown(opts) {
|
|
1158
|
-
return {
|
|
1159
|
-
render(form) {
|
|
1160
|
-
form.dropdown(
|
|
1161
|
-
opts.label,
|
|
1162
|
-
opts.options,
|
|
1163
|
-
{ defaultValueIndex: opts.defaultIndex ?? 0 }
|
|
1164
|
-
);
|
|
1165
|
-
},
|
|
1166
|
-
handle(player, value) {
|
|
1167
|
-
opts.handler?.(player, value);
|
|
1168
|
-
}
|
|
1169
|
-
};
|
|
1170
|
-
}
|
|
1171
|
-
function button(opts) {
|
|
1172
|
-
return {
|
|
1173
|
-
render(form) {
|
|
1174
|
-
if (opts.iconPath) {
|
|
1175
|
-
form.button(opts.text, opts.iconPath);
|
|
1176
|
-
} else {
|
|
1177
|
-
form.button(opts.text);
|
|
1178
|
-
}
|
|
1179
|
-
},
|
|
1180
|
-
handle(player) {
|
|
1181
|
-
opts.handler(player);
|
|
1182
|
-
}
|
|
1183
|
-
};
|
|
1184
|
-
}
|
|
1185
1065
|
export {
|
|
1186
|
-
ActionForm,
|
|
1066
|
+
A as ActionForm,
|
|
1187
1067
|
AxisAlignedBB,
|
|
1188
1068
|
DelayedTimer,
|
|
1189
1069
|
EventManager,
|
|
1190
1070
|
MessageForm,
|
|
1191
|
-
ModalForm,
|
|
1071
|
+
M as ModalForm,
|
|
1192
1072
|
Priority,
|
|
1193
1073
|
RepeatingTimer,
|
|
1194
1074
|
UntilTimer,
|
|
1195
1075
|
Vector3,
|
|
1196
|
-
button,
|
|
1197
|
-
createActionForm,
|
|
1076
|
+
e as button,
|
|
1077
|
+
a as createActionForm,
|
|
1198
1078
|
createMessageForm,
|
|
1199
|
-
createModalForm,
|
|
1079
|
+
c as createModalForm,
|
|
1200
1080
|
debug,
|
|
1201
1081
|
delayed,
|
|
1202
|
-
dropdown,
|
|
1082
|
+
d as dropdown,
|
|
1203
1083
|
keystone,
|
|
1204
1084
|
repeating,
|
|
1205
1085
|
sleep,
|
|
1206
|
-
slider,
|
|
1207
|
-
textField,
|
|
1208
|
-
toggle,
|
|
1086
|
+
s as slider,
|
|
1087
|
+
b as textField,
|
|
1088
|
+
t as toggle,
|
|
1209
1089
|
until,
|
|
1210
1090
|
waitUntil
|
|
1211
1091
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
type PluginConfig = {
|
|
3
|
+
name: string;
|
|
4
|
+
uuid?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
authors?: string[];
|
|
7
|
+
version?: number[];
|
|
8
|
+
embedSourceMap?: boolean;
|
|
9
|
+
};
|
|
10
|
+
declare const behaviorPacker: ({ name, uuid, description, authors, version, embedSourceMap, }?: PluginConfig) => Plugin;
|
|
11
|
+
export default behaviorPacker;
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
uuid?: string;
|
|
5
|
-
description?: string;
|
|
6
|
-
authors?: string[];
|
|
7
|
-
version?: number[];
|
|
8
|
-
embedSourceMap?: boolean;
|
|
9
|
-
};
|
|
10
|
-
declare const behaviorPacker: ({ name, uuid, description, authors, version, embedSourceMap, }?: PluginConfig) => Plugin;
|
|
11
|
-
export default behaviorPacker;
|
|
1
|
+
import { default as behaviorPacker } from './behaviorPacker';
|
|
2
|
+
import { default as supportJsx } from './supportJsx';
|
|
3
|
+
export { behaviorPacker, supportJsx, };
|
|
@@ -16,9 +16,8 @@ const behaviorPacker = ({
|
|
|
16
16
|
embedSourceMap: true
|
|
17
17
|
}) => ({
|
|
18
18
|
name: "BehaviorPacker",
|
|
19
|
-
config: (
|
|
19
|
+
config: () => {
|
|
20
20
|
return {
|
|
21
|
-
...config,
|
|
22
21
|
build: {
|
|
23
22
|
sourcemap: true,
|
|
24
23
|
minify: false,
|
|
@@ -40,7 +39,7 @@ const behaviorPacker = ({
|
|
|
40
39
|
},
|
|
41
40
|
generateBundle(options, bundle) {
|
|
42
41
|
if (!embedSourceMap) return;
|
|
43
|
-
for (const [
|
|
42
|
+
for (const [, file] of Object.entries(bundle)) {
|
|
44
43
|
if (file.type === "chunk" && file.map) {
|
|
45
44
|
const sourceMapData = file.map;
|
|
46
45
|
const embeddedSourceMap = {
|
|
@@ -113,6 +112,18 @@ globalThis.__SOURCE_MAP__ = ${JSON.stringify(embeddedSourceMap)};
|
|
|
113
112
|
fs.writeFileSync("./dist_behavior_pack/manifest.json", JSON.stringify(manifestStub, null, 2));
|
|
114
113
|
}
|
|
115
114
|
});
|
|
115
|
+
const supportJsx = () => ({
|
|
116
|
+
name: "SupportJsx",
|
|
117
|
+
config: () => {
|
|
118
|
+
return {
|
|
119
|
+
esbuild: {
|
|
120
|
+
jsx: "automatic",
|
|
121
|
+
jsxImportSource: "keystonemc/form"
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
});
|
|
116
126
|
export {
|
|
117
|
-
behaviorPacker
|
|
127
|
+
behaviorPacker,
|
|
128
|
+
supportJsx
|
|
118
129
|
};
|
package/package.json
CHANGED
|
@@ -1,21 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keystonemc",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "ScriptAPI Wrapper",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc && vite build",
|
|
8
8
|
"prepare": "npm run build"
|
|
9
9
|
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/XxPMMPERxX/KeystoneCore"
|
|
13
|
+
},
|
|
10
14
|
"main": "./dist/index.js",
|
|
11
15
|
"module": "./dist/index.js",
|
|
12
16
|
"types": "./dist/core/index.d.ts",
|
|
17
|
+
"typesVersions": {
|
|
18
|
+
"*": {
|
|
19
|
+
"form/jsx-runtime": [
|
|
20
|
+
"./dist/core/form/tsx/runtime.d.ts"
|
|
21
|
+
],
|
|
22
|
+
"form/jsx-dev-runtime": [
|
|
23
|
+
"./dist/core/form/tsx/runtime.d.ts"
|
|
24
|
+
],
|
|
25
|
+
"form/component": [
|
|
26
|
+
"./dist/core/form/tsx/components/index.d.ts"
|
|
27
|
+
],
|
|
28
|
+
"vite-plugin": [
|
|
29
|
+
"./dist/vite-plugin/index.d.ts"
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
},
|
|
13
33
|
"exports": {
|
|
14
34
|
".": {
|
|
15
35
|
"types": "./dist/core/index.d.ts",
|
|
16
36
|
"import": "./dist/index.js",
|
|
17
37
|
"default": "./dist/index.js"
|
|
18
38
|
},
|
|
39
|
+
"./form/jsx-runtime": {
|
|
40
|
+
"types": "./dist/core/form/tsx/runtime.d.ts",
|
|
41
|
+
"import": "./dist/form/jsx-runtime/index.js",
|
|
42
|
+
"default": "./dist/form/jsx-runtime/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./form/jsx-dev-runtime": {
|
|
45
|
+
"types": "./dist/core/form/tsx/runtime.d.ts",
|
|
46
|
+
"import": "./dist/form/jsx-runtime/index.js",
|
|
47
|
+
"default": "./dist/form/jsx-runtime/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./form/component": {
|
|
50
|
+
"types": "./dist/core/form/tsx/components/index.d.ts",
|
|
51
|
+
"import": "./dist/form/component/index.js",
|
|
52
|
+
"default": "./dist/form/component/index.js"
|
|
53
|
+
},
|
|
19
54
|
"./vite-plugin": {
|
|
20
55
|
"types": "./dist/vite-plugin/index.d.ts",
|
|
21
56
|
"import": "./dist/vite-plugin/index.js",
|