package foundation.data.meta.property;
|
|
import foundation.data.meta.template.PropertyTemplateBucket;
|
import foundation.data.object.DataObject;
|
import foundation.util.MapList;
|
import foundation.util.Util;
|
|
public class SystemMetasBucket {
|
|
private PropertyTemplateBucket templateBucket;
|
private DataObject dataObject;
|
private MapList<String, IPropertyMetasSet> capacitySetList;
|
private MapList<String, IPropertyMetasSet> sceneSetList;
|
private MetasDefaultSet defaultSet;
|
private IPropertyMetasSet cachedSet;
|
private Level cachedLevel;
|
private String cachedKey;
|
|
|
public SystemMetasBucket(DataObject dataObject, PropertyTemplateBucket templateBucket) {
|
this.dataObject = dataObject;
|
this.templateBucket = templateBucket;
|
|
this.defaultSet = new MetasDefaultSet(templateBucket.getDefaultIndexes());
|
|
this.cachedSet = null;
|
this.cachedLevel = null;
|
this.cachedKey = null;
|
}
|
|
public void loadOne(Property meta) {
|
//1. 加载 角色Meta
|
String capacity = meta.getCapacity();
|
|
if (!Util.isEmpty(capacity)) {
|
IPropertyMetasSet metasSet = getCachedMetasSet(Level.Capacity, capacity);
|
metasSet.loadOne(meta);
|
return;
|
}
|
|
//2. 加载 场景Meta
|
String scene = meta.getScene();
|
|
if (!Util.isEmpty(scene)) {
|
IPropertyMetasSet metasSet = getCachedMetasSet(Level.Scene, scene);
|
metasSet.loadOne(meta);
|
return;
|
}
|
|
//3. 加载 默认 Meta
|
IPropertyMetasSet metasSet = defaultSet;
|
metasSet.loadOne(meta);
|
}
|
|
public void build() throws Exception {
|
//1. build default
|
buildDefaultPropertyMetas();
|
|
//2. build scene
|
buildScenePropertyMetas();
|
|
//3. build capacity
|
buildCapacityPropertyMetas();
|
}
|
|
private void buildDefaultPropertyMetas() throws Exception {
|
if (defaultSet == null) {
|
return;
|
}
|
|
defaultSet.build(dataObject);
|
}
|
|
private void buildScenePropertyMetas() throws Exception {
|
if (sceneSetList == null) {
|
return;
|
}
|
|
for (IPropertyMetasSet sceneSet: sceneSetList) {
|
sceneSet.build(defaultSet);
|
}
|
}
|
|
private void buildCapacityPropertyMetas() throws Exception {
|
if (capacitySetList == null) {
|
return;
|
}
|
|
for (IPropertyMetasSet capacitySet: capacitySetList) {
|
String scene = capacitySet.getScene();
|
IPropertyMetasSet master = sceneSetList.get(scene);
|
|
if (master == null) {
|
master = defaultSet;
|
}
|
|
capacitySet.build(master);
|
}
|
}
|
|
public IPropertyMetasSet getMetasBucket(MetaCode metaCode) {
|
IPropertyMetasSet bucket;
|
|
//1. 从角色(角色+场景)配置中获取
|
if (capacitySetList != null) {
|
String capacity = metaCode.getCapacity();
|
bucket = capacitySetList.get(capacity);
|
|
if (bucket != null) {
|
return bucket;
|
}
|
}
|
|
//2. 从场景配置中获取
|
if (sceneSetList != null) {
|
String scene = metaCode.getScene();
|
bucket = sceneSetList.get(scene);
|
|
if (bucket != null) {
|
return bucket;
|
}
|
}
|
|
//3. 从全量配置(默认配置)中获取
|
return defaultSet;
|
}
|
|
public IPropertyMetasSet getMasterPropertys(Level from, MetaCode metaCode) throws Exception {
|
IPropertyMetasSet bucket = null;
|
|
//1. 从角色(角色+场景)开始获取 Master
|
if (Level.Capacity == from && capacitySetList != null) {
|
//1.1 从角色(角色+场景)配置中获取
|
String capacityKey = metaCode.getCapacity();
|
bucket = capacitySetList.get(capacityKey);
|
|
if (bucket != null) {
|
return bucket;
|
}
|
|
//1.2 从场景配置中获取
|
String sceneKey = metaCode.getScene();
|
bucket = sceneSetList.get(sceneKey);
|
|
if (bucket != null) {
|
return bucket;
|
}
|
|
//1.3 从全量配置(默认配置)中获取
|
bucket = defaultSet;
|
return bucket;
|
}
|
//2. 从角色(角色+场景)开始获取 Master
|
else if (Level.Scene == from && sceneSetList != null) {
|
//2.1 从场景配置中获取
|
String sceneKey = metaCode.getScene();
|
bucket = sceneSetList.get(sceneKey);
|
|
if (bucket != null) {
|
return bucket;
|
}
|
|
//2.2 从全量配置(默认配置)中获取
|
bucket = defaultSet;
|
return bucket;
|
}
|
//3. 从全量配置(默认配置)中获取Master
|
else if (Level.Default == from) {
|
bucket = defaultSet;
|
return bucket;
|
}
|
|
return defaultSet;
|
}
|
|
public void clear() {
|
if (capacitySetList != null) {
|
capacitySetList.clear();
|
}
|
|
if (sceneSetList != null) {
|
sceneSetList.clear();
|
}
|
|
if (defaultSet != null) {
|
defaultSet.clear();
|
}
|
}
|
|
private IPropertyMetasSet getCachedMetasSet(Level level, String key) {
|
if (level == cachedLevel && Util.equals(key, cachedKey)) {
|
return cachedSet;
|
}
|
|
IPropertyMetasSet result = null;
|
|
if (Level.Capacity == level) {
|
result = capacitySetList.get(key);
|
|
if (result == null) {
|
result = new MetasBranchSet(templateBucket.getCapacityIndexes());
|
capacitySetList.add(key, result);
|
}
|
}
|
else if (Level.Scene == level) {
|
result = sceneSetList.get(key);
|
|
if (result == null) {
|
result = new MetasBranchSet(templateBucket.getSceneIndexes());
|
sceneSetList.add(key, result);
|
}
|
}
|
else if (Level.Default == level) {
|
result = defaultSet;
|
}
|
|
cachedLevel = level;
|
cachedKey = key;
|
cachedSet = result;
|
|
return result;
|
}
|
|
}
|