Skip to content

Commit 8476411

Browse files
Editor v0.4 Update (#274)
* add editor module in dependencies * Delete scripts/editor-extensions directory * wqergtbjlk;p * Fix tsconfig * e * Update cl.yml Recursive * Update cl.yml * update vanilla data bundle to v1.20.20 * qwqwDEFV * tsconfig again --------- Co-authored-by: xKingDark <[email protected]>
1 parent c6f8fb5 commit 8476411

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+610
-4875
lines changed

Diff for: .github/workflows/cl.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ jobs:
2424
find ./docs/* -maxdepth 5 -name package.json -execdir sh -c 'pwd && npm install' \;
2525
2626
- name: Type Check
27-
run: tsc --build --verbose
27+
run: |
28+
tsc --build --verbose
29+
cp -r dist/* .
2830
2931
- name: Format Check
30-
run: node ./tools/index.js
32+
run: node ./dist/tools/index.js
3133
env:
3234
event_name: ${{ github.event_name }}
3335

Diff for: .github/workflows/dependency-update.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424

2525
- name: Update dependency
2626
id: update
27-
run: node ./tools/dependency.js
27+
run: node ./dist/tools/dependency.js
2828

2929
- name: Create Pull Request
3030
id: cpr

Diff for: .gitignore

+122-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
# Dependency directories
2-
node_modules/
3-
4-
# Tools build files
5-
tools/**/*.js
6-
tools/**/*.js.map
7-
tools/**/*.d.ts
8-
91
# Logs
102
logs
113
*.log
@@ -15,5 +7,127 @@ yarn-error.log*
157
lerna-debug.log*
168
.pnpm-debug.log*
179

10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
1848
# TypeScript cache
1949
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
.cache
106+
107+
# Docusaurus cache and generated files
108+
.docusaurus
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# TernJS port file
120+
.tern-port
121+
122+
# Stores VSCode versions used for testing VSCode extensions
123+
.vscode-test
124+
125+
# yarn v2
126+
.yarn/cache
127+
.yarn/unplugged
128+
.yarn/build-state.yml
129+
.yarn/install-state.gz
130+
.pnp.*
131+
132+
# scriptapi
133+
tools/*.js
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: scripts/editor-fullbright/tests.ts renamed to editorExtensions/editor-fullbright/tests.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@ registerEditorExtension('nightVision', (uiSession) => {
1919
uiSession.toolRail.show();
2020
// Add selection functionality
2121
new FullbrightToggle(uiSession, createMenu(uiSession));
22-
})
22+
return [
23+
{
24+
teardown() {
25+
this.uiSession.log.debug("Shutting down FullbrightToggle behavior\n");
26+
}
27+
}
28+
];
29+
}, () => {});
File renamed without changes.
File renamed without changes.

Diff for: scripts/editor-random-fill/index.ts renamed to editorExtensions/editor-random-fill/index.ts

+45-35
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import {
1616
KeyboardKey,
1717
IPlayerUISession,
18-
MouseRay,
18+
Ray,
1919
IModalTool,
2020
Action,
2121
ActionTypes,
@@ -32,7 +32,10 @@ import {
3232
IPropertyPane,
3333
IPropertyItem,
3434
ExtensionContext,
35-
CursorProperties
35+
CursorProperties,
36+
PropertyBag,
37+
RegisteredAction,
38+
NoArgsAction
3639
} from "@minecraft/server-editor";
3740
import {
3841
getRotationCorrectedDirectionVector,
@@ -65,7 +68,7 @@ const Controls = {
6568
Clear: KeyboardKey.KEY_D,
6669
};
6770

68-
interface SettingsObject {
71+
interface SettingsObject extends PropertyBag {
6972
origin: Vector3;
7073
size: Vector3;
7174
block: BlockType;
@@ -78,7 +81,7 @@ export class SelectionBehavior {
7881
tool: IModalTool;
7982
uiSession: IPlayerUISession;
8083
fnUnregisterToolBindings: () => void;
81-
singleClick: (uiSession: IPlayerUISession, mouseRay: MouseRay, shiftPressed: boolean, ctrlPressed: boolean, altPressed: boolean) => void;
84+
singleClick: (uiSession: IPlayerUISession, mouseRay: Ray, shiftPressed: boolean, ctrlPressed: boolean, altPressed: boolean) => void;
8285
lastAnchorPosition: Vector3;
8386
moveTopSelection: (uiSession: IPlayerUISession, lastAnchor: Vector3, direction: Direction) => Vector3;
8487
moveBlockCursorManually: (uiSession: IPlayerUISession, direction: Direction) => void;
@@ -90,14 +93,14 @@ export class SelectionBehavior {
9093
onTickRefresh: (uiSession: IPlayerUISession, tool: IModalTool) => void;
9194
tickRefreshHandle: number;
9295
settingsObject: SettingsObject;
93-
originPropertyItem: IPropertyItem;
94-
sizePropertyItem: IPropertyItem;
96+
originPropertyItem: IPropertyItem<SettingsObject, 'origin'>;
97+
sizePropertyItem: IPropertyItem<SettingsObject, 'size'>;
9598
addSettingsPane: (uiSession: IPlayerUISession) => void;
9699
pane: IPropertyPane;
97100
addTool: (uiSession: IPlayerUISession) => IModalTool;
98101
bindGlobalActivationShortcut: (uiSession: IPlayerUISession, storage: Record<string, any>) => void;
99102
performFillOperation: (context: ExtensionContext, fillType: BlockType) => Promise<void>;
100-
executeFillAction: Action<ActionTypes.NoArgsAction>;
103+
executeFillAction: RegisteredAction<NoArgsAction>;
101104
get toolId() {
102105
return this.tool.id;
103106
}
@@ -106,7 +109,7 @@ export class SelectionBehavior {
106109
this.fnUnregisterToolBindings = () => {
107110
this.tool.unregisterInputBindings();
108111
};
109-
this.singleClick = (uiSession: IPlayerUISession, mouseRay: MouseRay, shiftPressed: boolean, ctrlPressed: boolean, altPressed: boolean) => {
112+
this.singleClick = (uiSession: IPlayerUISession, mouseRay: Ray, shiftPressed: boolean, ctrlPressed: boolean, altPressed: boolean) => {
110113
const clickLoc = mouseRay.cursorBlockLocation;
111114
// Nothing pressed, then clear the stack and create a single 1x1x1
112115
if (!shiftPressed && !ctrlPressed && !altPressed) {
@@ -685,13 +688,11 @@ export class SelectionBehavior {
685688
value: SelectionCursorMode.AdjacentFace,
686689
},
687690
],
688-
onChange: (_obj, _property, _oldValue, _newValue) => {
689-
const oldVal = _oldValue;
690-
const newVal = _newValue;
691+
onChange: (_obj, _property, _oldValue: any, _newValue: any) => {
691692
let cursorControlMode = CursorControlMode.KeyboardAndMouse;
692693
let cursorTargetMode = CursorTargetMode.Block;
693-
if (oldVal !== newVal) {
694-
switch (newVal) {
694+
if (_oldValue !== _newValue) {
695+
switch (_newValue) {
695696
case SelectionCursorMode.Freeform:
696697
cursorControlMode = CursorControlMode.KeyboardAndMouse;
697698
cursorTargetMode = CursorTargetMode.Block;
@@ -775,7 +776,7 @@ export class SelectionBehavior {
775776
titleStringId: getLocalizationId('selectionTool.fillPane.title'),
776777
titleAltText: 'Fill Selection',
777778
});
778-
const blockPickers: IPropertyItem[] = [];
779+
const blockPickers: IPropertyItem<SettingsObject, 'block'>[] = [];
779780
subPaneFill.addNumber(bindDataSource(subPaneFill, {
780781
size: 1,
781782
}), 'size', {
@@ -784,26 +785,26 @@ export class SelectionBehavior {
784785
min: 1,
785786
max: 16,
786787
showSlider: true,
787-
onChange: async (_obj, _property, _oldValue, _newValue) => {
788-
console.warn(_property, _oldValue, _newValue, blockPickers.length);
789-
while (blockPickers.length < _newValue) {
790-
await null; // using await null in an async function to avoid making the server hangs
791-
792-
blockPickers.push(subPaneFill.addBlockPicker(this.settingsObject, 'block', {
793-
titleAltText: 'Block Type',
794-
allowedBlocks
795-
}));
796-
}
797-
while (blockPickers.length > _newValue) {
798-
await null; // using await null in an async function to avoid making the server hangs
799-
800-
const lastBlockPicker = blockPickers[blockPickers.length - 1];
801-
lastBlockPicker.visible = false;
802-
lastBlockPicker.enable = false;
803-
lastBlockPicker.dispose();
804-
blockPickers.pop();
788+
onChange: (_obj, _property, _oldValue: any, _newValue: any) => {
789+
function adjustBlockPickers() {
790+
if (blockPickers.length < _newValue) {
791+
blockPickers.push(subPaneFill.addBlockPicker(this.settingsObject, 'block', {
792+
titleAltText: 'Block Type',
793+
allowedBlocks
794+
}));
795+
} else if (blockPickers.length > _newValue) {
796+
const lastBlockPicker = blockPickers[blockPickers.length - 1];
797+
lastBlockPicker.visible = false;
798+
lastBlockPicker.enable = false;
799+
lastBlockPicker.dispose();
800+
blockPickers.pop();
801+
}
802+
803+
if (blockPickers.length === _newValue) {
804+
system.clearRun(id);
805+
}
805806
}
806-
subPaneFill.update(true);
807+
const id = system.runInterval(adjustBlockPickers);
807808
},
808809
});
809810
subPaneFill.addButton(this.executeFillAction, {
@@ -828,7 +829,7 @@ export class SelectionBehavior {
828829
// Add a modal tool to the tool rail and set up an activation subscription to set/unset the cursor states
829830
this.addTool = (uiSession: IPlayerUISession) => {
830831
const tool = uiSession.toolRail.addTool({
831-
displayStringId: 'Random Fill (CTRL + S)',
832+
displayAltText: 'Random Fill (CTRL + S)',
832833
icon: 'pack://textures/editor/Select-Fill.png?filtering=point',
833834
tooltipStringId: 'Random Fill Tool',
834835
});
@@ -896,6 +897,7 @@ export class SelectionBehavior {
896897
// Create pane.
897898
this.pane = uiSession.createPropertyPane({
898899
titleAltText: 'Random Fill',
900+
titleStringId: getLocalizationId('selectionTool.title'),
899901
});
900902
/**
901903
* Allowed blocks for the block picker
@@ -948,5 +950,13 @@ registerEditorExtension('randomFill', (uiSession) => {
948950
// Initialize tool rail.
949951
uiSession.toolRail.show();
950952
// Add selection functionality
951-
new SelectionBehavior(uiSession);
953+
return [
954+
new SelectionBehavior(uiSession)
955+
]
956+
}, (uiSession) => {
957+
uiSession.log.info('Shutting down minecraft::selection behavior');
958+
// Shutdown
959+
uiSession.scratchStorage = undefined;
960+
}, {
961+
description: 'Randomly fills blocks in the selection',
952962
});
File renamed without changes.
File renamed without changes.

Diff for: scripts/editor-utilities/index.js renamed to editorExtensions/editor-utilities/index.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Script example for ScriptAPI
2-
// Author: Mojang <https://github.com/Mojang>
2+
// Author: Mojang's Editor Team <https://github.com/Mojang>
33
// Project: https://github.com/DarkGamerYT/Bedrock-Editor-Extension
4-
import * as _minecraft_server_wrapper__WEBPACK_IMPORTED_MODULE_0__ from '@minecraft/server'
4+
import { Vector } from '@minecraft/server';
5+
56

67
/**
78
* Direction
@@ -26,12 +27,12 @@ var Direction = {
2627
* it down. I blame Tom's dodgy code, tbh.
2728
*/
2829
const directionLookup = {
29-
[Direction.Forward]: _minecraft_server_wrapper__WEBPACK_IMPORTED_MODULE_0__.Vector.forward,
30-
[Direction.Right]: _minecraft_server_wrapper__WEBPACK_IMPORTED_MODULE_0__.Vector.left,
31-
[Direction.Back]: _minecraft_server_wrapper__WEBPACK_IMPORTED_MODULE_0__.Vector.back,
32-
[Direction.Left]: _minecraft_server_wrapper__WEBPACK_IMPORTED_MODULE_0__.Vector.right,
33-
[Direction.Up]: _minecraft_server_wrapper__WEBPACK_IMPORTED_MODULE_0__.Vector.up,
34-
[Direction.Down]: _minecraft_server_wrapper__WEBPACK_IMPORTED_MODULE_0__.Vector.down,
30+
[Direction.Forward]: Vector.forward,
31+
[Direction.Right]: Vector.left,
32+
[Direction.Back]: Vector.back,
33+
[Direction.Left]: Vector.right,
34+
[Direction.Up]: Vector.up,
35+
[Direction.Down]: Vector.down,
3536
};
3637
/**
3738
* getRotationCorrectedDirection
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)