@kradle/challenges-sdk 0.22.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -1
- package/LLM_README.md +54 -15
- package/README.md +20 -2
- package/dist/engine.d.ts +2 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +4 -1
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime/builder.d.ts.map +1 -1
- package/dist/runtime/builder.js +26 -6
- package/dist/runtime/builder.js.map +1 -1
- package/dist/runtime/dimensions.d.ts +24 -0
- package/dist/runtime/dimensions.d.ts.map +1 -0
- package/dist/runtime/dimensions.js +47 -0
- package/dist/runtime/dimensions.js.map +1 -0
- package/dist/runtime/reducer.d.ts.map +1 -1
- package/dist/runtime/reducer.js +98 -29
- package/dist/runtime/reducer.js.map +1 -1
- package/dist/runtime/types.d.ts +56 -6
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/types.js.map +1 -1
- package/dist/runtime/wire.d.ts +33 -2
- package/dist/runtime/wire.d.ts.map +1 -1
- package/dist/runtime/wire.js +2 -0
- package/dist/runtime/wire.js.map +1 -1
- package/dist/runtime/world.d.ts +87 -4
- package/dist/runtime/world.d.ts.map +1 -1
- package/dist/runtime/world.js +288 -23
- package/dist/runtime/world.js.map +1 -1
- package/dist/structures.d.ts.map +1 -1
- package/dist/structures.js +3 -1
- package/dist/structures.js.map +1 -1
- package/dist/test/harness.d.ts +13 -2
- package/dist/test/harness.d.ts.map +1 -1
- package/dist/test/harness.js +44 -9
- package/dist/test/harness.js.map +1 -1
- package/dist/test/helpers.d.ts.map +1 -1
- package/dist/test/helpers.js +2 -1
- package/dist/test/helpers.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/runtime/reducer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/runtime/reducer.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAe,KAAK,UAAU,EAAqC,MAAM,aAAa,CAAC;AAE9F,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAW,MAAM,WAAW,CAAC;AAC/D,OAAO,KAAK,EAEX,SAAS,EACT,UAAU,EACV,eAAe,EAGf,QAAQ,EAIR,OAAO,EACP,SAAS,EAGT,SAAS,EAET,KAAK,EACL,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EACX,MAAM,EACN,OAAO,EACP,GAAG,EACH,UAAU,EAIV,MAAM,EACN,SAAS,EACT,KAAK,EACL,MAAM,EACN,SAAS,EACT,IAAI,EAIJ,eAAe,EAEf,MAAM,EAEN,IAAI,EACJ,MAAM,WAAW,CAAC;AACnB,OAAO,EAUN,KAAK,SAAS,EAed,KAAK,UAAU,EAKf,MAAM,YAAY,CAAC;AAIpB,yEAAyE;AACzE,eAAO,MAAM,iBAAiB,OAAO,CAAC;AACtC,uEAAuE;AACvE,eAAO,MAAM,eAAe,QAAQ,CAAC;AACrC,uEAAuE;AACvE,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAK3C,wDAAwD;AACxD,MAAM,MAAM,WAAW,GAAG,QAAQ,CACjC,eAAe,EACf,OAAO,EACP,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACtB,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CACrB,CAAC;AAEF,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAC7C,MAAM,MAAM,YAAY,GAAG,SAAS,CACnC,eAAe,EACf,OAAO,EACP,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACtB,MAAM,EACN,MAAM,EACN,MAAM,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MAAM,CAAC;QAChB,kDAAkD;QAClD,YAAY,EAAE,MAAM,CAAC;KACrB,GAAG,IAAI,CAAC;CACT;AA2CD,oGAAoG;AACpG,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAgC7D;AAeD,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAS1D;AAED,8DAA8D;AAC9D,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAKxD;AAyDD,iFAAiF;AACjF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,CAqB1D;AAmKD,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG;IAC/C,IAAI,EAAE,MAAM,KAAK,CAAC;IAClB,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,KAAK;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CAC5E,CA87DA"}
|
package/dist/runtime/reducer.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_ACHIEVEMENTS = exports.MAX_TRANSITIONS_PER_EVENT = exports.MAX_FILL_VOLUME = exports.MAX_BATCH_EFFECTS = void 0;
|
|
4
|
+
exports.assertJson = assertJson;
|
|
5
|
+
exports.parseBlockState = parseBlockState;
|
|
6
|
+
exports.blockSpecString = blockSpecString;
|
|
7
|
+
exports.splitBatches = splitBatches;
|
|
8
|
+
exports.createReducer = createReducer;
|
|
9
|
+
const dimensions_js_1 = require("./dimensions.js");
|
|
2
10
|
// The reducer: one locked definition, one `init()` per run, one `reduce(state,
|
|
3
11
|
// event)` per engine event. Everything a rule sees comes through a context
|
|
4
12
|
// built for the reduction; everything a rule asks for leaves as actions.
|
|
@@ -15,15 +23,8 @@
|
|
|
15
23
|
// the game-over hook, the judge data, `game_over`.
|
|
16
24
|
// - An author error rolls the reduction back and ends the run as
|
|
17
25
|
// `error_challenge` without another author callback.
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.MAX_ACHIEVEMENTS = exports.MAX_TRANSITIONS_PER_EVENT = exports.MAX_FILL_VOLUME = exports.MAX_BATCH_EFFECTS = void 0;
|
|
20
|
-
exports.assertJson = assertJson;
|
|
21
|
-
exports.parseBlockState = parseBlockState;
|
|
22
|
-
exports.blockSpecString = blockSpecString;
|
|
23
|
-
exports.splitBatches = splitBatches;
|
|
24
|
-
exports.createReducer = createReducer;
|
|
25
|
-
const dialog_js_1 = require("./dialog.js");
|
|
26
26
|
const chat_js_1 = require("./chat.js");
|
|
27
|
+
const dialog_js_1 = require("./dialog.js");
|
|
27
28
|
const errors_js_1 = require("./errors.js");
|
|
28
29
|
const time_js_1 = require("./time.js");
|
|
29
30
|
const types_js_1 = require("./types.js");
|
|
@@ -103,7 +104,7 @@ function deepFreeze(value, seen = new WeakSet()) {
|
|
|
103
104
|
for (const x of Object.values(value))
|
|
104
105
|
deepFreeze(x, seen);
|
|
105
106
|
}
|
|
106
|
-
const posKey =
|
|
107
|
+
const posKey = dimensions_js_1.positionKey;
|
|
107
108
|
/** `minecraft:oak_stairs[facing=east,half=bottom]` -> `{ id, props }`. */
|
|
108
109
|
function parseBlockState(state) {
|
|
109
110
|
const i = state.indexOf("[");
|
|
@@ -338,6 +339,7 @@ function viewOf(r, p) {
|
|
|
338
339
|
}
|
|
339
340
|
function createReducer(def) {
|
|
340
341
|
const config = def.config;
|
|
342
|
+
const dimensions = (0, dimensions_js_1.enabledDimensions)(config.challengeConfig?.dimensions);
|
|
341
343
|
const roleNames = Object.keys(config.roles);
|
|
342
344
|
const declaredZones = Object.keys(def.zones);
|
|
343
345
|
const derivedScores = def.outcome.scores !== undefined;
|
|
@@ -488,6 +490,21 @@ function createReducer(def) {
|
|
|
488
490
|
}
|
|
489
491
|
};
|
|
490
492
|
const push = (raw) => {
|
|
493
|
+
for (const value of [
|
|
494
|
+
raw,
|
|
495
|
+
...["at", "from", "to", "dest"].map((key) => raw[key]),
|
|
496
|
+
]) {
|
|
497
|
+
if (value &&
|
|
498
|
+
typeof value === "object" &&
|
|
499
|
+
"dimension" in value &&
|
|
500
|
+
value.dimension !== undefined &&
|
|
501
|
+
!dimensions.includes(value.dimension))
|
|
502
|
+
throw (0, errors_js_1.apiError)("invalid_value", "The target dimension is disabled");
|
|
503
|
+
}
|
|
504
|
+
if (raw.kind === "fill" || raw.kind === "clone")
|
|
505
|
+
(0, world_js_1.bounds)({ from: raw.from, to: raw.to });
|
|
506
|
+
if (raw.kind === "clone" && (0, dimensions_js_1.dimensionOf)(raw.from) !== (0, dimensions_js_1.dimensionOf)(raw.dest))
|
|
507
|
+
throw (0, errors_js_1.apiError)("invalid_value", "A clone cannot cross dimensions");
|
|
491
508
|
// A plain copy: an author's argument may be a view (`p.pos`, `g.params.box`).
|
|
492
509
|
const effect = compact(snapshot(raw));
|
|
493
510
|
if (r.batch)
|
|
@@ -580,6 +597,7 @@ function createReducer(def) {
|
|
|
580
597
|
throw (0, errors_js_1.notDeclared)("zones", zone, declaredZones);
|
|
581
598
|
return p.zones.includes(zone);
|
|
582
599
|
}
|
|
600
|
+
(0, world_js_1.bounds)(zone);
|
|
583
601
|
return p.pos !== null && (0, world_js_1.inBox)(p.pos, zone);
|
|
584
602
|
},
|
|
585
603
|
countItems(p, match) {
|
|
@@ -617,11 +635,13 @@ function createReducer(def) {
|
|
|
617
635
|
get worldTime() {
|
|
618
636
|
return s.world.time;
|
|
619
637
|
},
|
|
638
|
+
dimensionTime: (dimension) => (dimension === dimensions_js_1.OVERWORLD ? s.world.time : s.world.times?.[dimension]),
|
|
620
639
|
entities: (filter) => (0, world_js_1.entitiesIn)(s.world, filter).map(world_js_1.freezeObservation),
|
|
621
640
|
entity(id) {
|
|
622
641
|
const e = s.world.entities[id];
|
|
623
642
|
return e ? (0, world_js_1.freezeObservation)(e) : undefined;
|
|
624
643
|
},
|
|
644
|
+
blockNbt: (at) => s.world.blockNbt[posKey(at)],
|
|
625
645
|
containerContents(at) {
|
|
626
646
|
const c = s.containers[posKey(at)];
|
|
627
647
|
return c ? countsOf(c.slots) : undefined;
|
|
@@ -825,17 +845,17 @@ function createReducer(def) {
|
|
|
825
845
|
write("summon");
|
|
826
846
|
push({ kind: "summon", entity, at: { ...at }, nbt: opts?.nbt });
|
|
827
847
|
},
|
|
828
|
-
killEntities(entities) {
|
|
848
|
+
killEntities(entities, dimension) {
|
|
829
849
|
write("killEntities");
|
|
830
|
-
push({ kind: "kill_entities", entities });
|
|
850
|
+
push({ kind: "kill_entities", entities, dimension });
|
|
831
851
|
},
|
|
832
|
-
time(value) {
|
|
852
|
+
time(value, dimension) {
|
|
833
853
|
write("time");
|
|
834
|
-
push({ kind: "time", value });
|
|
854
|
+
push({ kind: "time", value, dimension });
|
|
835
855
|
},
|
|
836
|
-
gamerule(rule, value) {
|
|
856
|
+
gamerule(rule, value, dimension) {
|
|
837
857
|
write("gamerule");
|
|
838
|
-
push({ kind: "gamerule", rule, value });
|
|
858
|
+
push({ kind: "gamerule", rule, value, dimension });
|
|
839
859
|
},
|
|
840
860
|
setSpawn(at) {
|
|
841
861
|
write("setSpawn");
|
|
@@ -845,6 +865,7 @@ function createReducer(def) {
|
|
|
845
865
|
write("worldBorder");
|
|
846
866
|
push({
|
|
847
867
|
kind: "worldborder",
|
|
868
|
+
dimension: opts.dimension,
|
|
848
869
|
center: opts.center,
|
|
849
870
|
size: opts.size,
|
|
850
871
|
seconds: opts.over === undefined ? undefined : (0, time_js_1.toTicks)(opts.over) / 20,
|
|
@@ -865,11 +886,11 @@ function createReducer(def) {
|
|
|
865
886
|
}));
|
|
866
887
|
push({ kind: "container", at: { ...at }, items: out });
|
|
867
888
|
},
|
|
868
|
-
command(cmd, name) {
|
|
889
|
+
command(cmd, name, dimension) {
|
|
869
890
|
write("command");
|
|
870
891
|
r.actions.push({ type: "log", message: `raw command: ${cmd}` });
|
|
871
892
|
if (name === undefined) {
|
|
872
|
-
push({ kind: "command", cmd });
|
|
893
|
+
push({ kind: "command", cmd, dimension });
|
|
873
894
|
return;
|
|
874
895
|
}
|
|
875
896
|
if (typeof name !== "string")
|
|
@@ -878,7 +899,7 @@ function createReducer(def) {
|
|
|
878
899
|
throw (0, errors_js_1.apiError)("lifecycle", `command("${cmd}", "${name}"): a result needs a running game, not .setup (status ${s.status})`);
|
|
879
900
|
const id = `cmd:${s.nextId++}`;
|
|
880
901
|
s.commands[id] = { name };
|
|
881
|
-
push({ kind: "command", cmd, id });
|
|
902
|
+
push({ kind: "command", cmd, id, dimension });
|
|
882
903
|
},
|
|
883
904
|
// ---- flow
|
|
884
905
|
startPhase(name) {
|
|
@@ -1282,11 +1303,19 @@ function createReducer(def) {
|
|
|
1282
1303
|
const out = [];
|
|
1283
1304
|
if (w.spawn)
|
|
1284
1305
|
out.push({ kind: "spawn", at: { ...w.spawn } });
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1306
|
+
for (const dimension of dimensions) {
|
|
1307
|
+
const scope = dimension === dimensions_js_1.OVERWORLD ? {} : { dimension };
|
|
1308
|
+
if (w.time !== false)
|
|
1309
|
+
out.push({ kind: "time", value: w.time, ...scope });
|
|
1310
|
+
out.push({ kind: "gamerule", rule: "minecraft:advance_time", value: w.daylightCycle, ...scope });
|
|
1311
|
+
out.push({ kind: "gamerule", rule: "minecraft:spawn_mobs", value: w.mobSpawning, ...scope });
|
|
1312
|
+
out.push({
|
|
1313
|
+
kind: "gamerule",
|
|
1314
|
+
rule: "minecraft:natural_health_regeneration",
|
|
1315
|
+
value: w.naturalRegeneration,
|
|
1316
|
+
...scope,
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1290
1319
|
return out;
|
|
1291
1320
|
}
|
|
1292
1321
|
function worldPlayers(s) {
|
|
@@ -1664,6 +1693,8 @@ function createReducer(def) {
|
|
|
1664
1693
|
if (r.s.status !== "PLAYING")
|
|
1665
1694
|
return;
|
|
1666
1695
|
for (const { m, before, after } of edges) {
|
|
1696
|
+
if ((0, dimensions_js_1.dimensionOf)(m.from) !== (0, dimensions_js_1.dimensionOf)(m.to))
|
|
1697
|
+
fire(r, "dimensionChanged", { player: viewOf(r, m.p), from: m.from, to: { ...m.to } });
|
|
1667
1698
|
for (const zone of after)
|
|
1668
1699
|
if (!before.includes(zone))
|
|
1669
1700
|
fire(r, "zoneEntered", { player: viewOf(r, m.p), zone });
|
|
@@ -1788,6 +1819,8 @@ function createReducer(def) {
|
|
|
1788
1819
|
return;
|
|
1789
1820
|
}
|
|
1790
1821
|
const missing = missingCapabilities(e.capabilities);
|
|
1822
|
+
if (dimensions.length > 1 && !e.capabilities.includes("dimensions"))
|
|
1823
|
+
missing.push("dimensions");
|
|
1791
1824
|
if (def.setup && !e.capabilities.includes("batch"))
|
|
1792
1825
|
missing.push("batch");
|
|
1793
1826
|
if (missing.length > 0) {
|
|
@@ -1848,6 +1881,8 @@ function createReducer(def) {
|
|
|
1848
1881
|
delete s.dialogs[player];
|
|
1849
1882
|
r.actions.push({ type: "effect", effect: { kind: "clear_dialog", player } });
|
|
1850
1883
|
}
|
|
1884
|
+
if (e.times)
|
|
1885
|
+
s.world = { ...s.world, times: { ...s.world.times, ...e.times } };
|
|
1851
1886
|
if (e.entities)
|
|
1852
1887
|
s.world = (0, world_js_1.moveEntities)(s.world, e.entities);
|
|
1853
1888
|
if (e.time !== undefined && e.time !== s.world.time)
|
|
@@ -2075,7 +2110,11 @@ function createReducer(def) {
|
|
|
2075
2110
|
applyMobStatus(next, e);
|
|
2076
2111
|
s.world = (0, world_js_1.putEntity)(s.world, next);
|
|
2077
2112
|
if (playing())
|
|
2078
|
-
fire(r, "entityChanged",
|
|
2113
|
+
fire(r, "entityChanged", () => ({
|
|
2114
|
+
entity: (0, world_js_1.freezeObservation)(next),
|
|
2115
|
+
was: (0, world_js_1.freezeObservation)(prev),
|
|
2116
|
+
changed: Object.freeze((0, world_js_1.changedFields)(prev, next)),
|
|
2117
|
+
}));
|
|
2079
2118
|
break;
|
|
2080
2119
|
}
|
|
2081
2120
|
case "entity_removed": {
|
|
@@ -2091,15 +2130,41 @@ function createReducer(def) {
|
|
|
2091
2130
|
});
|
|
2092
2131
|
break;
|
|
2093
2132
|
}
|
|
2133
|
+
case "nbt": {
|
|
2134
|
+
const res = (0, world_js_1.applyNbt)(s.world, e);
|
|
2135
|
+
const world = res.world;
|
|
2136
|
+
s.world = world;
|
|
2137
|
+
if (!playing())
|
|
2138
|
+
break;
|
|
2139
|
+
// A counter (an item's `Age`) changes on every tick; the paths let a handler skip it. They are built only for a handler.
|
|
2140
|
+
for (const c of res.entities) {
|
|
2141
|
+
const entity = world.entities[c.id];
|
|
2142
|
+
if (!entity)
|
|
2143
|
+
continue;
|
|
2144
|
+
fire(r, "entityChanged", () => ({
|
|
2145
|
+
entity,
|
|
2146
|
+
was: (0, world_js_1.freezeObservation)(c.was),
|
|
2147
|
+
changed: Object.freeze((0, world_js_1.nbtPaths)(c.was.nbt, c.delta, "nbt")),
|
|
2148
|
+
}));
|
|
2149
|
+
}
|
|
2150
|
+
for (const c of res.blocks) {
|
|
2151
|
+
fire(r, "blockNbtChanged", () => ({
|
|
2152
|
+
at: { ...c.at },
|
|
2153
|
+
nbt: world.blockNbt[posKey(c.at)],
|
|
2154
|
+
was: c.was,
|
|
2155
|
+
changed: Object.freeze(c.delta === null ? [""] : (0, world_js_1.nbtPaths)(c.was, c.delta, "")),
|
|
2156
|
+
}));
|
|
2157
|
+
}
|
|
2158
|
+
break;
|
|
2159
|
+
}
|
|
2094
2160
|
case "chunk":
|
|
2095
2161
|
s.world = (0, world_js_1.applyChunk)(s.world, e);
|
|
2096
2162
|
break;
|
|
2097
2163
|
case "chunk_unloaded": {
|
|
2098
|
-
s.world = (0, world_js_1.removeChunk)(s.world, e.x, e.z);
|
|
2164
|
+
s.world = (0, world_js_1.removeChunk)(s.world, e.x, e.z, e.dimension);
|
|
2099
2165
|
// The containers of the chunk are unknown now.
|
|
2100
2166
|
for (const key of Object.keys(s.containers)) {
|
|
2101
|
-
|
|
2102
|
-
if (x >> 4 === e.x && z >> 4 === e.z)
|
|
2167
|
+
if ((0, dimensions_js_1.keyInChunk)(key, e.x, e.z, e.dimension))
|
|
2103
2168
|
delete s.containers[key];
|
|
2104
2169
|
}
|
|
2105
2170
|
break;
|
|
@@ -2109,6 +2174,7 @@ function createReducer(def) {
|
|
|
2109
2174
|
if (playing()) {
|
|
2110
2175
|
fire(r, "blocksChanged", () => ({
|
|
2111
2176
|
changes: e.changes.map((c) => compact({
|
|
2177
|
+
dimension: c.dimension,
|
|
2112
2178
|
x: c.x,
|
|
2113
2179
|
y: c.y,
|
|
2114
2180
|
z: c.z,
|
|
@@ -2133,10 +2199,13 @@ function createReducer(def) {
|
|
|
2133
2199
|
const from = { ...e.from };
|
|
2134
2200
|
const to = { ...e.to };
|
|
2135
2201
|
const { lo, hi } = (0, world_js_1.bounds)({ from, to });
|
|
2136
|
-
const dest = { x: Math.floor(e.dest.x), y: Math.floor(e.dest.y), z: Math.floor(e.dest.z) };
|
|
2202
|
+
const dest = { ...e.dest, x: Math.floor(e.dest.x), y: Math.floor(e.dest.y), z: Math.floor(e.dest.z) };
|
|
2137
2203
|
s.world = (0, world_js_1.cloneBlocks)(s.world, { from, to }, dest, e.mode);
|
|
2138
2204
|
if (playing()) {
|
|
2139
|
-
const box = {
|
|
2205
|
+
const box = {
|
|
2206
|
+
from: dest,
|
|
2207
|
+
to: { ...dest, x: dest.x + hi.x - lo.x, y: dest.y + hi.y - lo.y, z: dest.z + hi.z - lo.z },
|
|
2208
|
+
};
|
|
2140
2209
|
// A move clears the source first: an author who applies the entries in order gets the vanilla result on an overlap.
|
|
2141
2210
|
fire(r, "blocksChanged", {
|
|
2142
2211
|
changes: e.mode === "move"
|