redscript-mc 1.0.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/.github/ISSUE_TEMPLATE/bug_report.md +40 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +31 -0
- package/.github/ISSUE_TEMPLATE/wrong_output.md +33 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +34 -0
- package/.github/workflows/ci.yml +29 -0
- package/.github/workflows/publish-extension.yml +35 -0
- package/LICENSE +21 -0
- package/README.md +261 -0
- package/README.zh.md +261 -0
- package/dist/__tests__/cli.test.d.ts +1 -0
- package/dist/__tests__/cli.test.js +140 -0
- package/dist/__tests__/codegen.test.d.ts +1 -0
- package/dist/__tests__/codegen.test.js +121 -0
- package/dist/__tests__/diagnostics.test.d.ts +4 -0
- package/dist/__tests__/diagnostics.test.js +149 -0
- package/dist/__tests__/e2e.test.d.ts +6 -0
- package/dist/__tests__/e2e.test.js +1528 -0
- package/dist/__tests__/lexer.test.d.ts +1 -0
- package/dist/__tests__/lexer.test.js +316 -0
- package/dist/__tests__/lowering.test.d.ts +1 -0
- package/dist/__tests__/lowering.test.js +819 -0
- package/dist/__tests__/mc-integration.test.d.ts +12 -0
- package/dist/__tests__/mc-integration.test.js +395 -0
- package/dist/__tests__/mc-syntax.test.d.ts +1 -0
- package/dist/__tests__/mc-syntax.test.js +112 -0
- package/dist/__tests__/nbt.test.d.ts +1 -0
- package/dist/__tests__/nbt.test.js +82 -0
- package/dist/__tests__/optimizer-advanced.test.d.ts +1 -0
- package/dist/__tests__/optimizer-advanced.test.js +124 -0
- package/dist/__tests__/optimizer.test.d.ts +1 -0
- package/dist/__tests__/optimizer.test.js +118 -0
- package/dist/__tests__/parser.test.d.ts +1 -0
- package/dist/__tests__/parser.test.js +717 -0
- package/dist/__tests__/repl.test.d.ts +1 -0
- package/dist/__tests__/repl.test.js +27 -0
- package/dist/__tests__/runtime.test.d.ts +1 -0
- package/dist/__tests__/runtime.test.js +276 -0
- package/dist/__tests__/structure-optimizer.test.d.ts +1 -0
- package/dist/__tests__/structure-optimizer.test.js +33 -0
- package/dist/__tests__/typechecker.test.d.ts +1 -0
- package/dist/__tests__/typechecker.test.js +364 -0
- package/dist/ast/types.d.ts +357 -0
- package/dist/ast/types.js +9 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +407 -0
- package/dist/codegen/cmdblock/index.d.ts +26 -0
- package/dist/codegen/cmdblock/index.js +45 -0
- package/dist/codegen/mcfunction/index.d.ts +34 -0
- package/dist/codegen/mcfunction/index.js +413 -0
- package/dist/codegen/structure/index.d.ts +18 -0
- package/dist/codegen/structure/index.js +249 -0
- package/dist/compile.d.ts +30 -0
- package/dist/compile.js +152 -0
- package/dist/data/arena/function/__load.mcfunction +6 -0
- package/dist/data/arena/function/__tick.mcfunction +2 -0
- package/dist/data/arena/function/announce_leaders/else_1.mcfunction +3 -0
- package/dist/data/arena/function/announce_leaders/foreach_0/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/announce_leaders/foreach_0/then_0.mcfunction +3 -0
- package/dist/data/arena/function/announce_leaders/foreach_0.mcfunction +7 -0
- package/dist/data/arena/function/announce_leaders/foreach_1/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/announce_leaders/foreach_1/then_0.mcfunction +4 -0
- package/dist/data/arena/function/announce_leaders/foreach_1.mcfunction +6 -0
- package/dist/data/arena/function/announce_leaders/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/announce_leaders/then_0.mcfunction +4 -0
- package/dist/data/arena/function/announce_leaders.mcfunction +6 -0
- package/dist/data/arena/function/arena_tick/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/arena_tick/then_0.mcfunction +4 -0
- package/dist/data/arena/function/arena_tick.mcfunction +11 -0
- package/dist/data/counter/function/__load.mcfunction +5 -0
- package/dist/data/counter/function/__tick.mcfunction +2 -0
- package/dist/data/counter/function/counter_tick/merge_2.mcfunction +1 -0
- package/dist/data/counter/function/counter_tick/then_0.mcfunction +3 -0
- package/dist/data/counter/function/counter_tick.mcfunction +11 -0
- package/dist/data/minecraft/tags/function/load.json +5 -0
- package/dist/data/minecraft/tags/function/tick.json +5 -0
- package/dist/data/quiz/function/__load.mcfunction +16 -0
- package/dist/data/quiz/function/__tick.mcfunction +6 -0
- package/dist/data/quiz/function/__trigger_quiz_a_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/__trigger_quiz_b_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/__trigger_quiz_c_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/__trigger_quiz_start_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/answer_a.mcfunction +4 -0
- package/dist/data/quiz/function/answer_b.mcfunction +4 -0
- package/dist/data/quiz/function/answer_c.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/else_1.mcfunction +5 -0
- package/dist/data/quiz/function/ask_question/else_4.mcfunction +5 -0
- package/dist/data/quiz/function/ask_question/else_7.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/merge_2.mcfunction +1 -0
- package/dist/data/quiz/function/ask_question/merge_5.mcfunction +2 -0
- package/dist/data/quiz/function/ask_question/merge_8.mcfunction +2 -0
- package/dist/data/quiz/function/ask_question/then_0.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/then_3.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/then_6.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question.mcfunction +7 -0
- package/dist/data/quiz/function/finish_quiz.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer/else_1.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/else_10.mcfunction +3 -0
- package/dist/data/quiz/function/handle_answer/else_16.mcfunction +3 -0
- package/dist/data/quiz/function/handle_answer/else_4.mcfunction +3 -0
- package/dist/data/quiz/function/handle_answer/else_7.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/merge_11.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_14.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_17.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_2.mcfunction +8 -0
- package/dist/data/quiz/function/handle_answer/merge_5.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_8.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/then_0.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/then_12.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/then_15.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer/then_3.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer/then_6.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/then_9.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer.mcfunction +11 -0
- package/dist/data/quiz/function/start_quiz.mcfunction +5 -0
- package/dist/data/shop/function/__load.mcfunction +7 -0
- package/dist/data/shop/function/__tick.mcfunction +3 -0
- package/dist/data/shop/function/__trigger_shop_buy_dispatch.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase/else_1.mcfunction +5 -0
- package/dist/data/shop/function/complete_purchase/else_4.mcfunction +5 -0
- package/dist/data/shop/function/complete_purchase/else_7.mcfunction +3 -0
- package/dist/data/shop/function/complete_purchase/merge_2.mcfunction +2 -0
- package/dist/data/shop/function/complete_purchase/merge_5.mcfunction +2 -0
- package/dist/data/shop/function/complete_purchase/merge_8.mcfunction +2 -0
- package/dist/data/shop/function/complete_purchase/then_0.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase/then_3.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase/then_6.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase.mcfunction +7 -0
- package/dist/data/shop/function/handle_shop_trigger.mcfunction +3 -0
- package/dist/data/turret/function/__load.mcfunction +5 -0
- package/dist/data/turret/function/__tick.mcfunction +4 -0
- package/dist/data/turret/function/__trigger_deploy_turret_dispatch.mcfunction +4 -0
- package/dist/data/turret/function/deploy_turret.mcfunction +8 -0
- package/dist/data/turret/function/turret_tick/at_1.mcfunction +2 -0
- package/dist/data/turret/function/turret_tick/foreach_0.mcfunction +2 -0
- package/dist/data/turret/function/turret_tick/foreach_2.mcfunction +2 -0
- package/dist/data/turret/function/turret_tick/tick_body.mcfunction +3 -0
- package/dist/data/turret/function/turret_tick/tick_skip.mcfunction +1 -0
- package/dist/data/turret/function/turret_tick.mcfunction +5 -0
- package/dist/diagnostics/index.d.ts +44 -0
- package/dist/diagnostics/index.js +140 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +126 -0
- package/dist/ir/builder.d.ts +32 -0
- package/dist/ir/builder.js +99 -0
- package/dist/ir/types.d.ts +117 -0
- package/dist/ir/types.js +15 -0
- package/dist/lexer/index.d.ts +36 -0
- package/dist/lexer/index.js +458 -0
- package/dist/lowering/index.d.ts +106 -0
- package/dist/lowering/index.js +2041 -0
- package/dist/mc-test/client.d.ts +128 -0
- package/dist/mc-test/client.js +174 -0
- package/dist/mc-test/runner.d.ts +28 -0
- package/dist/mc-test/runner.js +150 -0
- package/dist/mc-test/setup.d.ts +11 -0
- package/dist/mc-test/setup.js +98 -0
- package/dist/mc-validator/index.d.ts +17 -0
- package/dist/mc-validator/index.js +322 -0
- package/dist/nbt/index.d.ts +86 -0
- package/dist/nbt/index.js +250 -0
- package/dist/optimizer/commands.d.ts +36 -0
- package/dist/optimizer/commands.js +349 -0
- package/dist/optimizer/passes.d.ts +34 -0
- package/dist/optimizer/passes.js +227 -0
- package/dist/optimizer/structure.d.ts +8 -0
- package/dist/optimizer/structure.js +344 -0
- package/dist/pack.mcmeta +6 -0
- package/dist/parser/index.d.ts +76 -0
- package/dist/parser/index.js +1193 -0
- package/dist/repl.d.ts +16 -0
- package/dist/repl.js +165 -0
- package/dist/runtime/index.d.ts +101 -0
- package/dist/runtime/index.js +1288 -0
- package/dist/typechecker/index.d.ts +42 -0
- package/dist/typechecker/index.js +629 -0
- package/docs/COMPILATION_STATS.md +142 -0
- package/docs/IMPLEMENTATION_GUIDE.md +512 -0
- package/docs/LANGUAGE_REFERENCE.md +415 -0
- package/docs/MC_MAPPING.md +280 -0
- package/docs/STRUCTURE_TARGET.md +80 -0
- package/docs/mc-reference/commands.md +259 -0
- package/editors/vscode/.vscodeignore +10 -0
- package/editors/vscode/LICENSE +21 -0
- package/editors/vscode/README.md +78 -0
- package/editors/vscode/build.mjs +28 -0
- package/editors/vscode/icon.png +0 -0
- package/editors/vscode/mcfunction-language-configuration.json +28 -0
- package/editors/vscode/out/extension.js +7236 -0
- package/editors/vscode/package-lock.json +566 -0
- package/editors/vscode/package.json +137 -0
- package/editors/vscode/redscript-language-configuration.json +28 -0
- package/editors/vscode/snippets/redscript.json +114 -0
- package/editors/vscode/src/codeactions.ts +89 -0
- package/editors/vscode/src/completion.ts +130 -0
- package/editors/vscode/src/extension.ts +239 -0
- package/editors/vscode/src/hover.ts +1120 -0
- package/editors/vscode/src/symbols.ts +207 -0
- package/editors/vscode/syntaxes/mcfunction.tmLanguage.json +740 -0
- package/editors/vscode/syntaxes/redscript.tmLanguage.json +357 -0
- package/editors/vscode/tsconfig.json +13 -0
- package/jest.config.js +5 -0
- package/package.json +38 -0
- package/src/__tests__/cli.test.ts +130 -0
- package/src/__tests__/codegen.test.ts +128 -0
- package/src/__tests__/diagnostics.test.ts +195 -0
- package/src/__tests__/e2e.test.ts +1721 -0
- package/src/__tests__/fixtures/mc-commands-1.21.4.json +18734 -0
- package/src/__tests__/formatter.test.ts +46 -0
- package/src/__tests__/lexer.test.ts +356 -0
- package/src/__tests__/lowering.test.ts +962 -0
- package/src/__tests__/mc-integration.test.ts +409 -0
- package/src/__tests__/mc-syntax.test.ts +96 -0
- package/src/__tests__/nbt.test.ts +58 -0
- package/src/__tests__/optimizer-advanced.test.ts +144 -0
- package/src/__tests__/optimizer.test.ts +129 -0
- package/src/__tests__/parser.test.ts +800 -0
- package/src/__tests__/repl.test.ts +33 -0
- package/src/__tests__/runtime.test.ts +289 -0
- package/src/__tests__/structure-optimizer.test.ts +38 -0
- package/src/__tests__/typechecker.test.ts +395 -0
- package/src/ast/types.ts +248 -0
- package/src/cli.ts +445 -0
- package/src/codegen/cmdblock/index.ts +63 -0
- package/src/codegen/mcfunction/index.ts +471 -0
- package/src/codegen/structure/index.ts +305 -0
- package/src/compile.ts +188 -0
- package/src/diagnostics/index.ts +186 -0
- package/src/examples/README.md +77 -0
- package/src/examples/SHOWCASE_GAME.md +43 -0
- package/src/examples/arena.rs +44 -0
- package/src/examples/counter.rs +12 -0
- package/src/examples/pvp_arena.rs +131 -0
- package/src/examples/quiz.rs +90 -0
- package/src/examples/rpg.rs +13 -0
- package/src/examples/shop.rs +30 -0
- package/src/examples/showcase_game.rs +552 -0
- package/src/examples/stdlib_demo.rs +181 -0
- package/src/examples/turret.rs +27 -0
- package/src/examples/world_manager.rs +23 -0
- package/src/formatter/index.ts +22 -0
- package/src/index.ts +161 -0
- package/src/ir/builder.ts +114 -0
- package/src/ir/types.ts +119 -0
- package/src/lexer/index.ts +555 -0
- package/src/lowering/index.ts +2406 -0
- package/src/mc-test/client.ts +259 -0
- package/src/mc-test/runner.ts +140 -0
- package/src/mc-test/setup.ts +70 -0
- package/src/mc-validator/index.ts +367 -0
- package/src/nbt/index.ts +321 -0
- package/src/optimizer/commands.ts +416 -0
- package/src/optimizer/passes.ts +233 -0
- package/src/optimizer/structure.ts +441 -0
- package/src/parser/index.ts +1437 -0
- package/src/repl.ts +165 -0
- package/src/runtime/index.ts +1403 -0
- package/src/stdlib/README.md +156 -0
- package/src/stdlib/combat.rs +20 -0
- package/src/stdlib/cooldown.rs +45 -0
- package/src/stdlib/math.rs +49 -0
- package/src/stdlib/mobs.rs +99 -0
- package/src/stdlib/player.rs +29 -0
- package/src/stdlib/strings.rs +7 -0
- package/src/stdlib/timer.rs +51 -0
- package/src/templates/README.md +126 -0
- package/src/templates/combat.rs +96 -0
- package/src/templates/economy.rs +40 -0
- package/src/templates/mini-game-framework.rs +117 -0
- package/src/templates/quest.rs +78 -0
- package/src/test_programs/zombie_game.rs +25 -0
- package/src/typechecker/index.ts +737 -0
- package/tsconfig.json +16 -0
package/dist/repl.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DatapackFile } from './codegen/mcfunction';
|
|
2
|
+
export interface ReplEvaluation {
|
|
3
|
+
source: string;
|
|
4
|
+
files: DatapackFile[];
|
|
5
|
+
output: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class ReplSession {
|
|
8
|
+
private readonly namespace;
|
|
9
|
+
private declarations;
|
|
10
|
+
private statements;
|
|
11
|
+
constructor(namespace?: string);
|
|
12
|
+
clear(): void;
|
|
13
|
+
getSource(): string;
|
|
14
|
+
evaluate(input: string): ReplEvaluation;
|
|
15
|
+
}
|
|
16
|
+
export declare function startRepl(namespace?: string): Promise<void>;
|
package/dist/repl.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ReplSession = void 0;
|
|
37
|
+
exports.startRepl = startRepl;
|
|
38
|
+
const readline = __importStar(require("readline"));
|
|
39
|
+
const index_1 = require("./index");
|
|
40
|
+
const REPL_FN = '__repl';
|
|
41
|
+
class ReplSession {
|
|
42
|
+
constructor(namespace = 'repl') {
|
|
43
|
+
this.namespace = namespace;
|
|
44
|
+
this.declarations = [];
|
|
45
|
+
this.statements = [];
|
|
46
|
+
}
|
|
47
|
+
clear() {
|
|
48
|
+
this.declarations = [];
|
|
49
|
+
this.statements = [];
|
|
50
|
+
}
|
|
51
|
+
getSource() {
|
|
52
|
+
const sections = [];
|
|
53
|
+
if (this.declarations.length > 0) {
|
|
54
|
+
sections.push(this.declarations.join('\n\n'));
|
|
55
|
+
}
|
|
56
|
+
const body = this.statements.map(stmt => ` ${stmt}`).join('\n');
|
|
57
|
+
sections.push(`fn ${REPL_FN}() {\n${body}${body ? '\n' : ''}}`);
|
|
58
|
+
return sections.join('\n\n');
|
|
59
|
+
}
|
|
60
|
+
evaluate(input) {
|
|
61
|
+
const trimmed = input.trim();
|
|
62
|
+
if (!trimmed) {
|
|
63
|
+
return { source: this.getSource(), files: [], output: '' };
|
|
64
|
+
}
|
|
65
|
+
const declaration = isTopLevelDeclaration(trimmed);
|
|
66
|
+
const normalized = declaration ? trimmed : normalizeStatement(trimmed);
|
|
67
|
+
const nextDeclarations = declaration ? [...this.declarations, normalized] : [...this.declarations];
|
|
68
|
+
const nextStatements = declaration ? [...this.statements] : [...this.statements, normalized];
|
|
69
|
+
const source = buildSource(nextDeclarations, nextStatements);
|
|
70
|
+
const result = (0, index_1.compile)(source, { namespace: this.namespace });
|
|
71
|
+
const files = selectRelevantFiles(result.files, this.namespace, declaration);
|
|
72
|
+
this.declarations = nextDeclarations;
|
|
73
|
+
this.statements = nextStatements;
|
|
74
|
+
return {
|
|
75
|
+
source,
|
|
76
|
+
files,
|
|
77
|
+
output: formatFiles(files, declaration),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.ReplSession = ReplSession;
|
|
82
|
+
async function startRepl(namespace = 'repl') {
|
|
83
|
+
const session = new ReplSession(namespace);
|
|
84
|
+
const rl = readline.createInterface({
|
|
85
|
+
input: process.stdin,
|
|
86
|
+
output: process.stdout,
|
|
87
|
+
terminal: true,
|
|
88
|
+
});
|
|
89
|
+
console.log('RedScript REPL. Type :help for commands.');
|
|
90
|
+
try {
|
|
91
|
+
while (true) {
|
|
92
|
+
const line = await question(rl, 'rs> ');
|
|
93
|
+
const trimmed = line.trim();
|
|
94
|
+
if (trimmed === ':quit') {
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
if (trimmed === ':help') {
|
|
98
|
+
console.log([
|
|
99
|
+
'Commands:',
|
|
100
|
+
' :help Show REPL commands',
|
|
101
|
+
' :clear Reset declarations and statements',
|
|
102
|
+
' :quit Exit the REPL',
|
|
103
|
+
].join('\n'));
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (trimmed === ':clear') {
|
|
107
|
+
session.clear();
|
|
108
|
+
console.log('State cleared.');
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const evaluation = session.evaluate(line);
|
|
113
|
+
if (evaluation.output) {
|
|
114
|
+
console.log(evaluation.output);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
rl.close();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function question(rl, prompt) {
|
|
127
|
+
return new Promise(resolve => rl.question(prompt, resolve));
|
|
128
|
+
}
|
|
129
|
+
function buildSource(declarations, statements) {
|
|
130
|
+
const sections = [];
|
|
131
|
+
if (declarations.length > 0) {
|
|
132
|
+
sections.push(declarations.join('\n\n'));
|
|
133
|
+
}
|
|
134
|
+
const body = statements.map(stmt => ` ${stmt}`).join('\n');
|
|
135
|
+
sections.push(`fn ${REPL_FN}() {\n${body}${body ? '\n' : ''}}`);
|
|
136
|
+
return sections.join('\n\n');
|
|
137
|
+
}
|
|
138
|
+
function isTopLevelDeclaration(line) {
|
|
139
|
+
return /^(?:@\w+(?:\([^)]*\))?\s*)*(fn|struct|enum)\b/.test(line);
|
|
140
|
+
}
|
|
141
|
+
function normalizeStatement(line) {
|
|
142
|
+
if (/[;}]$/.test(line)) {
|
|
143
|
+
return line;
|
|
144
|
+
}
|
|
145
|
+
return `${line};`;
|
|
146
|
+
}
|
|
147
|
+
function selectRelevantFiles(files, namespace, declaration) {
|
|
148
|
+
if (declaration) {
|
|
149
|
+
const functionFiles = files.filter(file => file.path.startsWith(`data/${namespace}/function/`) &&
|
|
150
|
+
file.path.endsWith('.mcfunction') &&
|
|
151
|
+
!file.path.includes(`/${REPL_FN}/`) &&
|
|
152
|
+
!file.path.endsWith('/__load.mcfunction') &&
|
|
153
|
+
!file.path.endsWith('/__tick.mcfunction'));
|
|
154
|
+
return functionFiles;
|
|
155
|
+
}
|
|
156
|
+
return files.filter(file => file.path.startsWith(`data/${namespace}/function/${REPL_FN}`) &&
|
|
157
|
+
file.path.endsWith('.mcfunction'));
|
|
158
|
+
}
|
|
159
|
+
function formatFiles(files, declaration) {
|
|
160
|
+
if (files.length === 0) {
|
|
161
|
+
return declaration ? 'Accepted. No mcfunction output for this declaration yet.' : '';
|
|
162
|
+
}
|
|
163
|
+
return files.map(file => `${file.path}\n${file.content}`).join('\n\n');
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=repl.js.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCRuntime - Minecraft Command Runtime Simulator
|
|
3
|
+
*
|
|
4
|
+
* A TypeScript interpreter that simulates the subset of MC commands that
|
|
5
|
+
* RedScript generates, allowing behavioral testing without a real server.
|
|
6
|
+
*/
|
|
7
|
+
export interface Entity {
|
|
8
|
+
id: string;
|
|
9
|
+
tags: Set<string>;
|
|
10
|
+
scores: Map<string, number>;
|
|
11
|
+
selector: string;
|
|
12
|
+
type?: string;
|
|
13
|
+
position?: {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
z: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
interface Range {
|
|
20
|
+
min: number;
|
|
21
|
+
max: number;
|
|
22
|
+
}
|
|
23
|
+
declare function parseRange(s: string): Range;
|
|
24
|
+
declare function matchesRange(value: number, range: Range): boolean;
|
|
25
|
+
declare function parseSelector(sel: string, entities: Entity[], executor?: Entity): Entity[];
|
|
26
|
+
export declare class MCRuntime {
|
|
27
|
+
scoreboard: Map<string, Map<string, number>>;
|
|
28
|
+
storage: Map<string, any>;
|
|
29
|
+
entities: Entity[];
|
|
30
|
+
functions: Map<string, string[]>;
|
|
31
|
+
chatLog: string[];
|
|
32
|
+
world: Map<string, string>;
|
|
33
|
+
weather: string;
|
|
34
|
+
worldTime: number;
|
|
35
|
+
effects: Map<string, {
|
|
36
|
+
effect: string;
|
|
37
|
+
duration: number;
|
|
38
|
+
amplifier: number;
|
|
39
|
+
}[]>;
|
|
40
|
+
xp: Map<string, number>;
|
|
41
|
+
tickCount: number;
|
|
42
|
+
namespace: string;
|
|
43
|
+
private entityIdCounter;
|
|
44
|
+
private returnValue;
|
|
45
|
+
private shouldReturn;
|
|
46
|
+
constructor(namespace: string);
|
|
47
|
+
loadDatapack(dir: string): void;
|
|
48
|
+
loadFunction(name: string, lines: string[]): void;
|
|
49
|
+
load(): void;
|
|
50
|
+
tick(): void;
|
|
51
|
+
ticks(n: number): void;
|
|
52
|
+
execFunction(name: string, executor?: Entity): void;
|
|
53
|
+
private execFunctionLines;
|
|
54
|
+
execCommand(cmd: string, executor?: Entity): boolean;
|
|
55
|
+
private execScoreboard;
|
|
56
|
+
private execExecute;
|
|
57
|
+
private parseNextSelector;
|
|
58
|
+
private execFunctionCmd;
|
|
59
|
+
private execData;
|
|
60
|
+
private parseDataValue;
|
|
61
|
+
private getStorageField;
|
|
62
|
+
private setStorageField;
|
|
63
|
+
private removeStorageField;
|
|
64
|
+
private parseStoragePath;
|
|
65
|
+
private execTag;
|
|
66
|
+
private execSay;
|
|
67
|
+
private execTellraw;
|
|
68
|
+
private execTitle;
|
|
69
|
+
private extractJsonText;
|
|
70
|
+
private execSetblock;
|
|
71
|
+
private execFill;
|
|
72
|
+
private execTp;
|
|
73
|
+
private execWeather;
|
|
74
|
+
private execTime;
|
|
75
|
+
private execKill;
|
|
76
|
+
private execEffect;
|
|
77
|
+
private execXp;
|
|
78
|
+
private execSummon;
|
|
79
|
+
private execReturn;
|
|
80
|
+
getScore(player: string, objective: string): number;
|
|
81
|
+
setScore(player: string, objective: string, value: number): void;
|
|
82
|
+
addScore(player: string, objective: string, delta: number): void;
|
|
83
|
+
getStorage(path: string): any;
|
|
84
|
+
setStorage(path: string, value: any): void;
|
|
85
|
+
spawnEntity(tags: string[], type?: string, position?: {
|
|
86
|
+
x: number;
|
|
87
|
+
y: number;
|
|
88
|
+
z: number;
|
|
89
|
+
}): Entity;
|
|
90
|
+
killEntity(tag: string): void;
|
|
91
|
+
getEntities(selector: string): Entity[];
|
|
92
|
+
private positionKey;
|
|
93
|
+
private parseAbsolutePosition;
|
|
94
|
+
private resolvePosition;
|
|
95
|
+
private parseTimeValue;
|
|
96
|
+
private resolveTargetKeys;
|
|
97
|
+
getLastSaid(): string;
|
|
98
|
+
getChatLog(): string[];
|
|
99
|
+
compileAndLoad(source: string): void;
|
|
100
|
+
}
|
|
101
|
+
export { parseRange, matchesRange, parseSelector };
|