Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions Source/Engine/Dropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,21 @@ let DROPPER_OVERRIDE = false
//=========//
// This function is the messy result of adding one line of code every two weeks without much thought
let dropperShadowReady = [false].repeated(9)

let dropAtomArgs = {shouldDropFromTop: false, elementName: undefined};

const dropAtom = (x, y, z, yOffset = 0, justShow = false, shadowNumber = 0, yOverride = Math.floor(DROPPER_HEIGHT)) => {
if (!UI) return
if (UI.selectedElement === undefined) return
const atomType = UI.selectedElement
const dropStart = MAX_Y - yOverride
const atomType = (dropAtomArgs.elementName != undefined) ? SpaceTode.global.elements[dropAtomArgs.elementName] : UI.selectedElement;
const dropStart = (dropAtomArgs.shouldDropFromTop) ? MAX_Y : MAX_Y - yOverride;
let alteredY = dropStart + yOffset
let alteredZ = z
if (D2_MODE) alteredY = y
if (D2_MODE) alteredZ = 0
if (D1_MODE) alteredY = 0
const space = WORLD.selectSpace(world, x, alteredY, alteredZ)

if (space.atom.element == Void) {
if (justShow) dropperShadow[shadowNumber].visible = false
return
Expand Down Expand Up @@ -258,4 +262,12 @@ let DROPPER_OVERRIDE = false
}
}

// This function is the pondering result of adding one line of code and then two more to change an object array
function dropAtomCall(x, y, z, elementName){
dropAtomArgs = {shouldDropFromTop: true, elementName: elementName};

dropAtom(x, y, z);

dropAtomArgs = {shouldDropFromTop: false, elementName: undefined};
}
}
87 changes: 87 additions & 0 deletions Source/Engine/Save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//carelessly constructed by davidsover d:
{
let globalGridLoadState = {arr: {}, y: -1};

function loadWorldGridFromArray(arr, y){
if (arr != undefined){
globalGridLoadState = {arr: arr, y: y};
} else{
arr = globalGridLoadState.arr;
y = globalGridLoadState.y;
}

if (y == -1 || y == undefined){
y = 0;
globalGridLoadState.y = y;
}

let highestY = 0;

let didDrop = false;
for (let element in arr){
for (let i in arr[element][y]){
dropAtomCall(arr[element][y][i][0], y, arr[element][y][i][1], element);

didDrop = true;
}

if (highestY < arr[element].length - 1){
highestY = arr[element].length - 1;
}
}

globalGridLoadState.y++;

if (globalGridLoadState.y <= highestY){
let timeoutLength = (didDrop) ? 50 : 1;

setTimeout(loadWorldGridFromArray, timeoutLength);
}
}

function saveWorldGridAsArray(isElementless){
let elements = {};

let arr = [];

for (let i in world.grid){
arr[i] = [];
for (let j in world.grid[i]){
for (let k in world.grid[i][j]){
if (world.grid[i][j][k].atom.visible){
arr[i].push([Number(j), Number(k)]);

let elementName = world.grid[i][j][k].atom.element.name;

if (elements[elementName] == undefined){
elements[elementName] = [];
}

if (elements[elementName][i] == undefined){
elements[elementName][i] = [];
}

elements[elementName][i].push([Number(j), Number(k)]);
}
}
}
}
return (isElementless) ? arr : elements;
}

function saveWorldGridToInput(){
document.getElementById("saveId").value = JSON.stringify(saveWorldGridAsArray());
}


function copyWorldGridSave(){
navigator.clipboard.writeText(document.getElementById("saveId").value);
}


function loadWorldGrid(){
let arr = JSON.parse(document.getElementById("loadId").value); //parse never went wrong in the history of humanity

loadWorldGridFromArray(arr);
}
}
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
<script src="Source/Engine/Site.js"></script>
<script src="Source/Engine/Random.js"></script>

<script src="Source/Engine/Save.js"></script>

<!-- Elements -->
<script src="Source/Elements/Globals.js"></script>
<script src="Source/Elements/State.js"></script>
Expand Down
8 changes: 7 additions & 1 deletion ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,17 @@ let secretMessageTimer = 0
<div class="heading box clickable" id="modeHeading"><div class="label">Mode</div></div>
<div class="heading box clickable" id="controlsHeading"><div class="label">Controls</div></div>
<div class="heading box clickable" id="sourceHeading"><div class="label">Source</div></div>
<div class="heading box clickable" id="saveHeading"><div class="label">Save</div></div>
<!--<div class="heading box clickable" id="configHeading"><div class="label">Config</div></div>-->
</div>

<div class="windowContainer">


<div id="save" class="minimised">
Save: <button onclick="copyWorldGridSave()">Copy</button><input id="saveId"></input> <button onclick="saveWorldGridToInput()">Save</button><br><br>
Load: <input id="loadId"></input> <button onclick="loadWorldGrid()">Load</button>
</div>

<div id="source" class="minimised">
<div class="menu">
<div class="heading box clickable sourceType selected" id="todeSplatSource"><div class="label">SpaceTode</div></div>
Expand Down