Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
56 lines
1.8 KiB
Java
56 lines
1.8 KiB
Java
package electrosphere.server.macro;
|
|
|
|
import java.io.File;
|
|
import java.util.List;
|
|
|
|
import electrosphere.client.entity.character.CharacterDescription;
|
|
import electrosphere.game.data.block.BlockFab;
|
|
import electrosphere.server.character.CharacterService;
|
|
import electrosphere.server.macro.character.Character;
|
|
import electrosphere.server.macro.structure.Structure;
|
|
import electrosphere.util.FileUtils;
|
|
|
|
/**
|
|
* Loads macro data
|
|
*/
|
|
public class MacroDataLoader {
|
|
|
|
/**
|
|
* Loads macro data from a save
|
|
* @param saveName The name of the save
|
|
* @return The macro data
|
|
*/
|
|
public static MacroData loadFromSave(String saveName){
|
|
|
|
MacroData rVal = FileUtils.loadObjectFromSavePath(saveName, "macro.json", MacroData.class);
|
|
|
|
//preload and assign structure fabs
|
|
for(Structure structure : rVal.getStructures()){
|
|
File fabFile = FileUtils.getAssetFile(structure.getFabPath());
|
|
if(!fabFile.exists()){
|
|
throw new Error("Failed to locate structure that does not exist! " + fabFile.getAbsolutePath());
|
|
}
|
|
BlockFab fab = BlockFab.read(fabFile);
|
|
if(fab == null){
|
|
throw new Error("Failed to read fab!");
|
|
}
|
|
structure.setFab(fab);
|
|
}
|
|
|
|
//inject characters from character service
|
|
List<CharacterDescription> characters = CharacterService.getAllCharacters();
|
|
for(CharacterDescription desc : characters){
|
|
int targetId = Integer.parseInt(desc.getId());
|
|
Character macroCharacter = rVal.getCharacter(targetId);
|
|
if(macroCharacter == null){
|
|
macroCharacter = new Character();
|
|
macroCharacter.setId(targetId);
|
|
rVal.characters.add(macroCharacter);
|
|
}
|
|
}
|
|
|
|
return rVal;
|
|
}
|
|
|
|
}
|