Skip to content

Commit

Permalink
Update to 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Fechner authored and Florian Fechner committed Feb 25, 2018
1 parent 6d780ca commit adbd57a
Show file tree
Hide file tree
Showing 13 changed files with 279 additions and 143 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"paper-fab": "^2.0.0",
"web-animations-js": "^2.3.1",
"paper-dialog": "PolymerElements/paper-dialog#^2.0.1",
"file-drop-zone": "PolymerVis/file-drop-zone#^2.0.3"
"voxel-visualization": "^1.0.5"
}
}
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
body
{
height: 100%;

padding: 0;
margin: 0;
}
Expand Down
81 changes: 25 additions & 56 deletions main-process/calculateOrigami/calculateOrigami.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ function calculateOrigami(data, onCalculationFinished)

const blockTexturePath = path.join(data.texturePackPath, "assets/minecraft/textures/blocks");

console.log("DATA:", data);

fs.readdir(blockTexturePath, (err, files) =>
{
let textures = files.map((file) =>
Expand All @@ -22,39 +24,40 @@ function calculateOrigami(data, onCalculationFinished)
{
if (err) throw err;

parseSchematicFile(data.minecraftSchematicPath, (schema) =>
{
let dimension = Math.max(schema.width, schema.height, schema.length);
let voxelData = Array(dimension * dimension * dimension).fill({type: 0, metaType: 0});
let schema = data.schematic;

console.log(schema.width, schema.height, schema.depth);

for(let x=0; x<schema.width; x++)
let dimension = Math.max(schema.width, schema.height, schema.depth);
let voxelData = Array(dimension * dimension * dimension).fill({type: 0, metaType: 0});

for(let x=0; x<schema.width; x++)
{
for(let y=0; y<schema.height; y++)
{
for(let y=0; y<schema.height; y++)
for(let z=0; z<schema.depth; z++)
{
for(let z=0; z<schema.length; z++)
{
let block = schema.blocks[x + y * schema.length * schema.width + z * schema.width];
let block = schema.blocks[x + y * schema.depth * schema.width + z * schema.depth];

if(blockIdList[charToUnsignedChar(block.id)] != undefined)
{
voxelData[x + dimension * y + dimension * dimension * z] = { type: charToUnsignedChar(block.id), metaType: block.metaData };
}
if(blockIdList[charToUnsignedChar(block.id)] != undefined)
{
voxelData[x + dimension * y + dimension * dimension * z] = { type: charToUnsignedChar(block.id), metaType: block.metaData };
}
}
}
}

let context = m2o.orthogami(
voxelData, dimension, dimension, dimension
);
let context = m2o.orthogami(
voxelData, dimension, dimension, dimension
);

context.texturePath = path.join(data.texturePackPath, "assets/minecraft/textures/blocks");
context.textures = textures;
context.texturePath = path.join(data.texturePackPath, "assets/minecraft/textures/blocks");
context.textures = textures;

let template = Handlebars.compile(source);
let html = template(context);
let template = Handlebars.compile(source);
let html = template(context);

onCalculationFinished(html);
});
onCalculationFinished(html);
});
});
}
Expand Down Expand Up @@ -155,40 +158,6 @@ function registerHandlebarsHelper(Handlebars, blockIdList)
});
}

function parseSchematicFile(fileName, onCalculationFinished)
{
let nbt = require('nbt');

let data = fs.readFileSync(fileName);

let schematic = {};

nbt.parse(data, (error, data) =>
{
if (error) { throw error; }

schematic.width = data.value.Width.value;
schematic.height = data.value.Height.value;
schematic.length = data.value.Length.value;

let blockIds = data.value.Blocks.value;
let metaData = data.value.Data.value;

let blocks = [];

for(let i=0; i<blockIds.length; i++)
{
blocks.push({ id: blockIds[i], metaData: metaData[i] });
}

schematic.blocks = blocks;

onCalculationFinished(schematic);
});

return schematic;
}

