mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-02-01 16:08:17 +00:00
重新加入事件系统。
This commit is contained in:
parent
709d925c53
commit
0849af55f8
@ -1,4 +1,5 @@
|
||||
import Editor from './Editor';
|
||||
import EventDispatcher from './event/EventDispatcher';
|
||||
import Viewport from './ui/Viewport';
|
||||
import Script from './core/Script';
|
||||
import Player from './core/Player';
|
||||
@ -13,7 +14,11 @@ import RemoveObjectCommand from './command/RemoveObjectCommand';
|
||||
*/
|
||||
function Application(container) {
|
||||
|
||||
var editor = new Editor();
|
||||
this.container = container;
|
||||
this.event = new EventDispatcher(this);
|
||||
|
||||
// editor
|
||||
var editor = new Editor(this);
|
||||
this.editor = editor;
|
||||
|
||||
// dom
|
||||
|
||||
@ -10,7 +10,7 @@ import SceneUtils from './utils/SceneUtils';
|
||||
* @author mrdoob / http://mrdoob.com/
|
||||
*/
|
||||
|
||||
function Editor() {
|
||||
function Editor(app) {
|
||||
|
||||
this.DEFAULT_CAMERA = new THREE.PerspectiveCamera(50, 1, 0.1, 10000);
|
||||
this.DEFAULT_CAMERA.name = 'Camera';
|
||||
|
||||
27
src/event/BaseEvent.js
Normal file
27
src/event/BaseEvent.js
Normal file
@ -0,0 +1,27 @@
|
||||
import NotImplementedException from '../exception/NotImplementedException';
|
||||
|
||||
/**
|
||||
* 事件基类
|
||||
*/
|
||||
class BaseEvent {
|
||||
|
||||
constructor(app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始执行
|
||||
*/
|
||||
start() {
|
||||
throw NotImplementedException();
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止执行
|
||||
*/
|
||||
stop() {
|
||||
throw NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
export default BaseEvent;
|
||||
75
src/event/EventDispatcher.js
Normal file
75
src/event/EventDispatcher.js
Normal file
@ -0,0 +1,75 @@
|
||||
import { dispatch } from '../third_party';
|
||||
import EventList from './EventList';
|
||||
|
||||
/**
|
||||
* 事件执行器
|
||||
*/
|
||||
class EventDispatcher {
|
||||
|
||||
constructor(app) {
|
||||
this.app = app;
|
||||
this.dispatch = dispatch.apply(dispatch, EventList);
|
||||
// this.domElement = this.app.container;
|
||||
// this.addDomEventListener();
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行事件
|
||||
* @param {*} eventName
|
||||
* @param {*} _this
|
||||
* @param {*} others
|
||||
*/
|
||||
call(eventName, _this, ...others) {
|
||||
this.dispatch.call(eventName, _this, ...others);
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听事件
|
||||
* @param {*} eventName
|
||||
* @param {*} callback
|
||||
*/
|
||||
on(eventName, callback) {
|
||||
this.dispatch.on(eventName, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听dom事件
|
||||
*/
|
||||
addDomEventListener() {
|
||||
var container = this.app.container;
|
||||
this.domElement.addEventListener('click', (event) => {
|
||||
this.dispatch.call('click', this, event);
|
||||
});
|
||||
this.domElement.addEventListener('contextmenu', (event) => {
|
||||
this.dispatch.call('contextmenu', this, event);
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
this.domElement.addEventListener('dblclick', (event) => {
|
||||
this.dispatch.call('dblclick', this, event);
|
||||
});
|
||||
this.domElement.addEventListener('keydown', (event) => {
|
||||
this.dispatch.call('keydown', this, event);
|
||||
});
|
||||
this.domElement.addEventListener('keyup', (event) => {
|
||||
this.dispatch.call('keyup', this, event);
|
||||
});
|
||||
this.domElement.addEventListener('mousedown', (event) => {
|
||||
this.dispatch.call('mousedown', this, event);
|
||||
});
|
||||
this.domElement.addEventListener('mousemove', (event) => {
|
||||
this.dispatch.call('mousemove', this, event);
|
||||
});
|
||||
this.domElement.addEventListener('mouseup', (event) => {
|
||||
this.dispatch.call('mouseup', this, event);
|
||||
});
|
||||
this.domElement.addEventListener('mousewheel', (event) => {
|
||||
this.dispatch.call('mousewheel', this, event);
|
||||
});
|
||||
window.addEventListener('resize', (event) => {
|
||||
this.dispatch.call('resize', this, event);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default EventDispatcher;
|
||||
8
src/event/EventList.js
Normal file
8
src/event/EventList.js
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* 自定义事件列表
|
||||
*/
|
||||
var EventList = [
|
||||
|
||||
];
|
||||
|
||||
export default EventList;
|
||||
3
src/event/index.js
Normal file
3
src/event/index.js
Normal file
@ -0,0 +1,3 @@
|
||||
export { default as EventList } from './EventList';
|
||||
export { default as BaseEvent } from './BaseEvent';
|
||||
export { default as EventDispatcher } from './EventDispatcher';
|
||||
@ -1,5 +1,6 @@
|
||||
export * from './third_party';
|
||||
import { } from './polyfills';
|
||||
export * from './event/index';
|
||||
export * from './core/index';
|
||||
export * from './command/index';
|
||||
export * from './ui/index';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user