Commit aa84041e authored by Max Bebök's avatar Max Bebök

chg: i don't know anymore :/

parent bb149733
......@@ -6,14 +6,17 @@
import { ActorType, ActorUID } from "./types";
import { ActorParams } from "./params/params";
import ActorHandler from "./handler/handler";
import ActorGUI from "./gui";
const BYAML = require("byaml-lib");
export default class Actor
{
gui: any; // @TODO type
gui: ActorGUI; // @TODO type
selected = false;
handler: any; // @TODO type
handler: ActorHandler;
updateCallbacks: Function[] = [];
constructor(
public params: ActorParams,
......@@ -21,7 +24,6 @@ export default class Actor
private _uid: ActorUID,
private objInstance: any // @TODO type
) {
this.objInstance = objInstance;
this.objInstance.setActor(this);
}
......@@ -123,6 +125,7 @@ export default class Actor
}
this.objInstance.update();
this.updateCallbacks.forEach(cb => cb());
if(this.gui)
{
......@@ -174,7 +177,7 @@ export default class Actor
this.update();
}
move({x = 0.0, y = 0.0, z = 0.0}): void
move({x = 0.0, y = 0.0, z = 0.0}: Vector3): void
{
if(this.params.Translate)
{
......@@ -198,7 +201,7 @@ export default class Actor
return {x: 0.0, y: 0.0, z:0.0};
}
setPos({x = 0.0, y = 0.0, z = 0.0}): void
setPos({x = 0.0, y = 0.0, z = 0.0}: Vector3): void
{
if(this.params.Translate)
{
......@@ -209,7 +212,7 @@ export default class Actor
this.update();
}
rotate({x = 0.0, y = 0.0, z = 0.0}): void
rotate({x = 0.0, y = 0.0, z = 0.0}: Vector3): void
{
if(this.params.Rotate)
{
......@@ -225,7 +228,7 @@ export default class Actor
this.update();
}
scale({x = 1.0, y = 1.0, z = 1.0}): void
scale({x = 1.0, y = 1.0, z = 1.0}: Vector3): void
{
if(this.params.Scale)
{
......@@ -252,4 +255,15 @@ export default class Actor
{
return this.objInstance.actorObject.modelGroup.name == "__DEFAULT_BOX";
}
subscribeToUpdate(callback: Function)
{
this.unsubscribeToUpdate(callback);
this.updateCallbacks.push(callback);
}
unsubscribeToUpdate(callback: Function)
{
this.updateCallbacks = this.updateCallbacks.filter(cb => cb != callback);
}
}
......@@ -196,5 +196,6 @@ export default class ActorGUI
delete(): void
{
this.hideEditor();
this.node.parentElement.removeChild(this.node);
}
}
\ No newline at end of file
......@@ -57,7 +57,7 @@ export default class ActorHandler
private editor: any;
private actorObjHandler: any;
public actorObjHandler: any;
public actors: ActorMap = {};
......
import Actor from "../actor";
import { ActorParams } from "./params";
/**
* @copyright 2018 - Max Bebök
* @author Max Bebök
* @license GNU-GPLv3 - see the "LICENSE" file in the root directory
*/
export default class ActorParamsWatcher
{
private actor: Actor;
private paramsInitial: string;
private paramsCurrent: string;
attach(actor: Actor)
{
this.actor = actor;
this.actor.subscribeToUpdate(this.update);
this.reset();
}
update = () =>
{
this.paramsCurrent = this.actor.getParamJSON();
}
detach()
{
this.actor.unsubscribeToUpdate(this.update);
}
get()
{
return {
old: this.paramsInitial,
new: this.paramsCurrent
};
}
reset()
{
this.update();
this.paramsInitial = this.paramsCurrent;
}
}
\ No newline at end of file
......@@ -111,33 +111,29 @@ export default class ActorEditor
const speedScale = 0.02;
const scrollMulti = 0.002;
let speedVec;
let speedVec: Vector3 = {x: 0.0, y: 0.0, z: 0.0};
if(ev.ctrlKey) // scaling
{
if(ev.type == "wheel")
{
speedVec = { y: 1.0 + (ev.deltaY < 0 ? speedScale : -speedScale) };
speedVec.y = 1.0 + (ev.deltaY < 0 ? speedScale : -speedScale);
}else{
const moveVec = new (THREE as any).Vector2(ev.movementX, -ev.movementY);
speedVec = {
x: 1.0 + Math.sign(moveVec.x) * speedScale,
z: 1.0 + Math.sign(moveVec.y) * speedScale,
};
speedVec.x = 1.0 + Math.sign(moveVec.x) * speedScale;
speedVec.z = 1.0 + Math.sign(moveVec.y) * speedScale;
}
}else{ // moving / rotating
if(ev.type == "wheel")
{
speedVec = { y: -ev.deltaY * scrollMulti };
speedVec.y = -ev.deltaY * scrollMulti;
}else{
const moveVec = new (THREE as any).Vector2(ev.movementX, -ev.movementY);
moveVec.rotateAround(new (THREE as any).Vector2(0.0, 0.0), camera.rotation.y % (Math.PI * 2));
speedVec = {
x: moveVec.x * speedMulti,
z: -moveVec.y * speedMulti
};
speedVec.x = moveVec.x * speedMulti;
speedVec.z = -moveVec.y * speedMulti;
}
}
......
......@@ -39,6 +39,22 @@ export default class HistoryControls
this.history.addChangeCallback(this.update);
}
undo()
{
const entry = this.history.undo();
if(entry) {
this.historyPatcher.undo(entry);
}
}
redo()
{
const entry = this.history.redo();
if(entry) {
this.historyPatcher.redo(entry);
}
}
/**
* loads and attaches the HTML view
*/
......@@ -71,22 +87,6 @@ export default class HistoryControls
});
}
undo()
{
const entry = this.history.undo();
if(entry) {
this.historyPatcher.undo(entry);
}
}
redo()
{
const entry = this.history.redo();
if(entry) {
this.historyPatcher.redo(entry);
}
}
/**
* creates the history view and adds controls
*/
......
......@@ -104,8 +104,9 @@ export default class MubinRenderer
deselectActor(actor: Actor): void
{
if(actor.gui)
this.selectedActorList.removeChild(actor.gui.node);
if(actor.gui) {
actor.gui.delete();
}
}
focusPos(pos: Vector3): void
......
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