keystonemc 4.1.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{components-BZCbUNW6.js → components-avk6bHuS.js} +71 -5
- package/dist/core/form/components.d.ts +18 -1
- package/dist/core/form/tsx/components/Divider.d.ts +2 -0
- package/dist/core/form/tsx/components/Dropdown.d.ts +3 -0
- package/dist/core/form/tsx/components/Header.d.ts +8 -0
- package/dist/core/form/tsx/components/Label.d.ts +5 -0
- package/dist/core/form/tsx/components/MessageForm.d.ts +15 -0
- package/dist/core/form/tsx/components/ModalForm.d.ts +17 -1
- package/dist/core/form/tsx/components/Slider.d.ts +3 -0
- package/dist/core/form/tsx/components/Textfield.d.ts +5 -1
- package/dist/core/form/tsx/components/Toggle.d.ts +3 -0
- package/dist/core/form/tsx/components/index.d.ts +5 -1
- package/dist/core/form/types.d.ts +8 -0
- package/dist/core/utils/textFormat.d.ts +50 -0
- package/dist/form/component/index.js +52 -12
- package/dist/index.js +23 -43
- package/dist/vite-plugin/behaviorPacker.d.ts +32 -1
- package/dist/vite-plugin/index.js +49 -5
- package/package.json +1 -1
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { ModalFormData, ActionFormData } from "@minecraft/server-ui";
|
|
1
|
+
import { ModalFormData, ActionFormData, MessageFormData } from "@minecraft/server-ui";
|
|
2
2
|
class ModalForm {
|
|
3
3
|
constructor(config) {
|
|
4
4
|
this.config = config;
|
|
5
5
|
}
|
|
6
6
|
async send(player) {
|
|
7
7
|
const form = new ModalFormData().title(this.config.title);
|
|
8
|
+
if (this.config.submitButtonText) {
|
|
9
|
+
form.submitButton(this.config.submitButtonText);
|
|
10
|
+
}
|
|
8
11
|
for (const component of this.config.components) {
|
|
9
12
|
component.render(form);
|
|
10
13
|
}
|
|
@@ -53,8 +56,31 @@ class ActionForm {
|
|
|
53
56
|
function createActionForm(config) {
|
|
54
57
|
return new ActionForm(config);
|
|
55
58
|
}
|
|
59
|
+
class MessageForm {
|
|
60
|
+
constructor(config) {
|
|
61
|
+
this.config = config;
|
|
62
|
+
}
|
|
63
|
+
async send(player) {
|
|
64
|
+
const form = new MessageFormData().title(this.config.title).body(this.config.body).button1(this.config.yes.text).button2(this.config.no.text);
|
|
65
|
+
const res = await form.show(player);
|
|
66
|
+
if (res.canceled) {
|
|
67
|
+
this.config.previousForm?.send(player);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (res.selection === 0) {
|
|
71
|
+
this.config.yes.handler(player);
|
|
72
|
+
} else if (res.selection === 1) {
|
|
73
|
+
this.config.no.handler(player);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function createMessageForm(config) {
|
|
78
|
+
return new MessageForm(config);
|
|
79
|
+
}
|
|
56
80
|
function toggle(opts) {
|
|
57
81
|
return {
|
|
82
|
+
type: "toggle",
|
|
83
|
+
opts,
|
|
58
84
|
render(form) {
|
|
59
85
|
form.toggle(opts.label, { defaultValue: opts.default });
|
|
60
86
|
},
|
|
@@ -65,11 +91,16 @@ function toggle(opts) {
|
|
|
65
91
|
}
|
|
66
92
|
function textField(opts) {
|
|
67
93
|
return {
|
|
94
|
+
type: "text_field",
|
|
95
|
+
opts,
|
|
68
96
|
render(form) {
|
|
69
97
|
form.textField(
|
|
70
98
|
opts.label,
|
|
71
99
|
opts.placeholder ?? "",
|
|
72
|
-
{
|
|
100
|
+
{
|
|
101
|
+
defaultValue: opts.default ?? "",
|
|
102
|
+
tooltip: opts.tooltip
|
|
103
|
+
}
|
|
73
104
|
);
|
|
74
105
|
},
|
|
75
106
|
handle(player, value) {
|
|
@@ -79,6 +110,8 @@ function textField(opts) {
|
|
|
79
110
|
}
|
|
80
111
|
function slider(opts) {
|
|
81
112
|
return {
|
|
113
|
+
type: "slider",
|
|
114
|
+
opts,
|
|
82
115
|
render(form) {
|
|
83
116
|
form.slider(
|
|
84
117
|
opts.label,
|
|
@@ -94,6 +127,8 @@ function slider(opts) {
|
|
|
94
127
|
}
|
|
95
128
|
function dropdown(opts) {
|
|
96
129
|
return {
|
|
130
|
+
type: "dropdown",
|
|
131
|
+
opts,
|
|
97
132
|
render(form) {
|
|
98
133
|
form.dropdown(
|
|
99
134
|
opts.label,
|
|
@@ -106,6 +141,32 @@ function dropdown(opts) {
|
|
|
106
141
|
}
|
|
107
142
|
};
|
|
108
143
|
}
|
|
144
|
+
function header(opts) {
|
|
145
|
+
return {
|
|
146
|
+
type: "header",
|
|
147
|
+
opts,
|
|
148
|
+
render(form) {
|
|
149
|
+
form.header(opts.text);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function label(opts) {
|
|
154
|
+
return {
|
|
155
|
+
type: "label",
|
|
156
|
+
opts,
|
|
157
|
+
render(form) {
|
|
158
|
+
form.label(opts.text);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function divider() {
|
|
163
|
+
return {
|
|
164
|
+
type: "divider",
|
|
165
|
+
render(form) {
|
|
166
|
+
form.divider();
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
109
170
|
function button(opts) {
|
|
110
171
|
return {
|
|
111
172
|
render(form) {
|
|
@@ -124,10 +185,15 @@ export {
|
|
|
124
185
|
ActionForm as A,
|
|
125
186
|
ModalForm as M,
|
|
126
187
|
createActionForm as a,
|
|
127
|
-
|
|
188
|
+
MessageForm as b,
|
|
128
189
|
createModalForm as c,
|
|
129
|
-
|
|
130
|
-
|
|
190
|
+
createMessageForm as d,
|
|
191
|
+
textField as e,
|
|
192
|
+
dropdown as f,
|
|
193
|
+
divider as g,
|
|
194
|
+
header as h,
|
|
195
|
+
button as i,
|
|
196
|
+
label as l,
|
|
131
197
|
slider as s,
|
|
132
198
|
toggle as t
|
|
133
199
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Player } from '@minecraft/server';
|
|
2
|
-
import { ActionButton, FormComponent } from './types';
|
|
2
|
+
import { ActionButton, FormComponent, StatelessFormComponent } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* トグル
|
|
5
5
|
* @param opts
|
|
@@ -19,6 +19,7 @@ export declare function textField(opts: {
|
|
|
19
19
|
label: string;
|
|
20
20
|
placeholder?: string;
|
|
21
21
|
default?: string;
|
|
22
|
+
tooltip?: string;
|
|
22
23
|
handler?(player: Player, value: string): void;
|
|
23
24
|
}): FormComponent<string>;
|
|
24
25
|
/**
|
|
@@ -45,6 +46,22 @@ export declare function dropdown(opts: {
|
|
|
45
46
|
defaultIndex?: number;
|
|
46
47
|
handler?(player: Player, value: number): void;
|
|
47
48
|
}): FormComponent<number>;
|
|
49
|
+
/**
|
|
50
|
+
* ヘッダー
|
|
51
|
+
*/
|
|
52
|
+
export declare function header(opts: {
|
|
53
|
+
text: string;
|
|
54
|
+
}): StatelessFormComponent;
|
|
55
|
+
/**
|
|
56
|
+
* ラベル
|
|
57
|
+
*/
|
|
58
|
+
export declare function label(opts: {
|
|
59
|
+
text: string;
|
|
60
|
+
}): StatelessFormComponent;
|
|
61
|
+
/**
|
|
62
|
+
* Divider
|
|
63
|
+
*/
|
|
64
|
+
export declare function divider(): StatelessFormComponent;
|
|
48
65
|
/**
|
|
49
66
|
* ボタン (ActionForm)
|
|
50
67
|
* @param opts
|
|
@@ -3,5 +3,8 @@ interface DropdownProps {
|
|
|
3
3
|
options: string[];
|
|
4
4
|
defaultValueIndex?: number;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* ModalFormでドロップダウン選択を行えるコンポーネント
|
|
8
|
+
*/
|
|
6
9
|
export default function Dropdown({ label, options, defaultValueIndex, }: DropdownProps): import('../../types').FormComponent<number>;
|
|
7
10
|
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ActionForm as ActionFormType } from '../../actionForm';
|
|
2
|
+
import { MessageForm as MessageFormType } from '../../messageForm';
|
|
3
|
+
import { ModalForm as ModalFormType } from '../../modalForm';
|
|
4
|
+
import { Player } from '@minecraft/server';
|
|
5
|
+
interface MessageFormProps {
|
|
6
|
+
title: string;
|
|
7
|
+
children?: string[];
|
|
8
|
+
previousForm?: ActionFormType | MessageFormType | ModalFormType;
|
|
9
|
+
yesLabel: string;
|
|
10
|
+
noLabel: string;
|
|
11
|
+
onClickYes?: (player: Player) => void;
|
|
12
|
+
onClickNo?: (player: Player) => void;
|
|
13
|
+
}
|
|
14
|
+
declare const MessageForm: ({ title, children, previousForm, yesLabel, noLabel, onClickYes, onClickNo, }: MessageFormProps) => MessageFormType;
|
|
15
|
+
export default MessageForm;
|
|
@@ -5,9 +5,25 @@ import { FormComponent } from '../../types';
|
|
|
5
5
|
import { Player } from '@minecraft/server';
|
|
6
6
|
interface ModalFormProps<T = any> {
|
|
7
7
|
title: string;
|
|
8
|
+
submitButtonText?: string;
|
|
8
9
|
previousForm?: ModalFormType | ActionForm | MessageForm;
|
|
9
10
|
children?: FormComponent[];
|
|
10
11
|
onSubmit?: (player: Player, values?: T[] | undefined) => any;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
+
/**
|
|
14
|
+
* ユーザーからのテキストやその他の入力を受け取れるフォーム
|
|
15
|
+
*
|
|
16
|
+
* **使用例**
|
|
17
|
+
* ```tsx
|
|
18
|
+
* <ModalForm
|
|
19
|
+
* title="タイトル"
|
|
20
|
+
* onSubmit={handleSubmit}
|
|
21
|
+
* >
|
|
22
|
+
* <Textfield
|
|
23
|
+
* label="テキスト入力"
|
|
24
|
+
* />
|
|
25
|
+
* </ModalForm>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export default function ModalForm({ title, submitButtonText, previousForm, children, onSubmit, }: ModalFormProps): ModalFormType;
|
|
13
29
|
export {};
|
|
@@ -2,6 +2,10 @@ interface TextfieldProps {
|
|
|
2
2
|
label: string;
|
|
3
3
|
placeholder?: string;
|
|
4
4
|
defaultValue?: string;
|
|
5
|
+
tooltip?: string;
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* ModalFormでテキスト入力を行えるコンポーネント
|
|
9
|
+
*/
|
|
10
|
+
export default function Textfield({ label, placeholder, defaultValue, tooltip, }: TextfieldProps): import('../../types').FormComponent<string>;
|
|
7
11
|
export {};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { default as ActionForm } from './ActionForm';
|
|
2
|
+
import { default as MessageForm } from './MessageForm';
|
|
2
3
|
import { default as Button } from './Button';
|
|
3
4
|
import { default as ModalForm } from './ModalForm';
|
|
4
5
|
import { default as Slider } from './Slider';
|
|
5
6
|
import { default as Dropdown } from './Dropdown';
|
|
6
7
|
import { default as Textfield } from './Textfield';
|
|
7
8
|
import { default as Toggle } from './Toggle';
|
|
8
|
-
|
|
9
|
+
import { default as Header } from './Header';
|
|
10
|
+
import { default as Divider } from './Divider';
|
|
11
|
+
import { default as Label } from './Label';
|
|
12
|
+
export { ActionForm, Button, MessageForm, ModalForm, Slider, Dropdown, Textfield, Toggle, Header, Divider, Label, };
|
|
@@ -4,11 +4,19 @@ import { ActionForm } from './actionForm';
|
|
|
4
4
|
import { ModalForm } from './modalForm';
|
|
5
5
|
import { MessageForm } from './messageForm';
|
|
6
6
|
export interface FormComponent<T = any> {
|
|
7
|
+
type: string;
|
|
8
|
+
opts: object;
|
|
7
9
|
render(form: ModalFormData): void;
|
|
8
10
|
handle?(player: Player, value: T): void;
|
|
9
11
|
}
|
|
12
|
+
export interface StatelessFormComponent {
|
|
13
|
+
type: string;
|
|
14
|
+
opts?: object;
|
|
15
|
+
render(form: ModalFormData): void;
|
|
16
|
+
}
|
|
10
17
|
export interface ModalFormConfig<T = any> {
|
|
11
18
|
title: string;
|
|
19
|
+
submitButtonText?: string;
|
|
12
20
|
previousForm?: ModalForm | ActionForm | MessageForm;
|
|
13
21
|
components: FormComponent[];
|
|
14
22
|
handle?(player: Player, values?: T[] | undefined): void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare class TextFormat {
|
|
2
|
+
static readonly ESCAPE = "\u00A7";
|
|
3
|
+
static readonly EOL = "\n";
|
|
4
|
+
static readonly BLACK: string;
|
|
5
|
+
static readonly DARK_BLUE: string;
|
|
6
|
+
static readonly DARK_GREEN: string;
|
|
7
|
+
static readonly DARK_AQUA: string;
|
|
8
|
+
static readonly DARK_RED: string;
|
|
9
|
+
static readonly DARK_PURPLE: string;
|
|
10
|
+
static readonly GOLD: string;
|
|
11
|
+
static readonly GRAY: string;
|
|
12
|
+
static readonly DARK_GRAY: string;
|
|
13
|
+
static readonly BLUE: string;
|
|
14
|
+
static readonly GREEN: string;
|
|
15
|
+
static readonly AQUA: string;
|
|
16
|
+
static readonly RED: string;
|
|
17
|
+
static readonly LIGHT_PURPLE: string;
|
|
18
|
+
static readonly YELLOW: string;
|
|
19
|
+
static readonly WHITE: string;
|
|
20
|
+
static readonly MINECOIN_GOLD: string;
|
|
21
|
+
static readonly MATERIAL_QUARTZ: string;
|
|
22
|
+
static readonly MATERIAL_IRON: string;
|
|
23
|
+
static readonly MATERIAL_NETHERITE: string;
|
|
24
|
+
static readonly MATERIAL_REDSTONE: string;
|
|
25
|
+
static readonly MATERIAL_COPPER: string;
|
|
26
|
+
static readonly MATERIAL_GOLD: string;
|
|
27
|
+
static readonly MATERIAL_EMERALD: string;
|
|
28
|
+
static readonly MATERIAL_DIAMOND: string;
|
|
29
|
+
static readonly MATERIAL_LAPIS: string;
|
|
30
|
+
static readonly MATERIAL_AMETHYST: string;
|
|
31
|
+
static readonly MATERIAL_RESIN: string;
|
|
32
|
+
static readonly COLORS: Readonly<Record<string, string>>;
|
|
33
|
+
static readonly OBFUSCATED: string;
|
|
34
|
+
static readonly BOLD: string;
|
|
35
|
+
static readonly ITALIC: string;
|
|
36
|
+
static readonly FORMATS: Readonly<Record<string, string>>;
|
|
37
|
+
static readonly RESET: string;
|
|
38
|
+
static tokenize(input: string): string[];
|
|
39
|
+
static clean(input: string): string;
|
|
40
|
+
static colorize(input: string, placeholder?: string): string;
|
|
41
|
+
static addBase(baseFormat: string, input: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Converts Java formatting to Bedrock-compatible formatting
|
|
44
|
+
*/
|
|
45
|
+
static javaToBedrock(input: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Converts Minecraft formatting to HTML
|
|
48
|
+
*/
|
|
49
|
+
static toHTML(input: string): string;
|
|
50
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as createActionForm,
|
|
1
|
+
import { a as createActionForm, d as createMessageForm, i as button, c as createModalForm, s as slider, f as dropdown, e as textField, t as toggle, h as header, g as divider, l as label } from "../../components-avk6bHuS.js";
|
|
2
2
|
function ActionForm({
|
|
3
3
|
title,
|
|
4
4
|
body,
|
|
@@ -12,6 +12,31 @@ function ActionForm({
|
|
|
12
12
|
buttons: children
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
+
const MessageForm = ({
|
|
16
|
+
title,
|
|
17
|
+
children = [],
|
|
18
|
+
previousForm,
|
|
19
|
+
yesLabel,
|
|
20
|
+
noLabel,
|
|
21
|
+
onClickYes = () => {
|
|
22
|
+
},
|
|
23
|
+
onClickNo = () => {
|
|
24
|
+
}
|
|
25
|
+
}) => {
|
|
26
|
+
return createMessageForm({
|
|
27
|
+
title,
|
|
28
|
+
body: typeof children === "object" ? children.join("\n") : children,
|
|
29
|
+
previousForm,
|
|
30
|
+
yes: {
|
|
31
|
+
text: yesLabel,
|
|
32
|
+
handler: onClickYes
|
|
33
|
+
},
|
|
34
|
+
no: {
|
|
35
|
+
text: noLabel,
|
|
36
|
+
handler: onClickNo
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
};
|
|
15
40
|
function Button({
|
|
16
41
|
iconPath = "",
|
|
17
42
|
children = [],
|
|
@@ -26,6 +51,7 @@ function Button({
|
|
|
26
51
|
}
|
|
27
52
|
function ModalForm({
|
|
28
53
|
title,
|
|
54
|
+
submitButtonText,
|
|
29
55
|
previousForm,
|
|
30
56
|
children = [],
|
|
31
57
|
onSubmit = () => {
|
|
@@ -33,20 +59,21 @@ function ModalForm({
|
|
|
33
59
|
}) {
|
|
34
60
|
return createModalForm({
|
|
35
61
|
title,
|
|
62
|
+
submitButtonText,
|
|
36
63
|
previousForm,
|
|
37
64
|
components: children,
|
|
38
65
|
handle: onSubmit
|
|
39
66
|
});
|
|
40
67
|
}
|
|
41
68
|
function Slider({
|
|
42
|
-
label,
|
|
69
|
+
label: label2,
|
|
43
70
|
min,
|
|
44
71
|
max,
|
|
45
72
|
step,
|
|
46
73
|
defaultValue = min
|
|
47
74
|
}) {
|
|
48
75
|
return slider({
|
|
49
|
-
label,
|
|
76
|
+
label: label2,
|
|
50
77
|
min,
|
|
51
78
|
max,
|
|
52
79
|
step,
|
|
@@ -54,40 +81,53 @@ function Slider({
|
|
|
54
81
|
});
|
|
55
82
|
}
|
|
56
83
|
function Dropdown({
|
|
57
|
-
label,
|
|
84
|
+
label: label2,
|
|
58
85
|
options,
|
|
59
86
|
defaultValueIndex
|
|
60
87
|
}) {
|
|
61
88
|
return dropdown({
|
|
62
|
-
label,
|
|
89
|
+
label: label2,
|
|
63
90
|
options,
|
|
64
91
|
defaultIndex: defaultValueIndex
|
|
65
92
|
});
|
|
66
93
|
}
|
|
67
94
|
function Textfield({
|
|
68
|
-
label,
|
|
69
|
-
placeholder
|
|
70
|
-
defaultValue
|
|
95
|
+
label: label2,
|
|
96
|
+
placeholder,
|
|
97
|
+
defaultValue,
|
|
98
|
+
tooltip
|
|
71
99
|
}) {
|
|
72
100
|
return textField({
|
|
73
|
-
label,
|
|
101
|
+
label: label2,
|
|
74
102
|
placeholder,
|
|
75
|
-
default: defaultValue
|
|
103
|
+
default: defaultValue,
|
|
104
|
+
tooltip
|
|
76
105
|
});
|
|
77
106
|
}
|
|
78
107
|
function Toggle({
|
|
79
|
-
label,
|
|
108
|
+
label: label2,
|
|
80
109
|
defaultValue = false
|
|
81
110
|
}) {
|
|
82
111
|
return toggle({
|
|
83
|
-
label,
|
|
112
|
+
label: label2,
|
|
84
113
|
default: defaultValue
|
|
85
114
|
});
|
|
86
115
|
}
|
|
116
|
+
const Header = ({ text }) => {
|
|
117
|
+
return header({ text });
|
|
118
|
+
};
|
|
119
|
+
const Divider = () => divider();
|
|
120
|
+
const Label = ({ text }) => {
|
|
121
|
+
return label({ text });
|
|
122
|
+
};
|
|
87
123
|
export {
|
|
88
124
|
ActionForm,
|
|
89
125
|
Button,
|
|
126
|
+
Divider,
|
|
90
127
|
Dropdown,
|
|
128
|
+
Header,
|
|
129
|
+
Label,
|
|
130
|
+
MessageForm,
|
|
91
131
|
ModalForm,
|
|
92
132
|
Slider,
|
|
93
133
|
Textfield,
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { world, system } from "@minecraft/server";
|
|
2
|
-
import { A, M,
|
|
3
|
-
import { MessageFormData } from "@minecraft/server-ui";
|
|
2
|
+
import { A, b, M, i, a, d, c, g, f, h, l, s, e, t } from "./components-avk6bHuS.js";
|
|
4
3
|
class Keystone {
|
|
5
4
|
constructor() {
|
|
6
5
|
}
|
|
@@ -24,8 +23,8 @@ const _VLQDecoder = class _VLQDecoder {
|
|
|
24
23
|
const result = [];
|
|
25
24
|
let shift = 0;
|
|
26
25
|
let value = 0;
|
|
27
|
-
for (let
|
|
28
|
-
const digit = this.BASE64_CHARS.indexOf(str[
|
|
26
|
+
for (let i2 = 0; i2 < str.length; i2++) {
|
|
27
|
+
const digit = this.BASE64_CHARS.indexOf(str[i2]);
|
|
29
28
|
if (digit === -1) continue;
|
|
30
29
|
const continuation = (digit & 32) !== 0;
|
|
31
30
|
value += (digit & 31) << shift;
|
|
@@ -141,11 +140,10 @@ class SourceMapDebugger {
|
|
|
141
140
|
const output = [];
|
|
142
141
|
output.push("");
|
|
143
142
|
output.push(`${COLOR.yellow}━━━━━━━━━━━━━━━━━━━━━━${COLOR.reset}`);
|
|
144
|
-
output.push(`${COLOR.bold}${COLOR.cyan}📍 DEBUG${COLOR.reset}`);
|
|
145
143
|
let position = null;
|
|
146
144
|
const offset = this.sourceMap?._offset || 0;
|
|
147
|
-
for (let
|
|
148
|
-
const line = stackLines[
|
|
145
|
+
for (let i2 = 2; i2 < Math.min(stackLines.length, 8); i2++) {
|
|
146
|
+
const line = stackLines[i2];
|
|
149
147
|
const match = /(?:\()?(?:[A-Za-z0-9._/-]+):(\d+)(?::(\d+))?\)?$/.exec(line);
|
|
150
148
|
if (match) {
|
|
151
149
|
const rawLineNum = parseInt(match[1]);
|
|
@@ -157,17 +155,17 @@ class SourceMapDebugger {
|
|
|
157
155
|
}
|
|
158
156
|
if (position) {
|
|
159
157
|
const file = position.source;
|
|
160
|
-
output.push(`${COLOR.blue}
|
|
161
|
-
if (position.name) output.push(`${COLOR.cyan}
|
|
158
|
+
output.push(`${COLOR.blue}${file}:${position.line}:${position.column}${COLOR.reset}`);
|
|
159
|
+
if (position.name) output.push(`${COLOR.cyan}${position.name}${COLOR.reset}`);
|
|
162
160
|
if (position.content) {
|
|
163
161
|
const lines = position.content.split("\n");
|
|
164
162
|
const target = position.line - 1;
|
|
165
163
|
const range = 2;
|
|
166
164
|
output.push(`${COLOR.gray}─────────────────────${COLOR.reset}`);
|
|
167
|
-
for (let
|
|
168
|
-
const num = `${(
|
|
169
|
-
const content = lines[
|
|
170
|
-
if (
|
|
165
|
+
for (let i2 = Math.max(0, target - range); i2 <= Math.min(lines.length - 1, target + range); i2++) {
|
|
166
|
+
const num = `${(i2 + 1).toString().padStart(3, " ")}`;
|
|
167
|
+
const content = lines[i2];
|
|
168
|
+
if (i2 === target) {
|
|
171
169
|
output.push(`${COLOR.red}${COLOR.bold}→ ${num}: ${COLOR.white}${content}${COLOR.reset}`);
|
|
172
170
|
} else {
|
|
173
171
|
output.push(`${COLOR.gray} ${num}: ${content}${COLOR.reset}`);
|
|
@@ -175,11 +173,11 @@ class SourceMapDebugger {
|
|
|
175
173
|
}
|
|
176
174
|
}
|
|
177
175
|
} else {
|
|
178
|
-
output.push(`${COLOR.gray}
|
|
176
|
+
output.push(`${COLOR.gray}Location: (source map not available)${COLOR.reset}`);
|
|
179
177
|
}
|
|
180
178
|
output.push(`${COLOR.gray}─────────────────────${COLOR.reset}`);
|
|
181
|
-
output.push(`${COLOR.bold}${COLOR.white}
|
|
182
|
-
args.forEach((arg,
|
|
179
|
+
output.push(`${COLOR.bold}${COLOR.white}Values:${COLOR.reset}`);
|
|
180
|
+
args.forEach((arg, i2) => {
|
|
183
181
|
let val;
|
|
184
182
|
if (arg === void 0) val = "undefined";
|
|
185
183
|
else if (arg === null) val = "null";
|
|
@@ -194,7 +192,7 @@ class SourceMapDebugger {
|
|
|
194
192
|
} else {
|
|
195
193
|
val = String(arg);
|
|
196
194
|
}
|
|
197
|
-
output.push(`${COLOR.green}[${
|
|
195
|
+
output.push(`${COLOR.green}[${i2}]:${COLOR.reset} ${val}`);
|
|
198
196
|
});
|
|
199
197
|
output.push(`${COLOR.yellow}━━━━━━━━━━━━━━━━━━━━━━${COLOR.reset}`);
|
|
200
198
|
console.log(output.join("\n"));
|
|
@@ -1041,50 +1039,32 @@ function waitUntil(condition, opts) {
|
|
|
1041
1039
|
});
|
|
1042
1040
|
});
|
|
1043
1041
|
}
|
|
1044
|
-
class MessageForm {
|
|
1045
|
-
constructor(config) {
|
|
1046
|
-
this.config = config;
|
|
1047
|
-
}
|
|
1048
|
-
async send(player) {
|
|
1049
|
-
const form = new MessageFormData().title(this.config.title).body(this.config.body).button1(this.config.yes.text).button2(this.config.no.text);
|
|
1050
|
-
const res = await form.show(player);
|
|
1051
|
-
if (res.canceled) {
|
|
1052
|
-
this.config.previousForm?.send(player);
|
|
1053
|
-
return;
|
|
1054
|
-
}
|
|
1055
|
-
if (res.selection === 0) {
|
|
1056
|
-
this.config.yes.handler(player);
|
|
1057
|
-
} else if (res.selection === 1) {
|
|
1058
|
-
this.config.no.handler(player);
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
function createMessageForm(config) {
|
|
1063
|
-
return new MessageForm(config);
|
|
1064
|
-
}
|
|
1065
1042
|
export {
|
|
1066
1043
|
A as ActionForm,
|
|
1067
1044
|
AxisAlignedBB,
|
|
1068
1045
|
DelayedTimer,
|
|
1069
1046
|
EventManager,
|
|
1070
|
-
MessageForm,
|
|
1047
|
+
b as MessageForm,
|
|
1071
1048
|
M as ModalForm,
|
|
1072
1049
|
Priority,
|
|
1073
1050
|
RepeatingTimer,
|
|
1074
1051
|
UntilTimer,
|
|
1075
1052
|
Vector3,
|
|
1076
|
-
|
|
1053
|
+
i as button,
|
|
1077
1054
|
a as createActionForm,
|
|
1078
|
-
createMessageForm,
|
|
1055
|
+
d as createMessageForm,
|
|
1079
1056
|
c as createModalForm,
|
|
1080
1057
|
debug,
|
|
1081
1058
|
delayed,
|
|
1082
|
-
|
|
1059
|
+
g as divider,
|
|
1060
|
+
f as dropdown,
|
|
1061
|
+
h as header,
|
|
1083
1062
|
keystone,
|
|
1063
|
+
l as label,
|
|
1084
1064
|
repeating,
|
|
1085
1065
|
sleep,
|
|
1086
1066
|
s as slider,
|
|
1087
|
-
|
|
1067
|
+
e as textField,
|
|
1088
1068
|
t as toggle,
|
|
1089
1069
|
until,
|
|
1090
1070
|
waitUntil
|
|
@@ -1,4 +1,34 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
+
type ManifestStub = {
|
|
3
|
+
format_version?: number;
|
|
4
|
+
header?: {
|
|
5
|
+
name?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
uuid?: string;
|
|
8
|
+
version?: number[];
|
|
9
|
+
min_engine_version?: number[];
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
};
|
|
12
|
+
modules?: Array<{
|
|
13
|
+
description?: string;
|
|
14
|
+
type?: string;
|
|
15
|
+
language?: string;
|
|
16
|
+
uuid?: string;
|
|
17
|
+
version?: number[];
|
|
18
|
+
entry?: string;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}>;
|
|
21
|
+
dependencies?: Array<{
|
|
22
|
+
module_name?: string;
|
|
23
|
+
version?: string;
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
}>;
|
|
26
|
+
metadata?: {
|
|
27
|
+
authors?: string[];
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
};
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
};
|
|
2
32
|
type PluginConfig = {
|
|
3
33
|
name: string;
|
|
4
34
|
uuid?: string;
|
|
@@ -6,6 +36,7 @@ type PluginConfig = {
|
|
|
6
36
|
authors?: string[];
|
|
7
37
|
version?: number[];
|
|
8
38
|
embedSourceMap?: boolean;
|
|
39
|
+
manifest?: ManifestStub;
|
|
9
40
|
};
|
|
10
|
-
declare const behaviorPacker: ({ name, uuid, description, authors, version, embedSourceMap, }?: PluginConfig) => Plugin;
|
|
41
|
+
declare const behaviorPacker: ({ name, uuid, description, authors, version, embedSourceMap, manifest: manifestOverride, }?: PluginConfig) => Plugin;
|
|
11
42
|
export default behaviorPacker;
|
|
@@ -1,13 +1,50 @@
|
|
|
1
|
-
import { resolve } from "path";
|
|
1
|
+
import { resolve, relative } from "path";
|
|
2
2
|
import * as crypto from "node:crypto";
|
|
3
3
|
import * as fs from "node:fs";
|
|
4
|
+
const mergeArrayByKey = (target, source, key) => {
|
|
5
|
+
const result = [...target];
|
|
6
|
+
for (const sourceItem of source) {
|
|
7
|
+
const keyValue = sourceItem[key];
|
|
8
|
+
const existingIndex = result.findIndex((item) => item[key] === keyValue);
|
|
9
|
+
if (existingIndex >= 0) {
|
|
10
|
+
result[existingIndex] = { ...result[existingIndex], ...sourceItem };
|
|
11
|
+
} else {
|
|
12
|
+
result.push(sourceItem);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
17
|
+
const ARRAY_MERGE_KEYS = {
|
|
18
|
+
dependencies: "module_name",
|
|
19
|
+
modules: "type"
|
|
20
|
+
};
|
|
21
|
+
const deepMerge = (target, source) => {
|
|
22
|
+
const result = { ...target };
|
|
23
|
+
for (const key in source) {
|
|
24
|
+
const sourceValue = source[key];
|
|
25
|
+
const targetValue = target[key];
|
|
26
|
+
if (Array.isArray(sourceValue) && Array.isArray(targetValue) && ARRAY_MERGE_KEYS[key]) {
|
|
27
|
+
result[key] = mergeArrayByKey(
|
|
28
|
+
targetValue,
|
|
29
|
+
sourceValue,
|
|
30
|
+
ARRAY_MERGE_KEYS[key]
|
|
31
|
+
);
|
|
32
|
+
} else if (sourceValue && typeof sourceValue === "object" && !Array.isArray(sourceValue) && targetValue && typeof targetValue === "object" && !Array.isArray(targetValue)) {
|
|
33
|
+
result[key] = deepMerge(targetValue, sourceValue);
|
|
34
|
+
} else if (sourceValue !== void 0) {
|
|
35
|
+
result[key] = sourceValue;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
4
40
|
const behaviorPacker = ({
|
|
5
41
|
name = "my first plugin",
|
|
6
42
|
uuid,
|
|
7
43
|
description = "",
|
|
8
44
|
authors = [],
|
|
9
45
|
version = [1, 0, 0],
|
|
10
|
-
embedSourceMap = true
|
|
46
|
+
embedSourceMap = true,
|
|
47
|
+
manifest: manifestOverride
|
|
11
48
|
} = {
|
|
12
49
|
name: "my first plugin",
|
|
13
50
|
description: "",
|
|
@@ -28,7 +65,8 @@ const behaviorPacker = ({
|
|
|
28
65
|
external: [
|
|
29
66
|
"@minecraft/server",
|
|
30
67
|
"@minecraft/server-net",
|
|
31
|
-
"@minecraft/server-ui"
|
|
68
|
+
"@minecraft/server-ui",
|
|
69
|
+
"@minecraft/server-admin"
|
|
32
70
|
],
|
|
33
71
|
input: {
|
|
34
72
|
index: resolve(process.cwd(), "./src/index.ts")
|
|
@@ -42,9 +80,14 @@ const behaviorPacker = ({
|
|
|
42
80
|
for (const [, file] of Object.entries(bundle)) {
|
|
43
81
|
if (file.type === "chunk" && file.map) {
|
|
44
82
|
const sourceMapData = file.map;
|
|
83
|
+
const projectRoot = process.cwd();
|
|
84
|
+
const outputDir = resolve(projectRoot, options.dir || "dist/behavior_pack/scripts");
|
|
45
85
|
const embeddedSourceMap = {
|
|
46
86
|
version: sourceMapData.version,
|
|
47
|
-
sources: sourceMapData.sources
|
|
87
|
+
sources: sourceMapData.sources.map((source) => {
|
|
88
|
+
const absolutePath = resolve(outputDir, source);
|
|
89
|
+
return relative(projectRoot, absolutePath);
|
|
90
|
+
}),
|
|
48
91
|
sourcesContent: sourceMapData.sourcesContent,
|
|
49
92
|
mappings: sourceMapData.mappings,
|
|
50
93
|
names: sourceMapData.names,
|
|
@@ -109,7 +152,8 @@ globalThis.__SOURCE_MAP__ = ${JSON.stringify(embeddedSourceMap)};
|
|
|
109
152
|
"authors": authors
|
|
110
153
|
}
|
|
111
154
|
};
|
|
112
|
-
|
|
155
|
+
const finalManifest = manifestOverride ? deepMerge(manifestStub, manifestOverride) : manifestStub;
|
|
156
|
+
fs.writeFileSync("./dist/behavior_pack/manifest.json", JSON.stringify(finalManifest, null, 2));
|
|
113
157
|
}
|
|
114
158
|
});
|
|
115
159
|
const supportJsx = () => ({
|