function charToUnsignedChar(char)
{
if(char > 0) return char;
Expand Down
55 changes: 55 additions & 0 deletions main-process/parseSchematicFile/parseSchematicFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const path = require('path');
const fs = require('fs');

function parseSchematicFile(fileName, onCalculationFinished)
{
let nbt = require('nbt');

let data = fs.readFileSync(fileName);

let schematic = {};

nbt.parse(data, (error, data) =>
{
if (error) { throw error; }

let width = data.value.Width.value;
let height = data.value.Height.value;
let length = data.value.Length.value;

let dimension = Math.max(width, height, length);

let blockIds = data.value.Blocks.value;
let metaData = data.value.Data.value;

let blocks = new Array(dimension * dimension * dimension).fill({ id: 0, metaData: 0 });

for(let x=0; x<width; x++)
{
for(let y=0; y<height; y++)
{
for(let z=0; z<length; z++)
{
let blockId = blockIds[x + y * length * width + z * width];
let blockMetaData = metaData[x + y * length * width + z * width];

blocks[x + y * dimension + z * dimension * dimension] = { id: charToUnsignedChar(blockId), metaData: blockMetaData };
}
}
}

let schematic = { width: dimension, height: dimension, depth: dimension, blocks : blocks };

onCalculationFinished(schematic);
});

return schematic;
}

function charToUnsignedChar(char)
{
if(char > 0) return char;
return (256 + char);
}

module.exports = parseSchematicFile;
31 changes: 31 additions & 0 deletions main-process/uploadTexturePack/uploadTexturePack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

let alternate = false;

function uploadTexturePack(filePath, callback)
{
const fs = require('fs');
const app = require('electron').app;
const path = require("path");
const unzip = require("unzip");

const applicationPath = path.join('../../package.json');
const applicationName = require(applicationPath).name;
const appDataPath = app.getPath("appData");
const fileStoragePath = path.join(appDataPath, applicationName);

const texturePackPath = path.join(fileStoragePath, "texture-pack", path.basename(filePath, '.zip'));


alternate = !alternate;

fs.createReadStream(filePath)
.pipe(
unzip.Extract({ path: texturePackPath })
.on('close', () =>
{
callback(texturePackPath);
})
);
}

module.exports = uploadTexturePack;
21 changes: 21 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const ipcMain = electron.ipcMain;
const path = require('path');
const url = require('url');
const fs = require('fs');

const calculateOrigami = require('./main-process/calculateOrigami/calculateOrigami');
const parseSchematicFile = require('./main-process/parseSchematicFile/parseSchematicFile');
const uploadTexturePack = require('./main-process/uploadTexturePack/uploadTexturePack');

let browserWindow = null;

Expand Down Expand Up @@ -128,6 +131,24 @@ app.on('ready', () =>
{
createWindow();

ipcMain.on("parseSchematicFile", (event, data) =>
{
parseSchematicFile(data.schematicPath, (schematic) =>
{
event.sender.send("parseSchematicFileFinished", { schematic: schematic });
});
});

ipcMain.on("uploadTexturePack", (event, data) =>
{
let texturePackSourcePath = data.sourcePath;

uploadTexturePack(texturePackSourcePath, (texturePackPath) =>
{
event.sender.send("uploadTexturePackFinished", { texturePackPath: texturePackPath });
});
});

ipcMain.on("startSchematicToOrigamiCalculation", (event, data) =>
{
calculateOrigami(data, (html) =>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "PaperCubes",
"version": "1.2.0",
"version": "1.2.1",
"description": "Electron app for building blueprints for minecraft origami",
"main": "main.js",
"scripts": {
Expand Down
68 changes: 57 additions & 11 deletions paper-cubes/configuration-page/configuration-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<link rel="import" href="../../bower_components/paper-input/paper-input.html">
<link rel="import" href="../../bower_components/paper-swatch-picker/paper-swatch-picker.html">
<link rel="import" href="../../bower_components/paper-toast/paper-toast.html">
<link rel="import" href="../../bower_components/voxel-visualization/voxel-visualization.html">

<link rel="import" href="../processing-page/processing-page.html">

<!-- Defines element markup -->
<dom-module id="configuration-page">
Expand All @@ -17,6 +20,8 @@
:host
{
display: block;
width: 100%;
height: calc(100% - 5px);
}

paper-card
Expand All @@ -28,18 +33,41 @@

.align-right
{
position: absolute;
right: 10px;
bottom: 10px;
text-align: right;
margin: 10px;
}

.flex-container
{
display: flex;
height: 100%;
width: 100%;
top: 10px;
left: 10px;
}

.flex-item
{
flex: 1;
height: 100%;
padding: 5px;
}

.flex-item-2
{
flex: 2;
height: 100%;
padding: 5px;
}

.flex-item-3
{
flex: 3;
height: 100%;
padding: 5px;
}

paper-button
Expand All @@ -60,23 +88,41 @@
--paper-toast-color: #f00;
}

vaadin-upload
#voxel-visualization
{
height: 85px;
width: 100%;
height: 100%;
}

</style>

<vaadin-upload id="minecraft-schematic-file-upload" max-files="1">
<span slot="drop-label">Drop Minecraft Schematic here...</span>
</vaadin-upload>
<br>
<vaadin-upload id="minecraft-texture-pack-upload" max-files="1">
<span slot="drop-label">Drop Minecraft Texture Pack here...</span>
</vaadin-upload>
<br>
<div class="flex-container">
<div class="flex-item-2">
<vaadin-upload id="schematic-file-upload" max-files="1">
<span slot="drop-label">Drop Minecraft Schematic here...</span>
</vaadin-upload>
<br>
<vaadin-upload id="texture-pack-upload" max-files="1">
<span slot="drop-label">Drop Minecraft Texture Pack here...</span>
</vaadin-upload>
</div>

<div class="flex-item-3">
<template is="dom-if" if="[[not(loading)]]">
<voxel-visualization
id="voxel-visualization"
schematic="[[schematic]]"
texture-pack-path="[[texturePackPath]]"
></voxel-visualization>
</template>
<template is="dom-if" if="[[loading]]">
<processing-page></processing-page>
</template>
</div>
</div>

<div class="align-right">
<paper-button disabled="[[isNotReadyForCalculation(condition1, condition2)]]" id="continue-button">continue</paper-button>
<paper-button disabled="[[isNotReadyForCalculation(schematic, texturePackPath)]]" id="continue-button">continue</paper-button>
</div>
</template>

Expand Down
Loading

0 comments on commit adbd57a

Please sign in to comment.