Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

. #1

Merged
merged 2 commits into from Feb 12, 2019
Merged

. #1

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .vscode/extensions.json
@@ -0,0 +1,8 @@
{
"recommendations": [
"ms-vscode.vscode-typescript-tslint-plugin"
],
"unwantedRecommendations": [
"pca.datapack-helper"
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,10 @@
{
"json.schemas": [
{
"fileMatch": [
"/ref/commands.json"
],
"url": "/ref/commands.schema.json"
}
]
}
44 changes: 44 additions & 0 deletions .vscode/tasks.json
@@ -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
}
}
]
}
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -10,6 +10,13 @@ Also called 'spu'. An online tool that can help you update minecraft commands.

Type [https://spu.spgoding.com](https://spu.spgoding.com) in the web browser, or open the [./docs/index.html](https://github.com/CommandBlockLogic/spu/blob/master/docs/index.html) locally.

## File Structure

- `src`: Main typescript codes and a few jsx files under `./view/`.
- `js`: All compiled js files. Files in `/src/view/` will import js from this directory.
- `dist`: Temp directory.
- `docs`: The web page showed on https://spu.spgoding.com.

## How it Works

The *WheelChief* will try to parse your command(s) when you click 'Update'. All commands is stored in a `CmdNode`, whose format is very similiar to the format of the `commands.json` file that data generator provides:
Expand Down
57 changes: 28 additions & 29 deletions docs/bundle.min.js

Large diffs are not rendered by default.

142 changes: 65 additions & 77 deletions js/index.js
@@ -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;
156 changes: 78 additions & 78 deletions js/test/utils/block_state.js
@@ -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);
});
});
});