forked from SPGoding/spu
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.
- Loading branch information
Showing
54 changed files
with
36,030 additions
and
35,741 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"recommendations": [ | ||
"ms-vscode.vscode-typescript-tslint-plugin" | ||
], | ||
"unwantedRecommendations": [ | ||
"pca.datapack-helper" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"json.schemas": [ | ||
{ | ||
"fileMatch": [ | ||
"/ref/commands.json" | ||
], | ||
"url": "/ref/commands.schema.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// This file is adapted from vscode-extension-samples which is released under MIT License. | ||
// Go to https://github.com/Microsoft/vscode-extension-samples/blob/master/LICENSE for full license details. | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "npm", | ||
"script": "compile", | ||
"group": "build", | ||
"presentation": { | ||
"panel": "dedicated", | ||
"reveal": "never" | ||
}, | ||
"problemMatcher": [ | ||
"$tsc" | ||
] | ||
}, | ||
{ | ||
"type": "npm", | ||
"script": "watch", | ||
"isBackground": true, | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
}, | ||
"presentation": { | ||
"panel": "dedicated", | ||
"reveal": "never" | ||
}, | ||
"problemMatcher": [ | ||
"$tsc-watch" | ||
] | ||
}, | ||
{ | ||
"type": "npm", | ||
"script": "test", | ||
"isBackground": true, | ||
"group": { | ||
"kind": "test", | ||
"isDefault": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,65 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const updater_1 = require("./to19/updater"); | ||
const updater_2 = require("./to111/updater"); | ||
const updater_3 = require("./to112/updater"); | ||
const updater_4 = require("./to113/updater"); | ||
const updater_5 = require("./to114/updater"); | ||
const utils_1 = require("./utils/utils"); | ||
function transform(content, from, to) { | ||
let number = 1; | ||
let frame = 'success'; | ||
let msg = []; | ||
let ans = []; | ||
try { | ||
let timeBefore = (new Date()).getTime(); | ||
if (content) { | ||
const lines = content.toString().split('\n'); | ||
console.log("Got lines:", lines); | ||
for (const line of lines) { | ||
number = lines.indexOf(line); | ||
let result; | ||
if (line[0] === '#' || utils_1.isWhiteSpace(line)) { | ||
result = { command: line, warnings: [] }; | ||
} | ||
else { | ||
if (to === 14) { | ||
result = updater_5.UpdaterTo114.upLine(line, '1' + from); | ||
} | ||
else if (to === 13) { | ||
result = updater_4.UpdaterTo113.upLine(line, '1' + from); | ||
} | ||
else if (to === 12) { | ||
result = updater_3.UpdaterTo112.upLine(line, '1' + from); | ||
} | ||
else if (to === 11) { | ||
result = updater_2.UpdaterTo111.upLine(line, '1' + from); | ||
} | ||
else if (to === 9) { | ||
result = updater_1.UpdaterTo19.upLine(line, '1' + from); | ||
} | ||
else { | ||
throw `Unknown to version: '${to}'.`; | ||
} | ||
} | ||
result.warnings = result.warnings.filter(v => !utils_1.isWhiteSpace(v)); | ||
if (result.warnings.length > 0) { | ||
console.warn("检测到在途的编译错误:", msg); | ||
frame = 'warning'; | ||
msg.push(`Line #${number + 1}:`); | ||
for (const warning of result.warnings) { | ||
msg.push(` ${warning}`); | ||
} | ||
} | ||
console.log("已转换:", result); | ||
ans.push(result.command); | ||
} | ||
const timeAfter = (new Date()).getTime(); | ||
const timeDelta = timeAfter - timeBefore; | ||
msg.push(`Updated ${lines.length} line${lines.length === 1 ? '' : 's'} (in ${(timeDelta / 1000).toFixed(3)} seconds).`); | ||
} | ||
} | ||
catch (ex) { | ||
return { | ||
state: 'danger', | ||
commands: [], | ||
log: [`Updated error at line #${number + 1}: ${ex}`] | ||
}; | ||
} | ||
finally { | ||
return { | ||
state: frame, | ||
commands: ans, | ||
log: msg | ||
}; | ||
} | ||
} | ||
exports.transformCommand = transform; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const updater_1 = require("./to19/updater"); | ||
const updater_2 = require("./to111/updater"); | ||
const updater_3 = require("./to112/updater"); | ||
const updater_4 = require("./to113/updater"); | ||
const updater_5 = require("./to114/updater"); | ||
const utils_1 = require("./utils/utils"); | ||
function transformCommand(content, from, to) { | ||
let state = 'success'; | ||
const logs = []; | ||
const commands = []; | ||
const timeBefore = (new Date()).getTime(); | ||
const lines = content.split('\n'); | ||
for (let i = 0; i < lines.length; i++) { | ||
try { | ||
const line = lines[i]; | ||
let result; | ||
if (line[0] === '#' || utils_1.isWhiteSpace(line)) { | ||
result = { command: line, warnings: [] }; | ||
} | ||
else { | ||
if (to === 14) { | ||
result = updater_5.UpdaterTo114.upLine(line, `1${from}`); | ||
} | ||
else if (to === 13) { | ||
result = updater_4.UpdaterTo113.upLine(line, `1${from}`); | ||
} | ||
else if (to === 12) { | ||
result = updater_3.UpdaterTo112.upLine(line, `1${from}`); | ||
} | ||
else if (to === 11) { | ||
result = updater_2.UpdaterTo111.upLine(line, `1${from}`); | ||
} | ||
else if (to === 9) { | ||
result = updater_1.UpdaterTo19.upLine(line, `1${from}`); | ||
} | ||
else { | ||
throw `Unknown version: '${to}'. This should NEVER happen :(`; | ||
} | ||
} | ||
result.warnings = result.warnings.filter(v => !utils_1.isWhiteSpace(v)); | ||
if (result.warnings.length > 0) { | ||
state = 'warning'; | ||
let log = `Warnings detected when updating Line #${i + 1}: <br/> - `; | ||
log += result.warnings.join('<br/> - '); | ||
logs.push(log); | ||
} | ||
commands.push(result.command); | ||
} | ||
catch (ex) { | ||
const ans = { | ||
commands: [], | ||
state: 'error', | ||
logs: [`Errors occurred when updating Line #${i + 1}: <br/>${ex}`] | ||
}; | ||
return ans; | ||
} | ||
} | ||
const timeAfter = (new Date()).getTime(); | ||
const timeDelta = timeAfter - timeBefore; | ||
logs.push(`Updated ${lines.length} line${lines.length === 1 ? '' : 's'} (in ${(timeDelta / 1000).toFixed(3)} seconds).`); | ||
return { commands, logs, state }; | ||
} | ||
exports.transformCommand = transformCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,78 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("mocha"); | ||
const assert = require("power-assert"); | ||
const block_state_1 = require("../../utils/block_state"); | ||
describe('BlockState tests', () => { | ||
describe('constructor() tests', () => { | ||
it('should parse single name', () => { | ||
const input = 'spgoding:foobar'; | ||
const actual = new block_state_1.BlockState(input); | ||
assert(actual.name === 'spgoding:foobar'); | ||
}); | ||
it('should parse empty state', () => { | ||
const input = 'spgoding:foobar[]'; | ||
const actual = new block_state_1.BlockState(input); | ||
assert.deepEqual(actual.states, {}); | ||
}); | ||
it('should parse a single state', () => { | ||
const input = 'spgoding:foobar[foo=bar]'; | ||
const actual = new block_state_1.BlockState(input); | ||
assert.deepEqual(actual.states, { foo: 'bar' }); | ||
}); | ||
it('should parse states ending with a comma', () => { | ||
const input = 'spgoding:foobar[foo=bar,]'; | ||
const actual = new block_state_1.BlockState(input); | ||
assert.deepEqual(actual.states, { foo: 'bar' }); | ||
}); | ||
it('should parse multiple states', () => { | ||
const input = 'spgoding:foobar[foo=bar,baz=qux]'; | ||
const actual = new block_state_1.BlockState(input); | ||
assert.deepEqual(actual.states, { foo: 'bar', baz: 'qux' }); | ||
}); | ||
it('should parse single nbt', () => { | ||
const input = 'spgoding:foobar{foo:bar}'; | ||
const actual = new block_state_1.BlockState(input); | ||
const foo = actual.nbt.get('foo'); | ||
assert(foo && foo.toString() === '"bar"'); | ||
}); | ||
it('should parse both states and nbt', () => { | ||
const input = 'spgoding:foobar[foo=bar]{baz:qux}'; | ||
const actual = new block_state_1.BlockState(input); | ||
const baz = actual.nbt.get('baz'); | ||
assert.deepEqual(actual.states, { foo: 'bar' }); | ||
assert(baz && baz.toString() === '"qux"'); | ||
}); | ||
it(`shouldn't parse unfinished blockstate`, () => { | ||
const input = 'minecraft:command_block[conditional=false,facing=down]{Command:"fill'; | ||
try { | ||
new block_state_1.BlockState(input).toString(); | ||
assert(false); | ||
} | ||
catch (_a) { | ||
} | ||
}); | ||
}); | ||
describe('toString() tests', () => { | ||
it('should return name', () => { | ||
const input = 'spgoding:foobar'; | ||
const actual = new block_state_1.BlockState(input).toString(); | ||
assert(actual === input); | ||
}); | ||
it('should return states', () => { | ||
const input = 'spgoding:foobar[baz=qux]'; | ||
const actual = new block_state_1.BlockState(input).toString(); | ||
assert(actual === input); | ||
}); | ||
it('should return nbt', () => { | ||
const input = 'spgoding:foobar{baz:"qux"}'; | ||
const actual = new block_state_1.BlockState(input).toString(); | ||
assert(actual === input); | ||
}); | ||
it('should return both states and nbt', () => { | ||
const input = 'spgoding:sf[foo=bar]{baz:"qux"}'; | ||
const actual = new block_state_1.BlockState(input).toString(); | ||
assert(actual === input); | ||
}); | ||
}); | ||
}); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("mocha"); | ||
const assert = require("power-assert"); | ||
const block_state_1 = require("../../utils/block_state"); | ||
describe('BlockState tests', () => { | ||
describe('constructor() tests', () => { | ||
it('should parse single name', () => { | ||
const input = 'spgoding:foobar'; | ||
const actual = new block_state_1.BlockState(input); | ||
assert(actual.name === 'spgoding:foobar'); | ||
}); | ||
it('should parse empty state', () => { | ||
const input = 'spgoding:foobar[]'; | ||
const actual = new block_state_1.BlockState(input); | ||
assert.deepEqual(actual.states, {}); | ||
}); | ||
it('should parse a single state', () => { | ||
const input = 'spgoding:foobar[foo=bar]'; | ||
const actual = new block_state_1.BlockState(input); | ||
assert.deepEqual(actual.states, { foo: 'bar' }); | ||
}); | ||
it('should parse states ending with a comma', () => { | ||
const input = 'spgoding:foobar[foo=bar,]'; | ||
const actual = new block_state_1.BlockState(input); | ||
assert.deepEqual(actual.states, { foo: 'bar' }); | ||
}); | ||
it('should parse multiple states', () => { | ||
const input = 'spgoding:foobar[foo=bar,baz=qux]'; | ||
const actual = new block_state_1.BlockState(input); | ||
assert.deepEqual(actual.states, { foo: 'bar', baz: 'qux' }); | ||
}); | ||
it('should parse single nbt', () => { | ||
const input = 'spgoding:foobar{foo:bar}'; | ||
const actual = new block_state_1.BlockState(input); | ||
const foo = actual.nbt.get('foo'); | ||
assert(foo && foo.toString() === '"bar"'); | ||
}); | ||
it('should parse both states and nbt', () => { | ||
const input = 'spgoding:foobar[foo=bar]{baz:qux}'; | ||
const actual = new block_state_1.BlockState(input); | ||
const baz = actual.nbt.get('baz'); | ||
assert.deepEqual(actual.states, { foo: 'bar' }); | ||
assert(baz && baz.toString() === '"qux"'); | ||
}); | ||
it(`shouldn't parse unfinished blockstate`, () => { | ||
const input = 'minecraft:command_block[conditional=false,facing=down]{Command:"fill'; | ||
try { | ||
new block_state_1.BlockState(input).toString(); | ||
assert(false); | ||
} | ||
catch (_a) { | ||
} | ||
}); | ||
}); | ||
describe('toString() tests', () => { | ||
it('should return name', () => { | ||
const input = 'spgoding:foobar'; | ||
const actual = new block_state_1.BlockState(input).toString(); | ||
assert(actual === input); | ||
}); | ||
it('should return states', () => { | ||
const input = 'spgoding:foobar[baz=qux]'; | ||
const actual = new block_state_1.BlockState(input).toString(); | ||
assert(actual === input); | ||
}); | ||
it('should return nbt', () => { | ||
const input = 'spgoding:foobar{baz:"qux"}'; | ||
const actual = new block_state_1.BlockState(input).toString(); | ||
assert(actual === input); | ||
}); | ||
it('should return both states and nbt', () => { | ||
const input = 'spgoding:sf[foo=bar]{baz:"qux"}'; | ||
const actual = new block_state_1.BlockState(input).toString(); | ||
assert(actual === input); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.