redscript-mc 1.2.28 → 1.2.29
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/__tests__/cli.test.js +12 -12
- package/dist/__tests__/optimizer-advanced.test.js +4 -4
- package/dist/compile.d.ts +3 -2
- package/dist/compile.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -1
- package/editors/vscode/out/extension.js +1797 -1157
- package/editors/vscode/package-lock.json +3 -3
- package/editors/vscode/package.json +1 -1
- package/editors/vscode/src/hover.ts +18 -0
- package/editors/vscode/syntaxes/redscript.tmLanguage.json +12 -3
- package/package.json +1 -1
- package/src/__tests__/cli.test.ts +12 -12
- package/src/__tests__/optimizer-advanced.test.ts +4 -4
- package/src/compile.ts +4 -3
- package/src/index.ts +5 -4
|
@@ -77,7 +77,7 @@ describe('CLI API', () => {
|
|
|
77
77
|
const source = fs.readFileSync(mainPath, 'utf-8');
|
|
78
78
|
const result = (0, index_1.compile)(source, { namespace: 'mygame', filePath: mainPath });
|
|
79
79
|
const tickTimer = result.files.find(file => file.path.endsWith('/tick_timer.mcfunction'));
|
|
80
|
-
expect(tickTimer?.content).toContain('scoreboard players set #rs
|
|
80
|
+
expect(tickTimer?.content).toContain('scoreboard players set #rs __mygame.timer_ticks 1');
|
|
81
81
|
});
|
|
82
82
|
it('adds a call-site hash for stdlib internal scoreboard objectives', () => {
|
|
83
83
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'redscript-stdlib-hash-'));
|
|
@@ -125,8 +125,8 @@ describe('CLI API', () => {
|
|
|
125
125
|
const result = (0, index_1.compile)(source, { namespace: 'timernew', filePath: mainPath });
|
|
126
126
|
expect(result.typeErrors).toEqual([]);
|
|
127
127
|
const newFn = result.files.find(file => file.path.endsWith('/Timer_new.mcfunction'));
|
|
128
|
-
expect(newFn?.content).toContain('scoreboard players set timer_ticks
|
|
129
|
-
expect(newFn?.content).toContain('scoreboard players set timer_active
|
|
128
|
+
expect(newFn?.content).toContain('scoreboard players set timer_ticks __timernew 0');
|
|
129
|
+
expect(newFn?.content).toContain('scoreboard players set timer_active __timernew 0');
|
|
130
130
|
});
|
|
131
131
|
it('Timer.start/pause/reset', () => {
|
|
132
132
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'redscript-timer-state-'));
|
|
@@ -149,9 +149,9 @@ describe('CLI API', () => {
|
|
|
149
149
|
const startFn = result.files.find(file => file.path.endsWith('/Timer_start.mcfunction'));
|
|
150
150
|
const pauseFn = result.files.find(file => file.path.endsWith('/Timer_pause.mcfunction'));
|
|
151
151
|
const resetFn = result.files.find(file => file.path.endsWith('/Timer_reset.mcfunction'));
|
|
152
|
-
expect(startFn?.content).toContain('scoreboard players set timer_active
|
|
153
|
-
expect(pauseFn?.content).toContain('scoreboard players set timer_active
|
|
154
|
-
expect(resetFn?.content).toContain('scoreboard players set timer_ticks
|
|
152
|
+
expect(startFn?.content).toContain('scoreboard players set timer_active __timerstate 1');
|
|
153
|
+
expect(pauseFn?.content).toContain('scoreboard players set timer_active __timerstate 0');
|
|
154
|
+
expect(resetFn?.content).toContain('scoreboard players set timer_ticks __timerstate 0');
|
|
155
155
|
});
|
|
156
156
|
it('Timer.done returns bool', () => {
|
|
157
157
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'redscript-timer-done-'));
|
|
@@ -174,9 +174,9 @@ describe('CLI API', () => {
|
|
|
174
174
|
expect(result.typeErrors).toEqual([]);
|
|
175
175
|
const doneFn = result.files.find(file => file.path.endsWith('/Timer_done.mcfunction'));
|
|
176
176
|
const mainFn = result.files.find(file => file.path.endsWith('/main.mcfunction'));
|
|
177
|
-
expect(doneFn?.content).toContain('scoreboard players get timer_ticks
|
|
177
|
+
expect(doneFn?.content).toContain('scoreboard players get timer_ticks __timerdone');
|
|
178
178
|
expect(doneFn?.content).toContain('return run scoreboard players get');
|
|
179
|
-
expect(mainFn?.content).toContain('execute if score $main_finished
|
|
179
|
+
expect(mainFn?.content).toContain('execute if score $main_finished __timerdone matches 1..');
|
|
180
180
|
});
|
|
181
181
|
it('Timer.tick increments', () => {
|
|
182
182
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'redscript-timer-tick-'));
|
|
@@ -199,10 +199,10 @@ describe('CLI API', () => {
|
|
|
199
199
|
.filter(file => file.path.includes('/Timer_tick'))
|
|
200
200
|
.map(file => file.content)
|
|
201
201
|
.join('\n');
|
|
202
|
-
expect(tickOutput).toContain('scoreboard players get timer_active
|
|
203
|
-
expect(tickOutput).toContain('scoreboard players get timer_ticks
|
|
204
|
-
expect(tickOutput).toContain(' += $const_1
|
|
205
|
-
expect(tickOutput).toContain('execute store result score timer_ticks
|
|
202
|
+
expect(tickOutput).toContain('scoreboard players get timer_active __timertick');
|
|
203
|
+
expect(tickOutput).toContain('scoreboard players get timer_ticks __timertick');
|
|
204
|
+
expect(tickOutput).toContain(' += $const_1 __timertick');
|
|
205
|
+
expect(tickOutput).toContain('execute store result score timer_ticks __timertick run scoreboard players get $_');
|
|
206
206
|
});
|
|
207
207
|
});
|
|
208
208
|
describe('compile()', () => {
|
|
@@ -26,7 +26,7 @@ fn turret_tick() {
|
|
|
26
26
|
const result = (0, index_1.compile)(source, { namespace: 'test' });
|
|
27
27
|
const parent = getFileContent(result.files, 'data/test/function/turret_tick.mcfunction');
|
|
28
28
|
const loopBody = getFileContent(result.files, 'data/test/function/turret_tick/foreach_0.mcfunction');
|
|
29
|
-
const hoistedRead = 'execute store result score $_0
|
|
29
|
+
const hoistedRead = 'execute store result score $_0 __test run scoreboard players get config test.turret_range';
|
|
30
30
|
const executeCall = 'execute as @e[tag=turret] run function test:turret_tick/foreach_0';
|
|
31
31
|
expect(parent).toContain(hoistedRead);
|
|
32
32
|
expect(parent.indexOf(hoistedRead)).toBeLessThan(parent.indexOf(executeCall));
|
|
@@ -48,7 +48,7 @@ fn read_twice() {
|
|
|
48
48
|
const fn = getFileContent(result.files, 'data/test/function/read_twice.mcfunction');
|
|
49
49
|
const readMatches = fn.match(/scoreboard players get @s test\.coins/g) ?? [];
|
|
50
50
|
expect(readMatches).toHaveLength(1);
|
|
51
|
-
expect(fn).toContain('scoreboard players operation $_1
|
|
51
|
+
expect(fn).toContain('scoreboard players operation $_1 __test = $_0 __test');
|
|
52
52
|
});
|
|
53
53
|
test('reuses duplicate arithmetic sequences', () => {
|
|
54
54
|
const source = `
|
|
@@ -63,9 +63,9 @@ fn math() {
|
|
|
63
63
|
`;
|
|
64
64
|
const result = (0, index_1.compile)(source, { namespace: 'test' });
|
|
65
65
|
const fn = getFileContent(result.files, 'data/test/function/math.mcfunction');
|
|
66
|
-
const addMatches = fn.match(/\+= \$const_2
|
|
66
|
+
const addMatches = fn.match(/\+= \$const_2 __test/g) ?? [];
|
|
67
67
|
expect(addMatches).toHaveLength(1);
|
|
68
|
-
expect(fn).toContain('scoreboard players operation $_1
|
|
68
|
+
expect(fn).toContain('scoreboard players operation $_1 __test = $_0 __test');
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
71
|
describe('setblock batching', () => {
|
package/dist/compile.d.ts
CHANGED
|
@@ -14,8 +14,9 @@ export interface CompileOptions {
|
|
|
14
14
|
dce?: boolean;
|
|
15
15
|
mangle?: boolean;
|
|
16
16
|
/** Scoreboard objective used for all variable slots.
|
|
17
|
-
* Defaults to '
|
|
18
|
-
*
|
|
17
|
+
* Defaults to '__<namespace>' (e.g. '__mathshow') — the double-underscore
|
|
18
|
+
* prefix signals compiler-internal and avoids occupying the user's namespace.
|
|
19
|
+
* Each datapack gets a unique objective automatically; no manual setup needed. */
|
|
19
20
|
scoreboardObjective?: string;
|
|
20
21
|
/** Additional source files that should be treated as *library* code.
|
|
21
22
|
* Functions in these files are DCE-eligible: they are only compiled into
|
package/dist/compile.js
CHANGED
|
@@ -212,7 +212,7 @@ function compile(source, options = {}) {
|
|
|
212
212
|
// Configure scoreboard objective for this compilation.
|
|
213
213
|
// Default: use the datapack namespace so each datapack gets its own objective
|
|
214
214
|
// automatically, preventing variable collisions when multiple datapacks coexist.
|
|
215
|
-
const scoreboardObj = options.scoreboardObjective ?? namespace
|
|
215
|
+
const scoreboardObj = options.scoreboardObjective ?? `__${namespace}`;
|
|
216
216
|
(0, lowering_1.setScoreboardObjective)(scoreboardObj);
|
|
217
217
|
// Lowering
|
|
218
218
|
const ir = new lowering_1.Lowering(namespace, preprocessed.ranges).lower(ast);
|
package/dist/index.d.ts
CHANGED
|
@@ -17,9 +17,10 @@ export interface CompileOptions {
|
|
|
17
17
|
filePath?: string;
|
|
18
18
|
dce?: boolean;
|
|
19
19
|
mangle?: boolean;
|
|
20
|
-
/** Scoreboard objective used for all variable slots
|
|
21
|
-
*
|
|
22
|
-
* RedScript datapacks are loaded simultaneously
|
|
20
|
+
/** Scoreboard objective used for all variable slots.
|
|
21
|
+
* Defaults to '__<namespace>' (e.g. '__mathshow') to avoid collisions when
|
|
22
|
+
* multiple RedScript datapacks are loaded simultaneously, without occupying
|
|
23
|
+
* the user's own namespace. Override only if you need a specific name. */
|
|
23
24
|
scoreboardObjective?: string;
|
|
24
25
|
}
|
|
25
26
|
export interface CompileResult {
|
package/dist/index.js
CHANGED
|
@@ -69,7 +69,7 @@ function compile(source, options = {}) {
|
|
|
69
69
|
// Configure scoreboard objective for this compilation.
|
|
70
70
|
// Default: use the datapack namespace so each datapack gets its own objective
|
|
71
71
|
// automatically, preventing variable collisions when multiple datapacks coexist.
|
|
72
|
-
const scoreboardObj = options.scoreboardObjective ?? namespace
|
|
72
|
+
const scoreboardObj = options.scoreboardObjective ?? `__${namespace}`;
|
|
73
73
|
(0, lowering_1.setScoreboardObjective)(scoreboardObj);
|
|
74
74
|
// Lowering to IR
|
|
75
75
|
const lowering = new lowering_1.Lowering(namespace, preprocessed.ranges);
|