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

Synchronize NC plugin at different backends #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 44 additions & 46 deletions src/plugin/nc/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { systemInstance as system, Description, Usage, Block, Coordinate, Position, BlockType, BuildInstruction, canonicalGeneratorFactory } from 'norma-core';
import { utils } from '../utils.js';
import * as preset from './presetBuildingsInterface.js';
Expand Down Expand Up @@ -45,7 +44,7 @@ system.registerCanonicalGenerator({
},
method: {
generate: function (e) {
let { state } = e
let { state, runtime } = e;
let { positions, blockTypes, directions } = state

let halt = false
Expand Down Expand Up @@ -103,7 +102,7 @@ system.registerCanonicalGenerator({
else {
let blocks = []

//logger.log("verbose", "NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "NZ is JULAO!")

let minCoordinate = new Coordinate(
Math.min(positions[0].coordinate.x, positions[1].coordinate.x),
Expand All @@ -116,7 +115,7 @@ system.registerCanonicalGenerator({
Math.max(positions[0].coordinate.z, positions[1].coordinate.z)
)

//logger.log("verbose", "Yes, NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "Yes, NZ is JULAO!")

for (let x = minCoordinate.x; x <= maxCoordinate.x; x++) {
for (let y = minCoordinate.y; y <= maxCoordinate.y; y++) {
Expand All @@ -137,7 +136,7 @@ system.registerCanonicalGenerator({
}
},
UIHandler: function (e) {
let { state, data } = e;
let { state, data, runtime } = e;
let { positions, blockTypes, directions } = state;
if (data == "resetAll") {
positions.fill(undefined);
Expand Down Expand Up @@ -174,7 +173,7 @@ system.registerCanonicalGenerator({
},
method: {
generate: function (e) {
let { state } = e;
let { state, runtime } = e;
if (state.generateByServer)
return [{
"type": "clone",
Expand Down Expand Up @@ -239,17 +238,17 @@ let createLineGenerator = canonicalGeneratorFactory({
},
method: {
generate: function (e) {
let { state } = e;
let { state, runtime } = e;
let blockArray = [];

//let logger = runtime.logger;
//logger.log("verbose", "NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "NZ is JULAO!")

let positionArray = state.positions
let blockTypeArray = state.blockTypes
let directionArray = state.directions

//logger.log("verbose", "Yes, NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "Yes, NZ is JULAO!")


let direction = (function () {
Expand Down Expand Up @@ -320,7 +319,7 @@ let createLineGenerator = canonicalGeneratorFactory({
}
})

createLineGenerator.addPosition = function () {
createLineGenerator.onAddPosition = function (e) {
let { state, position, runtime } = e;
if (state.doAcceptNewPosition) {
let indexOfVacancy = state.positions.indexOf(undefined)
Expand Down Expand Up @@ -408,16 +407,16 @@ system.registerCanonicalGenerator({
},
method: {
generate: function (e) {
let { state } = e;
let { state, runtime } = e;
let blockArray = []

//logger.log("verbose", "NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "NZ is JULAO!")

let positionArray = state.positions
let blockTypeArray = state.blockTypes
let directionArray = state.directions

//logger.log("verbose", "Yes, NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "Yes, NZ is JULAO!")

//{"blockIdentifier":"minecraft:stained_hardened_clay","blockState":{"color":"cyan"}}

Expand Down Expand Up @@ -585,23 +584,22 @@ system.registerCanonicalGenerator({
// following are postGenerate
state.positions = [undefined]
if (state["roadStyle"] == "custom") state.blockTypes = [undefined, undefined, undefined, undefined];
else state.blockTypeArray = [];
state.blockTypes = [];
else state.blockTypes = [];
state.directions = [undefined];
return blockArray
},
UIHandler: function (e) {
let { state, data } = e;
let { state, data, runtime } = e;
if (data == "custom") {
//logger.log("info", "Using custom materials.")
//logger.log("info", "First block type for surface.")
//logger.log("info", "Second for white line.")
//logger.log("info", "Third for yellow line.")
//logger.log("info", "Fourth for bar.")
runtime.logger && runtime.logger.log("info", "Using custom materials.")
runtime.logger && runtime.logger.log("info", "First block type for surface.")
runtime.logger && runtime.logger.log("info", "Second for white line.")
runtime.logger && runtime.logger.log("info", "Third for yellow line.")
runtime.logger && runtime.logger.log("info", "Fourth for bar.")
state.blockTypes = [undefined, undefined, undefined, undefined]
}
else {
//logger.log("info", "Using preset materials. Custom materials are erased!")
runtime.logger && runtime.logger.log("info", "Using preset materials. Custom materials are erased!")
state.blockTypes = []
}
}
Expand Down Expand Up @@ -643,15 +641,15 @@ system.registerCanonicalGenerator({
},
method: {
generate: function (e) {
let { state } = e;
let { state, runtime } = e;
let blockArray = []

//logger.log("verbose", "NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "NZ is JULAO!")

let positionArray = state.positions
let blockTypeArray = state.blockTypes
let directionArray = state.directions
//logger.log("verbose", "Yes, NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "Yes, NZ is JULAO!")

let directionMark = (function () {
if (-45 <= directionArray[0].y && directionArray[0].y <= 45) return "+z"
Expand Down Expand Up @@ -824,15 +822,15 @@ system.registerCanonicalGenerator({
},
method: {
generate: function (e) {
let { state } = e;
let { state, runtime } = e;
let blockArray = []

//logger.log("verbose", "NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "NZ is JULAO!")

let positionArray = state.positions
let blockTypeArray = state.blockTypes

//logger.log("verbose", "Yes, NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "Yes, NZ is JULAO!")

let coordinateArray = utils.coordinateGeometry.generateFilledPlanarTriangle(
positionArray[0].coordinate.x, positionArray[0].coordinate.y, positionArray[0].coordinate.z,
Expand Down Expand Up @@ -874,9 +872,9 @@ system.registerCanonicalGenerator({
},
method: {
generate: function (e) {
let { state } = e;
let { state, runtime } = e;
if (state.generateByServer) {
//logger.log("verbose", "NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "NZ is JULAO!")

let x_min = Math.min(state.positions[0].coordinate.x, state.positions[1].coordinate.x)
let z_min = Math.min(state.positions[0].coordinate.z, state.positions[1].coordinate.z)
Expand All @@ -901,7 +899,7 @@ system.registerCanonicalGenerator({
else {
let blockArray = []

//logger.log("verbose", "NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "NZ is JULAO!")

let positionArray = state.positions
let blockTypeArray = state.blockTypes
Expand Down Expand Up @@ -969,10 +967,10 @@ system.registerCanonicalGenerator({
},
method: {
generate: function (e) {
let { state } = e;
let { state, runtime } = e;
let blockArray = [];

//logger.log("verbose", "NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "NZ is JULAO!")

let positionArray = state.positions

Expand Down Expand Up @@ -1025,12 +1023,12 @@ system.registerCanonicalGenerator({
},
method: {
generate: function (e) {
let { state } = e;
let { state, runtime } = e;
let blockArray = []



//logger.log("verbose", "NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "NZ is JULAO!")

let positionArray = state.positions
let blockTypeArray = state.blockTypes
Expand Down Expand Up @@ -1092,12 +1090,12 @@ system.registerCanonicalGenerator({
},
method: {
generate: function (e) {
let { state } = e;
let { state, runtime } = e;
let blockArray = []



//logger.log("verbose", "NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "NZ is JULAO!")

let positionArray = state.positions
let blockTypeArray = state.blockTypes
Expand Down Expand Up @@ -1145,7 +1143,7 @@ let flagGenerator = canonicalGeneratorFactory({
},
method: {
generate: function (e) {
let { state } = e;
let { state, runtime } = e;
let blockArray = []
let positionArray = state.positions;
let option = state;
Expand Down Expand Up @@ -1178,7 +1176,7 @@ flagGenerator.isValidParameter = function (e) {
if (state.height % 2 != 0) result += "The height is odd!"
if (result == "") return true;

runtime.logger && runtime.logger.log("info", result);
runtime.logger && runtime.logger.log("error", result);
return false;
};

Expand Down Expand Up @@ -1229,16 +1227,16 @@ system.registerCanonicalGenerator({
},
method: {
generate: function (e) {
let { state } = e;
let { state, runtime } = e;
let blockArray = []

//logger.log("verbose", "NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "NZ is JULAO!")

let positionArray = state.positions;
let blockTypeArray = state.blockTypes;
let directionArray = state.directions;
let option = state;
//logger.log("verbose", "Yes, NZ is JULAO!")
runtime.logger && runtime.logger.log("verbose", "Yes, NZ is JULAO!")

const directionMark = utils.geometry.getDirectionMark.horizontal(directionArray[0].y)

Expand Down Expand Up @@ -1297,7 +1295,7 @@ system.registerCanonicalGenerator({
},
"rail": function (coordinate) { return materials["rail"] },
"void/redstone": function (coordinate) {
//logger.logObject("debug", coordinate)
runtime.logger && runtime.logger.logObject("debug", coordinate)
if (coordinate.x % 16 == 0) return materials["red_stone_torch"]
else return materials["air"]
}
Expand Down Expand Up @@ -1570,8 +1568,8 @@ system.registerCanonicalGenerator({
option: {},
method: {
UIHandler: function () { }, generate: function (e) {
let { state } = e;
return new BuildInstruction("writeBuildingStructureToLog", {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you changed the corresponding compile mechanism?

let { state, runtime } = e;
return new BuildInstruction("writeBuildingStructure", {
startCoordinate: state.positions[0].coordinate,
endCoordinate: state.positions[1].coordinate,
referenceCoordinate: state.positions[2].coordinate,
Expand All @@ -1587,7 +1585,7 @@ system.registerCanonicalGenerator({
option: {},
method: {
generate: function (e) {
let { state } = e;
let { state, runtime } = e;
let coordinate = state.positions[0].coordinate

return Array.from(preset.presetBuildings.subway_station, a => new Block(new Position(new Coordinate(
Expand Down