Commit 88127858 authored by Christian Winter's avatar Christian Winter

Instances renamed to prefabs

parent affa0ed3
*:not(.layerbutton):not(.instancebutton):not(input)::selection {
*:not(.layerbutton):not(.prefabbutton):not(input)::selection {
background-color: Transparent;
}
......@@ -234,7 +234,7 @@ div {
border-radius: 0;
}
.toolcategory table#instances button {
.toolcategory table#prefabs button {
margin: 0px;
width: 100%;
border-radius: 0;
......@@ -244,7 +244,7 @@ div {
background: linear-gradient(#111111, #555555);
}
table#layers table#instances{
table#layers table#prefabs {
border-collapse: collapse;
}
......@@ -256,7 +256,7 @@ table #selectedLayer {
border-bottom: 1px lightblue solid;
}
table #selectedInstance {
table #selectedPrefab {
background-color: lightblue;
border-left: 1px lightblue solid;
border-right: 1px lightblue solid;
......
......@@ -17,7 +17,7 @@
<script src="scripts/input/Key.js"></script>
<script src="scripts/states/State.js"></script>
<script src="scripts/states/InstanceBrushState.js"></script>
<script src="scripts/states/PrefabBrushState.js"></script>
<script src="scripts/states/InputRecorderState.js"></script>
<script src="scripts/states/BoxSelectionState.js"></script>
<script src="scripts/states/BrushSelectionState.js"></script>
......@@ -62,8 +62,8 @@
<script src="scripts/grids/TriangleGrid.js"></script>
<script src="scripts/grids/PolarGrid.js"></script>
<script src="scripts/InstanceManager.js"></script>
<script src="scripts/Instance.js"></script>
<script src="scripts/PrefabManager.js"></script>
<script src="scripts/Prefab.js"></script>
</head>
<body onload="onLoad();">
<div id="menubar">
......@@ -219,11 +219,11 @@
</div>
<div class="toolcategory">
<p>Instances (Alpha)</p>
<button type="button" onclick="InstanceManager.createNewInstanceFromSelection()">Create new Instance from selection</button>
<p>Prefabs</p>
<button type="button" onclick="PrefabManager.createNewPrefabFromSelection()">Create new Prefab from selection</button>
</div>
<div class="toolcategory" id="instances">
<div class="toolcategory" id="prefabsDiv">
</div>
<div class="toolcategory">
......@@ -231,7 +231,7 @@
<button type="button" onclick="File.createNewLayer(true)">Create new Layer</button>
</div>
<div class="toolcategory" id="layers">
<div class="toolcategory" id="layersDiv">
</div>
<div class="toolcategory">
......
class InstanceManager {
static init() {
console.log("InstanceManager created.");
this.instances = [];
}
static addInstance(instance) {
this.instances.push(instance);
}
static createNewInstanceFromSelection() {
let newInstance = new Instance();
for (let line of Selection.data.lines.concat(Selection.data.partialLines))
newInstance.addLine(line.copy());
this.addInstance(newInstance);
//newInstance.name = newInstance.lines.length;
GUI.buildInstancesUI();
}
static editInstance(id) {
GUI.notify("Editing instances doesn't work yet.", 'green')
}
static selectInstanceWithID(id) {
Logic.setState(new InstanceBrushState(this.instances[id]));
GUI.buildInstancesUI();
}
static changeNameForInstanceWithID(id, name) {
this.instances[id].name = name;
}
static deleteInstanceWithID(id) {
// TODO convert prefabs to lines
Utilities.deleteArrayEntry(this.instances, this.instances[id]);
GUI.buildInstancesUI();
}
}
\ No newline at end of file
class Instance {
class Prefab{
constructor() {
this.position = Vector2.zero;
this.lines = [];
this.name = "Instance";
this.name = "Prefab";
}
get bounds() {
......@@ -29,11 +29,18 @@
}
copy() {
let copy = new Instance();
let copy = new Prefab();
for (let line of this.lines)
copy.addLine(line.copy());
return copy;
}
}
class PrefabInstance {
constructor(position, prefabReference) {
this.position = position;
this.reference = prefabReference;
}
}
\ No newline at end of file
class PrefabManager {
static init() {
console.log("PrefabManager created.");
this.prefabs = [];
}
static addPrefab(prefab) {
this.prefabs.push(prefab);
}
static createNewPrefabFromSelection() {
let newPrefab = new Prefab();
for (let line of Selection.data.lines.concat(Selection.data.partialLines))
newPrefab.addLine(line.copy());
this.addPrefab(newPrefab);
GUI.buildPrefabUI();
}
static editPrefab(id) {
GUI.notify("Editing prefabs doesn't work yet.", 'green')
}
static selectPrefabWithID(id) {
Logic.setState(new PrefabBrushState(this.prefabs[id]));
GUI.buildPrefabUI();
}
static changeNameForPrefabWithID(id, name) {
this.prefabs[id].name = name;
}
static deletePrefabWithID(id) {
// TODO convert prefabs to lines
Utilities.deleteArrayEntry(this.prefabs, this.prefabs[id]);
GUI.buildPrefabUI();
}
}
\ No newline at end of file
class Layer {
constructor() {
this.lines = [];
this.name = "New Layer";
this.visible = true;
this.hideInRenderPreview = false;
this.lines = [];
this.prefabInstances = [];
}
addLine(line) {
......@@ -62,6 +64,14 @@
this.changed();
}
addPrefabInstance(instance) {
this.prefabInstances.push(instance);
}
removePrefabInstance(instance) {
Utilities.deleteArrayEntry(this.prefabInstances, instance);
}
cleanUp() {
let deletedLinesCounter = 0;
// lines with length 0
......
......@@ -107,7 +107,7 @@ class MouseHandler {
else if (Logic.currentState instanceof ContinousDrawingState) {
Logic.currentState.oldPos = Logic.shouldSnap() ? currentPosition.copy() : mousePosition.copy();
}
else if (Logic.currentState instanceof InstanceBrushState) {
else if (Logic.currentState instanceof PrefabBrushState) {
Logic.currentState.place();
}
}
......@@ -172,7 +172,7 @@ class MouseHandler {
else if (Logic.currentState instanceof BrushSelectionState) {
Logic.currentState.cancel();
}
else if (Logic.currentState instanceof InstanceBrushState) {
else if (Logic.currentState instanceof PrefabBrushState) {
Logic.currentState.cancel();
}
......
......@@ -15,10 +15,10 @@
this.statsDict = [];
// Layers
this.layersDiv = document.getElementById('layers')
this.layersDiv = document.getElementById('layersDiv')
// Instances
this.instancesDiv = document.getElementById('instances')
// Prefab
this.prefabsDiv = document.getElementById('prefabsDiv')
// Toggles
this.lineHandlesToggle = document.getElementById("lineHandlesToggle");
......@@ -541,77 +541,77 @@
static buildInstancesUI() {
while (this.instancesDiv.firstChild) {
this.instancesDiv.removeChild(this.instancesDiv.firstChild);
static buildPrefabUI() {
while (this.prefabsDiv.firstChild) {
this.prefabsDiv.removeChild(this.prefabsDiv.firstChild);
}
let instances = InstanceManager.instances;
let prefabs = PrefabManager.prefabs;
let table = document.createElement("table");
table.setAttribute("id", "instances");
table.setAttribute("id", "prefabs");
// edit instance button
// edit prefab button
let col = document.createElement("col");
col.setAttribute("width", "20%");
table.appendChild(col);
// select instance button
// select prefab button
col = document.createElement("col");
col.setAttribute("width", "60%");
table.appendChild(col);
// delete instance button
// delete prefab button
col = document.createElement("col");
col.setAttribute("width", "20%");
table.appendChild(col);
for (let i = 0; i < instances.length; ++i) {
for (let i = 0; i < prefabs.length; ++i) {
let tr = document.createElement("tr");
table.appendChild(tr);
// edit instance button
// edit prefab button
let td = document.createElement("td");
tr.appendChild(td);
let button = document.createElement("button");
button.setAttribute("type", "button");
button.setAttribute("title", "Edit instace");
button.setAttribute("onclick", "InstanceManager.editInstance(" + i + ")");
button.setAttribute("onclick", "PrefabManager.editPrefab(" + i + ")");
button.innerHTML = "+";
td.appendChild(button);
// select instance button
// select prefab button
td = document.createElement("td");
tr.appendChild(td);
button = document.createElement("button");
button.setAttribute("type", "button");
button.setAttribute("class", "instancebutton");
button.setAttribute("class", "prefabbutton");
button.setAttribute("title", "Rightclick to rename");
button.setAttribute("onmousedown", "InstanceManager.selectInstanceWithID(" + i + ")");
button.setAttribute("onmousedown", "PrefabManager.selectPrefabWithID(" + i + ")");
button.setAttribute("oncontextmenu", "this.focus(); document.execCommand('selectAll',false,null);");
button.setAttribute("contenteditable", "true");
button.setAttribute("oninput", "InstanceManager.changeNameForInstanceWithID(" + i + ", this.innerHTML)");
button.setAttribute("oninput", "PrefabManager.changeNameForPrefabWithID(" + i + ", this.innerHTML)");
if (Logic.currentState instanceof InstanceBrushState &&
Logic.currentState.currentInstance == instances[i]) {
if (Logic.currentState instanceof PrefabBrushState &&
Logic.currentState.currentPrefab == prefabs[i]) {
button.setAttribute("id", "selectedButton");
tr.setAttribute("id", "selectedInstance");
tr.setAttribute("id", "selectedPrefab");
}
button.innerHTML = instances[i].name;
button.innerHTML = prefabs[i].name;
td.appendChild(button);
// delete instance button
// delete prefab button
td = document.createElement("td");
tr.appendChild(td);
button = document.createElement("button");
button.setAttribute("type", "button");
button.setAttribute("title", "Delete instance");
button.setAttribute("onclick", "InstanceManager.deleteInstanceWithID(" + i + ")");
button.setAttribute("title", "Delete prefab");
button.setAttribute("onclick", "PrefabManager.deletePrefabWithID(" + i + ")");
button.innerHTML = "<font color='red'>X</font>";
td.appendChild(button);
}
this.instancesDiv.appendChild(table);
this.prefabsDiv.appendChild(table);
}
......
......@@ -46,7 +46,7 @@ function onLoad() {
GridManager.init();
ActionHistory.init();
InstanceManager.init();
PrefabManager.init();
GUI.genereateGridSettings();
......
......@@ -291,8 +291,8 @@
else {
this.drawPivot();
if (Logic.currentState instanceof InstanceBrushState)
this.drawInstancePreview();
if (Logic.currentState instanceof PrefabBrushState)
this.drawPrefabPreview();
}
this.fps = 1000 / (step - this.oldStep);
......@@ -831,8 +831,8 @@
this.currentContext.stroke();
}
static drawInstancePreview() {
for (let line of Logic.currentState.currentInstance.lines)
static drawPrefabPreview() {
for (let line of Logic.currentState.currentPrefab.lines)
this.batchLine(line.copy().move(currentPosition));
this.renderBatchedLines(1, 'green');
......
class InstanceBrushState extends State {
constructor(instance) {
class PrefabBrushState extends State {
constructor(prefab) {
super();
this.currentInstance = instance;
this.currentPrefab = prefab;
}
......@@ -13,14 +13,14 @@
}
place() {
for (let line of this.currentInstance.lines)
for (let line of this.currentPrefab.lines)
File.currentLayer.addLine(line.copy().move(currentPosition));
}
cancel() {
Logic.setState(new IdleState());
Renderer.redraw();
GUI.buildInstancesUI();
GUI.buildPrefabUI();
}
keyDown(keycode) {
......@@ -33,6 +33,6 @@
toString() {
return "Instance Brush State";
return "Prefab Brush State";
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment