简化配置代码,修复一些配置bug。

This commit is contained in:
tengge1 2020-02-15 21:25:03 +08:00
parent 4ce8e8e525
commit 1fabd7ae40
22 changed files with 71 additions and 66 deletions

View File

@ -21,7 +21,7 @@ class ControlsManager extends BaseControls {
this.handleUpdate = this.handleUpdate.bind(this);
this.handleEnd = this.handleEnd.bind(this);
const mode = app.storage.get('controlMode');
const mode = app.storage.controlMode;
this.changeMode(mode);
// 记录上次控制器以便按Esc退出第一视角返回原来的模式。

View File

@ -145,7 +145,7 @@ class ModelPanel extends React.Component {
Server: true
});
if (app.storage.get('addMode') === 'click') {
if (app.storage.addMode === 'click') {
this.clickSceneToAdd(obj);
} else {
this.addToCenter(obj);

View File

@ -161,12 +161,12 @@ class OptionsMenu extends React.Component {
// ---------------------------------- -------------------------------
handleEnableDebugMode() {
app.storage.set('debug', true);
app.storage.debug = true;
window.location.reload();
}
handleDisableDebugMode() {
app.storage.set('debug', false);
app.storage.debug = false;
window.location.reload();
}
}

View File

@ -9,9 +9,9 @@ class ViewMenu extends React.Component {
super(props);
this.state = {
showStats: app.storage.get('showStats') === undefined ? true : app.storage.get('showStats'),
showGrid: app.storage.get('showGrid') === undefined ? true : app.storage.get('showGrid'),
showViewHelper: app.storage.get('showViewHelper') === undefined ? true : app.storage.get('showViewHelper'),
showStats: app.storage.showStats,
showGrid: app.storage.showGrid,
showViewHelper: app.storage.showViewHelper,
enablePhysics: app.options.enablePhysics,
isThrowBall: false
};
@ -53,8 +53,8 @@ class ViewMenu extends React.Component {
}
handleShowStats() {
const showStats = !app.storage.get('showStats');
app.storage.set('showStats', showStats);
const showStats = !app.storage.showStats;
app.storage.showStats = showStats;
Object.assign(app.stats.dom.style, {
display: showStats ? 'block' : 'none'
@ -66,8 +66,8 @@ class ViewMenu extends React.Component {
}
handleShowGrid() {
const showGrid = !app.storage.get('showGrid');
app.storage.set('showGrid', showGrid);
const showGrid = !app.storage.showGrid;
app.storage.showGrid = showGrid;
app.call(`storageChanged`, this, 'showGrid', showGrid);
@ -77,8 +77,8 @@ class ViewMenu extends React.Component {
}
handleShowViewHelper() {
const showViewHelper = !app.storage.get('showViewHelper');
app.storage.set('showViewHelper', showViewHelper);
const showViewHelper = !app.storage.showViewHelper;
app.storage.showViewHelper = showViewHelper;
app.call(`storageChanged`, this, 'showViewHelper', showViewHelper);

View File

@ -36,8 +36,8 @@ class EditorStatusBar extends React.Component {
render() {
const { x, y, objects, vertices, triangles } = this.state;
const selectMode = app.storage.get('selectMode');
const controlMode = app.storage.get('controlMode');
const selectMode = app.storage.selectMode;
const controlMode = app.storage.controlMode;
const isLogin = !app.server.enableAuthority || app.server.isLogin;
@ -138,14 +138,14 @@ class EditorStatusBar extends React.Component {
}
handleChangeSelectMode(value) {
app.storage.set('selectMode', value);
app.storage.selectMode = value;
app.call('storageChanged', this, 'selectMode', value);
this.forceUpdate();
}
handleChangeControlMode(value) {
app.editor.controls.changeMode(value);
app.storage.set('controlMode', value);
app.storage.controlMode = value;
app.call('storageChanged', this, 'controlMode', value);
this.forceUpdate();
}

View File

@ -41,7 +41,7 @@ class DrawTools extends React.Component {
render() {
const { isAddingPoint, isAddingLine, isAddingPolygon, isSpraying, isDigging } = this.state;
const addMode = app.storage.get('addMode');
const addMode = app.storage.addMode;
return <>
<IconButton
@ -394,7 +394,7 @@ class DrawTools extends React.Component {
}
changeAddMode(value) {
app.storage.set('addMode', value);
app.storage.addMode = value;
app.call('storageChanged', this, 'addMode', value);
this.forceUpdate();
}

View File

@ -45,11 +45,11 @@ class Viewport extends React.Component {
//
app.stats = new Stats();
let showStats = app.storage.get('showStats');
let showStats = app.storage.showStats;
if (showStats === undefined) {
showStats = true;
app.storage.set('showStats', true);
app.storage.showStats = true;
}
Object.assign(app.stats.dom.style, {

View File

@ -14,10 +14,10 @@ class DisplayPanel extends React.Component {
}
render() {
const selectedColor = app.storage.get('selectedColor');
const selectedThickness = app.storage.get('selectedThickness');
const hoverEnabled = app.storage.get('hoverEnabled');
const hoveredColor = app.storage.get('hoveredColor');
const selectedColor = app.storage.selectedColor;
const selectedThickness = app.storage.selectedThickness;
const hoverEnabled = app.storage.hoverEnabled;
const hoveredColor = app.storage.hoveredColor;
return <Form className={'DisplayPanel'}>
<FormControl>
@ -72,7 +72,7 @@ class DisplayPanel extends React.Component {
return;
}
app.storage.set(name, value);
app.storage[name] = value;
app.call(`storageChanged`, this, name, value);
this.handleUpdate();

View File

@ -89,14 +89,14 @@ class HelperPanel extends React.Component {
handleUpdate() {
this.setState({
showGrid: app.storage.get('showGrid') === true,
showCamera: app.storage.get('showCamera') === true,
showPointLight: app.storage.get('showPointLight') === true,
showDirectionalLight: app.storage.get('showDirectionalLight') === true,
showSpotLight: app.storage.get('showSpotLight') === true,
showHemisphereLight: app.storage.get('showHemisphereLight') === true,
showRectAreaLight: app.storage.get('showRectAreaLight') === true,
showSkeleton: app.storage.get('showSkeleton') === true
showGrid: app.storage.showGrid,
showCamera: app.storage.showCamera,
showPointLight: app.storage.showPointLight,
showDirectionalLight: app.storage.showDirectionalLight,
showSpotLight: app.storage.showSpotLight,
showHemisphereLight: app.storage.showHemisphereLight,
showRectAreaLight: app.storage.showRectAreaLight,
showSkeleton: app.storage.showSkeleton
});
}
@ -113,43 +113,43 @@ class HelperPanel extends React.Component {
[name]: value
});
if (showGrid !== app.storage.get('showGrid')) {
app.storage.set('showGrid', showGrid);
if (showGrid !== app.storage.showGrid) {
app.storage.showGrid = showGrid;
app.call(`storageChanged`, this, 'showGrid', showGrid);
}
if (showCamera !== app.storage.get('showCamera')) {
app.storage.set('showCamera', showCamera);
if (showCamera !== app.storage.showCamera) {
app.storage.showCamera = showCamera;
app.call(`storageChanged`, this, 'showCamera', showCamera);
}
if (showPointLight !== app.storage.get('showPointLight')) {
app.storage.set('showPointLight', showPointLight);
if (showPointLight !== app.storage.showPointLight) {
app.storage.showPointLight = showPointLight;
app.call(`storageChanged`, this, 'showPointLight', showPointLight);
}
if (showDirectionalLight !== app.storage.get('showDirectionalLight')) {
app.storage.set('showDirectionalLight', showDirectionalLight);
if (showDirectionalLight !== app.storage.showDirectionalLight) {
app.storage.showDirectionalLight = showDirectionalLight;
app.call(`storageChanged`, this, 'showDirectionalLight', showDirectionalLight);
}
if (showSpotLight !== app.storage.get('showSpotLight')) {
app.storage.set('showSpotLight', showSpotLight);
if (showSpotLight !== app.storage.showSpotLight) {
app.storage.showSpotLight = showSpotLight;
app.call(`storageChanged`, this, 'showSpotLight', showSpotLight);
}
if (showHemisphereLight !== app.storage.get('showHemisphereLight')) {
app.storage.set('showHemisphereLight', showHemisphereLight);
if (showHemisphereLight !== app.storage.showHemisphereLight) {
app.storage.showHemisphereLight = showHemisphereLight;
app.call(`storageChanged`, this, 'showHemisphereLight', showHemisphereLight);
}
if (showRectAreaLight !== app.storage.get('showRectAreaLight')) {
app.storage.set('showRectAreaLight', showRectAreaLight);
if (showRectAreaLight !== app.storage.showRectAreaLight) {
app.storage.showRectAreaLight = showRectAreaLight;
app.call(`storageChanged`, this, 'showRectAreaLight', showRectAreaLight);
}
if (showSkeleton !== app.storage.get('showSkeleton')) {
app.storage.set('showSkeleton', showSkeleton);
if (showSkeleton !== app.storage.showSkeleton) {
app.storage.showSkeleton = showSkeleton;
app.call(`storageChanged`, this, 'showSkeleton', showSkeleton);
}

View File

@ -35,7 +35,7 @@ GPUPickEvent.prototype.start = function () {
app.on(`resize.${this.id}`, this.onResize);
app.on(`storageChanged.${this.id}`, this.onStorageChanged);
this.selectMode = app.storage.get('selectMode');
this.selectMode = app.storage.selectMode;
};
GPUPickEvent.prototype.stop = function () {

View File

@ -69,7 +69,7 @@ PickEvent.prototype.handleClick = function () {
let editor = app.editor;
let objects = editor.objects;
const selectMode = app.storage.get('selectMode');
const selectMode = app.storage.selectMode;
if (this.onDownPosition.distanceTo(this.onUpPosition) === 0) {
let intersects = this.getIntersects(this.onUpPosition, objects);

View File

@ -27,7 +27,7 @@ CameraHelper.prototype.stop = function () {
};
CameraHelper.prototype.update = function () {
var showCamera = app.storage.get('showCamera');
var showCamera = app.storage.showCamera;
if (!this.helper) {
this.helper = new THREE.CameraHelper(app.editor.camera);

View File

@ -27,7 +27,7 @@ GridHelper.prototype.stop = function () {
};
GridHelper.prototype.update = function () {
var showGrid = app.storage.get('showGrid');
var showGrid = app.storage.showGrid;
if (!this.helper) {
this.helper = new THREE.GridHelper(30, 30, 0x444444, 0x888888);

View File

@ -7,8 +7,8 @@ import BaseHelper from './BaseHelper';
function HoverHelper() {
BaseHelper.call(this);
this.hoverEnabled = app.storage.get('hoverEnabled');
this.hoveredColor = app.storage.get('hoveredColor');
this.hoverEnabled = app.storage.hoverEnabled;
this.hoveredColor = app.storage.hoveredColor;
this.onGpuPick = this.onGpuPick.bind(this);
this.onObjectRemoved = this.onObjectRemoved.bind(this);

View File

@ -97,8 +97,8 @@ SelectHelper.prototype.onObjectSelected = function (obj) {
});
}
const selectedColor = app.storage.get('selectedColor');
const selectedThickness = app.storage.get('selectedThickness');
const selectedColor = app.storage.selectedColor;
const selectedThickness = app.storage.selectedThickness;
if (this.edgeMaterial === undefined) {
this.edgeMaterial = new THREE.ShaderMaterial({

View File

@ -16,11 +16,11 @@ ViewHelper.prototype.constructor = ViewHelper;
ViewHelper.prototype.start = function () {
this.scene = new THREE.Scene();
let show = app.storage.get('showViewHelper');
let show = app.storage.showViewHelper;
if (show === undefined) {
show = true;
app.storage.set('showViewHelper', true);
app.storage.showViewHelper = true;
}
this.show = show;

View File

@ -35,7 +35,7 @@ DirectionalLightHelpers.prototype.onObjectAdded = function (object) {
var helper = new VolumeDirectionalLightHelper(object, 1);
helper.visible = app.storage.get('showDirectionalLight');
helper.visible = app.storage.showDirectionalLight;
this.helpers.push(helper);

View File

@ -35,7 +35,7 @@ HemisphereLightHelpers.prototype.onObjectAdded = function (object) {
var helper = new VolumeHemisphereLightHelper(object, 1);
helper.visible = app.storage.get('showHemisphereLight');
helper.visible = app.storage.showHemisphereLight;
this.helpers.push(helper);

View File

@ -35,7 +35,7 @@ PointLightHelpers.prototype.onObjectAdded = function (object) {
var helper = new VolumePointLightHelper(object, 1);
helper.visible = app.storage.get('showPointLight');
helper.visible = app.storage.showPointLight;
this.helpers.push(helper);

View File

@ -35,7 +35,7 @@ RectAreaLightHelpers.prototype.onObjectAdded = function (object) {
var helper = new VolumeRectAreaLightHelper(object, 0xffffff);
helper.visible = app.storage.get('showRectAreaLight');
helper.visible = app.storage.showRectAreaLight;
this.helpers.push(helper);

View File

@ -35,7 +35,7 @@ SpotLightHelpers.prototype.onObjectAdded = function (object) {
var helper = new VolumeSpotLightHelper(object, 0xffffff);
helper.visible = app.storage.get('showSpotLight');
helper.visible = app.storage.showSpotLight;
this.helpers.push(helper);

View File

@ -5,7 +5,12 @@ class Storage {
constructor() {
// 向本地存储写入默认配置,并提供快捷访问方法
const defaultConfigs = {
showGrid: true,
debug: false, // 调试模式
// 帮助器
showStats: true, // 性能监视器
showGrid: true, // 网格
showViewHelper: true, // 视角帮助器
showCamera: false,
showPointLight: true,
showDirectionalLight: true,