|
//-----------------------------------------------------------------------------
// ConfigManager
// 配置管理器
// The static class that manages the configuration data.
//这个静态的类 管理 配置数据
function ConfigManager() {
throw new Error('This is a static class');
}
//总是奔跑
ConfigManager.alwaysDash = false;
//命令记住
ConfigManager.commandRemember = false;
//定义属性 bgm大小
Object.defineProperty(ConfigManager, 'bgmVolume', {
get: function() {
return AudioManager._bgmVolume;
},
set: function(value) {
AudioManager.bgmVolume = value;
},
configurable: true
});
//定义属性 bgs大小
Object.defineProperty(ConfigManager, 'bgsVolume', {
get: function() {
return AudioManager.bgsVolume;
},
set: function(value) {
AudioManager.bgsVolume = value;
},
configurable: true
});
//定义属性 me大小
Object.defineProperty(ConfigManager, 'meVolume', {
get: function() {
return AudioManager.meVolume;
},
set: function(value) {
AudioManager.meVolume = value;
},
configurable: true
});
//定义属性 se大小
Object.defineProperty(ConfigManager, 'seVolume', {
get: function() {
return AudioManager.seVolume;
},
set: function(value) {
AudioManager.seVolume = value;
},
configurable: true
});
//读取
ConfigManager.load = function() {
var json;
var config = {};
try {
json = StorageManager.load(-1);
} catch (e) {
console.error(e);
}
if (json) {
config = JSON.parse(json);
}
this.applyData(config);
};
//保存
ConfigManager.save = function() {
StorageManager.save(-1, JSON.stringify(this.makeData()));
};
//制作数据
ConfigManager.makeData = function() {
var config = {};
config.alwaysDash = this.alwaysDash;
config.commandRemember = this.commandRemember;
config.bgmVolume = this.bgmVolume;
config.bgsVolume = this.bgsVolume;
config.meVolume = this.meVolume;
config.seVolume = this.seVolume;
return config;
};
//应用数据
ConfigManager.applyData = function(config) {
this.alwaysDash = this.readFlag(config, 'alwaysDash');
this.commandRemember = this.readFlag(config, 'commandRemember');
this.bgmVolume = this.readVolume(config, 'bgmVolume');
this.bgsVolume = this.readVolume(config, 'bgsVolume');
this.meVolume = this.readVolume(config, 'meVolume');
this.seVolume = this.readVolume(config, 'seVolume');
};
//读取标志
ConfigManager.readFlag = function(config, name) {
return !!config[name];
};
//读取 大小
ConfigManager.readVolume = function(config, name) {
var value = config[name];
if (value !== undefined) {
return Number(value).clamp(0, 100);
} else {
return 100;
}
};
站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作
GMT+8, 2024-5-10 09:10
Powered by Discuz! X3.1
© 2001-2013 Comsenz Inc.