mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-25 15:08:11 +00:00
修复存储类,使其支持多种类型。
This commit is contained in:
parent
9ced4a28fb
commit
f85e86cc60
@ -126,35 +126,35 @@ SettingPanel.prototype.render = function () {
|
||||
control.render();
|
||||
|
||||
// 为各种设置设定默认值
|
||||
if (this.app.storage.get('showGrid') === null) {
|
||||
if (this.app.storage.get('showGrid') === undefined) {
|
||||
this.app.storage.set('showGrid', true);
|
||||
}
|
||||
|
||||
if (this.app.storage.get('showCamera') === null) {
|
||||
if (this.app.storage.get('showCamera') === undefined) {
|
||||
this.app.storage.set('showCamera', false);
|
||||
}
|
||||
|
||||
if (this.app.storage.get('showPointLight') === null) {
|
||||
if (this.app.storage.get('showPointLight') === undefined) {
|
||||
this.app.storage.set('showPointLight', true);
|
||||
}
|
||||
|
||||
if (this.app.storage.get('showDirectionalLight') === null) {
|
||||
if (this.app.storage.get('showDirectionalLight') === undefined) {
|
||||
this.app.storage.set('showDirectionalLight', true);
|
||||
}
|
||||
|
||||
if (this.app.storage.get('showSpotLight') === null) {
|
||||
if (this.app.storage.get('showSpotLight') === undefined) {
|
||||
this.app.storage.set('showSpotLight', true);
|
||||
}
|
||||
|
||||
if (this.app.storage.get('showHemisphereLight') === null) {
|
||||
if (this.app.storage.get('showHemisphereLight') === undefined) {
|
||||
this.app.storage.set('showHemisphereLight', true);
|
||||
}
|
||||
|
||||
if (this.app.storage.get('showRectAreaLight') === null) {
|
||||
if (this.app.storage.get('showRectAreaLight') === undefined) {
|
||||
this.app.storage.set('showRectAreaLight', true);
|
||||
}
|
||||
|
||||
if (this.app.storage.get('showSkeleton') === null) {
|
||||
if (this.app.storage.get('showSkeleton') === undefined) {
|
||||
this.app.storage.set('showSkeleton', false);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,51 @@
|
||||
import BaseHelper from './BaseHelper';
|
||||
|
||||
/**
|
||||
* 相机帮助器
|
||||
* @param {*} app
|
||||
*/
|
||||
function CameraHelper(app) {
|
||||
BaseHelper.call(this, app);
|
||||
}
|
||||
|
||||
CameraHelper.prototype = Object.create(BaseHelper.prototype);
|
||||
CameraHelper.prototype.constructor = CameraHelper;
|
||||
|
||||
CameraHelper.prototype.start = function () {
|
||||
this.app.on(`storageChanged.${this.id}`, this.onStorageChanged.bind(this));
|
||||
this.update();
|
||||
};
|
||||
|
||||
CameraHelper.prototype.stop = function () {
|
||||
this.app.on(`appStarted.${this.id}`, null);
|
||||
|
||||
if (this.helper) {
|
||||
var scene = this.app.editor.sceneHelpers;
|
||||
scene.remove(this.helper);
|
||||
delete this.helper;
|
||||
}
|
||||
};
|
||||
|
||||
CameraHelper.prototype.update = function () {
|
||||
var showCamera = this.app.storage.get('showCamera');
|
||||
|
||||
if (!this.helper) {
|
||||
this.helper = new THREE.CameraHelper(this.app.editor.camera);
|
||||
}
|
||||
|
||||
var scene = this.app.editor.sceneHelpers;
|
||||
|
||||
if (showCamera && this.helper.parent !== scene) {
|
||||
scene.add(this.helper);
|
||||
} else if (!showCamera && this.helper.parent === scene) {
|
||||
scene.remove(this.helper);
|
||||
}
|
||||
};
|
||||
|
||||
CameraHelper.prototype.onStorageChanged = function (key, value) {
|
||||
if (key === 'showCamera') {
|
||||
this.update();
|
||||
}
|
||||
};
|
||||
|
||||
export default CameraHelper;
|
||||
@ -19,26 +19,26 @@ GridHelper.prototype.start = function () {
|
||||
GridHelper.prototype.stop = function () {
|
||||
this.app.on(`appStarted.${this.id}`, null);
|
||||
|
||||
if (this.grid) {
|
||||
if (this.helper) {
|
||||
var scene = this.app.editor.sceneHelpers;
|
||||
scene.remove(this.grid);
|
||||
delete this.grid;
|
||||
scene.remove(this.helper);
|
||||
delete this.helper;
|
||||
}
|
||||
};
|
||||
|
||||
GridHelper.prototype.update = function () {
|
||||
var showGrid = this.app.storage.get('showGrid');
|
||||
|
||||
if (!this.grid) {
|
||||
this.grid = new THREE.GridHelper(30, 30, 0x444444, 0x888888);
|
||||
if (!this.helper) {
|
||||
this.helper = new THREE.GridHelper(30, 30, 0x444444, 0x888888);
|
||||
}
|
||||
|
||||
var scene = this.app.editor.sceneHelpers;
|
||||
|
||||
if (showGrid && this.grid.parent !== scene) {
|
||||
scene.add(this.grid);
|
||||
} else if (!showGrid && this.grid.parent === scene) {
|
||||
scene.remove(this.grid);
|
||||
if (showGrid && this.helper.parent !== scene) {
|
||||
scene.add(this.helper);
|
||||
} else if (!showGrid && this.helper.parent === scene) {
|
||||
scene.remove(this.helper);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import BaseHelper from './BaseHelper';
|
||||
|
||||
import GridHelper from './GridHelper';
|
||||
import CameraHelper from './CameraHelper';
|
||||
|
||||
import ViewHelper from './ViewHelper';
|
||||
import SelectHelper from './SelectHelper';
|
||||
import SplineHelper from './line/SplineHelper';
|
||||
@ -13,6 +16,8 @@ function Helpers(app) {
|
||||
|
||||
this.helpers = [
|
||||
new GridHelper(app),
|
||||
new CameraHelper(app),
|
||||
|
||||
new SelectHelper(app),
|
||||
new ViewHelper(app),
|
||||
new SplineHelper(app),
|
||||
|
||||
@ -5,26 +5,54 @@ function Storage() {
|
||||
|
||||
}
|
||||
|
||||
Storage.prototype.length = {
|
||||
get: function () {
|
||||
return window.localStorage.length;
|
||||
}
|
||||
};
|
||||
|
||||
Storage.prototype.get = function (key) {
|
||||
return window.localStorage.getItem(key);
|
||||
var configs = this._getConfigs();
|
||||
return configs[key];
|
||||
};
|
||||
|
||||
Storage.prototype.set = function (key, value) {
|
||||
window.localStorage.setItem(key, value);
|
||||
var configs = this._getConfigs();
|
||||
configs[key] = value;
|
||||
this._setConfigs(configs);
|
||||
};
|
||||
|
||||
Storage.prototype.setConfigs = function (configs) {
|
||||
if (typeof (configs) !== 'object') {
|
||||
console.warn(`Storage: configs should be an object.`);
|
||||
return;
|
||||
}
|
||||
|
||||
var _configs = this._getConfigs();
|
||||
|
||||
Object.keys(configs).forEach(n => {
|
||||
_configs[n] = configs[n];
|
||||
});
|
||||
|
||||
this._setConfigs(_configs);
|
||||
};
|
||||
|
||||
Storage.prototype.remove = function (key) {
|
||||
window.localStorage.removeItem(key);
|
||||
var configs = this._getConfigs();
|
||||
delete configs[key];
|
||||
this._setConfigs(configs);
|
||||
};
|
||||
|
||||
Storage.prototype.clear = function () {
|
||||
window.localStorage.clear();
|
||||
window.localStorage.removeItem('configs');
|
||||
};
|
||||
|
||||
Storage.prototype._getConfigs = function () {
|
||||
var configs = window.localStorage.getItem('configs');
|
||||
|
||||
if (!configs) {
|
||||
configs = '{}';
|
||||
}
|
||||
|
||||
return JSON.parse(configs);
|
||||
};
|
||||
|
||||
Storage.prototype._setConfigs = function (configs) {
|
||||
window.localStorage.setItem('configs', JSON.stringify(configs));
|
||||
};
|
||||
|
||||
export default Storage;
|
||||
Loading…
x
Reference in New Issue
Block a user