WIP Copy / Paste
This commit is contained in:
parent
7841b64284
commit
3c55bd3c19
@ -14,6 +14,10 @@ LZ-String, Copyright 2013 pieroxy under MIT license https://github.com/pieroxy/l
|
|||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
### 0.4.11
|
||||||
|
|
||||||
|
* Copy and Paste
|
||||||
|
|
||||||
### 0.4.10
|
### 0.4.10
|
||||||
|
|
||||||
* Draw optimizations, the drawing loop has been considerably optimized.
|
* Draw optimizations, the drawing loop has been considerably optimized.
|
||||||
|
@ -324,7 +324,7 @@ class ICElement extends Element {
|
|||||||
getOutput(Output = 0) {
|
getOutput(Output = 0) {
|
||||||
if (super.getOutput() === 0) return false;
|
if (super.getOutput() === 0) return false;
|
||||||
if (this.Outputs.length >= Output) {
|
if (this.Outputs.length >= Output) {
|
||||||
return this.Outputs[Output].fromElement.getOutput(this.Outputs[Output].Input);
|
return this?.Outputs[Output]?.fromElement?.getOutput(this?.Outputs[Output]?.Input);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -153,6 +153,16 @@ function KeybindToString(binding) {
|
|||||||
return kbs;
|
return kbs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function GetCopyObject() {
|
||||||
|
if (logicEngine?.ActiveContainer?.Selected?.length > 0) {
|
||||||
|
let copyObject = {};
|
||||||
|
copyObject.Elements = logicEngine.ActiveContainer.Selected;
|
||||||
|
return copyObject;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function BuildTopMenu() {
|
function BuildTopMenu() {
|
||||||
// Make sure settings are set correct
|
// Make sure settings are set correct
|
||||||
if (logicEngine.Settings.HideConnections) {
|
if (logicEngine.Settings.HideConnections) {
|
||||||
@ -335,6 +345,87 @@ function download(filename, savestate) {
|
|||||||
document.body.removeChild(element);
|
document.body.removeChild(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPastedElementDesignator(map,element) {
|
||||||
|
for (let a = 0; a < map?.length; a++) {
|
||||||
|
if (map[a].Old == element) return map[a].New;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadActiveContainer(Elements) {
|
||||||
|
|
||||||
|
let elementConnections = new Array();
|
||||||
|
let icelementConnections = new Array();
|
||||||
|
let designatorMap = new Array();
|
||||||
|
|
||||||
|
for (let a = 0; a < Elements.length; a++) {
|
||||||
|
if (Elements[a].IsIC) {
|
||||||
|
let classRef = getElementInfo(Elements[a].Name).Class;
|
||||||
|
if (!classRef) {
|
||||||
|
// We need to add this IC to the toolbox
|
||||||
|
let newIC = createIC(JSON.stringify(Elements[a].ICBlueprint),Elements[a].Name,Elements[a].Description);
|
||||||
|
//console.log("NewIC:" + newIC);
|
||||||
|
if (!newIC) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let classRef = getElementInfo(Elements[a].Name).Class;
|
||||||
|
|
||||||
|
let newElement = new classRef(logicEngine.ActiveContainer,Elements[a],logicEngine,getElementInfo(Elements[a].Name).Args[0]);
|
||||||
|
|
||||||
|
logicEngine.ActiveContainer.AddElement(newElement);
|
||||||
|
designatorMap.push({Old: Elements[a].Designator, New: newElement.Designator});
|
||||||
|
|
||||||
|
if (Elements[a].Outputs) {
|
||||||
|
if (Elements[a].Outputs.length > 0) {
|
||||||
|
for (let b=0; b < Elements[a].Outputs.length; b++) {
|
||||||
|
elementConnections.push({
|
||||||
|
FromElement: newElement,
|
||||||
|
Input: Elements[a].Outputs[b].Input,
|
||||||
|
Output: Elements[a].Outputs[b].Output,
|
||||||
|
ToElement: Elements[a].Outputs[b].Element
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Elements[a].ICOutputs) {
|
||||||
|
if (Elements[a].ICOutputs.length > 0) {
|
||||||
|
for (let b=0; b < Elements[a].ICOutputs.length; b++) {
|
||||||
|
icelementConnections.push({
|
||||||
|
Element: newElement,
|
||||||
|
FromContainer: newElement.Container,
|
||||||
|
FromElement: Elements[a].ICOutputs[b].fromElement,
|
||||||
|
Input: Elements[a].ICOutputs[b].Input,
|
||||||
|
ToElement: Elements[a].ICOutputs[b].toElement
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let a = 0; a < elementConnections.length; a++) {
|
||||||
|
let toElement = logicEngine.ActiveContainer.HasElement(getPastedElementDesignator(designatorMap,elementConnections[a].ToElement));
|
||||||
|
if (toElement) {
|
||||||
|
if (elementConnections[a].FromContainer) {
|
||||||
|
let fromElement = elementConnections[a].FromContainer.HasElement(elementConnections[a].fromElement);
|
||||||
|
let newConnection = new ContainerConnection(elementConnections[a].FromContainer,logicEngine.ActiveContainer,fromElement,toElement,elementConnections[a].Input);
|
||||||
|
elementConnections[a].Element.Outputs.push(newConnection);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
let newConnection = new ElementConnection(logicEngine.ActiveContainer, toElement, elementConnections[a].Input, elementConnections[a].Output);
|
||||||
|
if (newConnection) {
|
||||||
|
elementConnections[a].FromElement.addConnection(logicEngine.ActiveContainer,toElement,elementConnections[a].Input, elementConnections[a].Output)
|
||||||
|
} else {
|
||||||
|
console.log("We dont have a new connection!!!");
|
||||||
|
console.log(toElement);
|
||||||
|
console.log(elementConnections[a]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function loadContainer(Elements) {
|
function loadContainer(Elements) {
|
||||||
let newContainer = new elementContainer();
|
let newContainer = new elementContainer();
|
||||||
let elementConnections = new Array();
|
let elementConnections = new Array();
|
||||||
|
@ -147,9 +147,9 @@ class LogicEngineSettings {
|
|||||||
Name: "Toggle FPS",
|
Name: "Toggle FPS",
|
||||||
Description: "Show / Hide FPS counter",
|
Description: "Show / Hide FPS counter",
|
||||||
Category: "View"},
|
Category: "View"},
|
||||||
CreateIC: {Key: "c", // lowercase
|
CreateIC: {Key: "i", // lowercase
|
||||||
Alt: false,
|
Alt: false,
|
||||||
Shift: false,
|
Shift: true,
|
||||||
Ctrl: true,
|
Ctrl: true,
|
||||||
Meta: false,
|
Meta: false,
|
||||||
Name: "Create IC",
|
Name: "Create IC",
|
||||||
|
33
js/main.js
33
js/main.js
@ -2,7 +2,7 @@
|
|||||||
MatCat BrowserLogic Simulator
|
MatCat BrowserLogic Simulator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let Version = "0.4.10";
|
let Version = "0.4.11";
|
||||||
|
|
||||||
let spanVersion = document.getElementById("version");
|
let spanVersion = document.getElementById("version");
|
||||||
spanVersion.innerText = Version;
|
spanVersion.innerText = Version;
|
||||||
@ -18,6 +18,37 @@ window.addEventListener('resize', function(evt) {
|
|||||||
logicEngine.Resize(evt);
|
logicEngine.Resize(evt);
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
document.addEventListener('copy', function(evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
let copyObject = GetCopyObject();
|
||||||
|
if (!copyObject) return;
|
||||||
|
|
||||||
|
evt.clipboardData.setData('logicparts/json',JSON.stringify(copyObject));
|
||||||
|
evt.clipboardData.setData('text',JSON.stringify(copyObject));
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('cut', function(evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
let copyObject = GetCopyObject();
|
||||||
|
if (!copyObject) return;
|
||||||
|
|
||||||
|
evt.clipboardData.setData('logicparts/json',JSON.stringify(copyObject));
|
||||||
|
evt.clipboardData.setData('text',JSON.stringify(copyObject));
|
||||||
|
|
||||||
|
logicEngine.Key_Press({ctrlKey: false, key: "Delete"});
|
||||||
|
disableSelectedRCMs(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
document.addEventListener('paste', function(evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
if (evt.clipboardData.getData('logicparts/json')) {
|
||||||
|
//console.log(evt.clipboardData.getData('logicparts/json'));
|
||||||
|
loadActiveContainer(JSON.parse(evt.clipboardData.getData('logicparts/json')).Elements);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
window.addEventListener('keydown', function(evt) {
|
window.addEventListener('keydown', function(evt) {
|
||||||
logicEngine.Key_Press(evt);
|
logicEngine.Key_Press(evt);
|
||||||
}, false);
|
}, false);
|
||||||
|
Loading…
Reference in New Issue
Block a user