package application.editor;
import simulator.Resource;
import simulator.Simulator;
import java.util.HashMap;
import java.util.Set;
public class SimulationLayout {
//リソース毎の分割度を保持する
HashMap<Resource,Integer> divisionLevelMap = new HashMap<>();
//リソース毎の拡大倍率を保持する
HashMap<Resource,Double> resourceScaleMap = new HashMap<>();
int maxDivisionLevel = 1;
public final double BASE_WIDTH = 100;
public final double BASE_HEIGHT = BASE_WIDTH/2;
public SimulationLayout(Set<Resource> resources){
//全リソースの分割度を計算
for (Resource res:resources) {
setDivisionLevel(divisionLevelMap, res, 1);
}
//リソース毎の表示倍率を決定
for (Resource res:divisionLevelMap.keySet()) {
double scale = (double) maxDivisionLevel / divisionLevelMap.get(res);
resourceScaleMap.put(res, scale);
}
}
public double getScale(Resource resource){
return resourceScaleMap.get(resource);
}
public double getDivision(Resource resource){
return divisionLevelMap.get(resource);
}
public boolean isExistResource(Resource resource){
return divisionLevelMap.containsKey(resource);
}
private void setDivisionLevel(HashMap<Resource,Integer> resourceSet, Resource resource, int childCount){
int divisionLevel;
if(resourceSet.get(resource.getParent()) == null){
divisionLevel = 1;
}else{
divisionLevel = resourceSet.get(resource.getParent()) * childCount;
}
if (divisionLevel > maxDivisionLevel)maxDivisionLevel = divisionLevel;
resourceSet.put(resource,divisionLevel);
if(resource.getChildren()!=null){
for(Resource child:resource.getChildren()){
setDivisionLevel(resourceSet, child, resource.getChildren().size());
}
}
}
}