Commit be453c55 authored by Christian Winter's avatar Christian Winter

EObject unification wip

parent a27bb3d7
Pipeline #5143210 passed with stage
in 50 seconds
......@@ -11,7 +11,9 @@
<script src="scripts/Preferences.js"></script>
<script src="scripts/EObject.js"></script>
<script src="scripts/objects/EObject.js"></script>
<script src="scripts/objects/Rectangle.js"></script>
<script src="scripts/filestructure/Line.js"></script>
<script src="scripts/filestructure/Vector2.js"></script>
<script src="scripts/filestructure/LineEnding.js"></script>
......
class EObject {
constructor() {
this.position; // line --> getter which calculates mean of start and end
// rotation
// scale
// function instanceSpaceForPosition()
}
get getAsLines() {
}
selectionHit() { // other name? intersect? overlap? circleHit?
}
boxSelectionHit() {
}
copy() {
}
}
\ No newline at end of file
class PrefabInstance {
class PrefabInstance extends EObject {
constructor(prefabReference, position, rotation, scale) {
this.transform = new Transform(position, rotation, scale);
super(position, rotation, scale);
this.reference = prefabReference;
}
......@@ -20,8 +20,8 @@
for (let instance of this.reference.data.instances)
{
for (let line of instance.getAsLines()) {
line.start.position = this.instanceSpaceForPosition(line.start.position);
line.end.position = this.instanceSpaceForPosition(line.end.position);
line.start.position = this.objectSpaceForPosition(line.start.position);
line.end.position = this.objectSpaceForPosition(line.end.position);
if (Utilities.distancePointToLine(mousePosition, line) <= cursorRange)
return true;
......@@ -31,7 +31,7 @@
return false;
}
selectionBoxHit(bounds) {
boxSelectionHit(bounds) {
for (let line of this.getAsLines())
if (bounds.contains(line.start) || bounds.contains(line.end))
return true;
......@@ -39,8 +39,8 @@
for (let instance of this.reference.data.instances)
{
for (let line of instance.getAsLines()) {
line.start.position = this.instanceSpaceForPosition(line.start.position);
line.end.position = this.instanceSpaceForPosition(line.end.position);
line.start.position = this.objectSpaceForPosition(line.start.position);
line.end.position = this.objectSpaceForPosition(line.end.position);
if (bounds.contains(line.start) || bounds.contains(line.end))
return true;
......@@ -50,13 +50,6 @@
return false;
}
instanceSpaceForPosition(pos) {
pos = pos.addVector(this.transform.position);
pos = pos.scaleFrom(this.transform.position, this.transform.scale);
pos = pos.rotateAround(this.transform.position, this.transform.rotation);
return pos;
}
get bounds() {
let min = new Vector2(Infinity, Infinity);
let max = new Vector2(-Infinity, -Infinity);
......@@ -81,8 +74,8 @@
for (let line of this.reference.data.lines) {
lines.push(new Line(
this.instanceSpaceForPosition(line.start.position),
this.instanceSpaceForPosition(line.end.position),
this.objectSpaceForPosition(line.start.position),
this.objectSpaceForPosition(line.end.position),
line.color,
line.thickness
));}
......@@ -90,8 +83,8 @@
for (let instance of this.reference.data.instances) {
for (let line of instance.getAsLines()) {
lines.push(new Line(
this.instanceSpaceForPosition(line.start.position),
this.instanceSpaceForPosition(line.end.position),
this.objectSpaceForPosition(line.start.position),
this.objectSpaceForPosition(line.end.position),
line.color,
line.thickness
));
......@@ -102,8 +95,8 @@
if (Application.prefabEditorView.prefab == this.reference) {
for (let line of Application.prefabEditorView.getSelectionAsLines())
lines.push(new Line(
this.instanceSpaceForPosition(line.start.position),
this.instanceSpaceForPosition(line.end.position),
this.objectSpaceForPosition(line.start.position),
this.objectSpaceForPosition(line.end.position),
line.color,
line.thickness
));
......@@ -115,7 +108,7 @@
// TODO implement me should return
/*
dissolve() {
// return in this.instanceSpaceForPosition?
// return in this.objectSpaceForPosition?
// what happens to scale and rotation?
return this.data();
} // */
......
......@@ -10,4 +10,11 @@
&& this.rotation == other.rotation
&& this.scale.equals(other.scale);
}
transformSpaceForPosition(pos) {
pos = pos.addVector(this.position);
pos = pos.scaleFrom(this.position, this.scale);
pos = pos.rotateAround(this.position, this.rotation);
return pos;
}
}
\ No newline at end of file
class EObject {
constructor(position, rotation, scale) {
this.transform = new Transform(position, rotation, scale);
// line --> getter which calculates mean of start and end
}
objectSpaceForPosition(pos) {
return this.transform.transformSpaceForPosition(pos);
}
getAsLines() { throw ("getAsLines() not implemented"); }
selectionHit() { throw ("selectionHit() not implemented"); }
boxSelectionHit(bounds) { throw ("boxSelectionHit() not implemented"); }
copy() { throw ("copy() not implemented"); }
}
\ No newline at end of file
class Rectangle extends EObject {
constructor(position, rotation, scale) {
super(position, rotation, scale);
this.width = 32;
this.height = 32;
}
getAsLines() {
}
selectionHit() {
}
boxSelectionHit() {
}
copy() {
}
}
\ No newline at end of file
......@@ -96,7 +96,7 @@
if (selectionType) {
for (let instance of Application.currentView.data.instances)
if (instance.selectionBoxHit(selectionBounds))
if (instance.boxSelectionHit(selectionBounds))
instancesToChangeSelection.push(instance);
for (let instance of instancesToChangeSelection) {
......@@ -106,7 +106,7 @@
}
else {
for (let instance of Application.currentView.selection.data.instances)
if (instance.selectionBoxHit(selectionBounds))
if (instance.boxSelectionHit(selectionBounds))
instancesToChangeSelection.push(instance);
for (let instance of instancesToChangeSelection) {
......
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