public Store(IStoreIO storeIO) { resourceRegistry = new ResourceRegistry(); factoryRegistry = new FactoryRegistry(); modifierRegistry = new ModifierRegistry(); this.storeIO = storeIO; }
public StoreSaveState Load(ResourceRegistry resourceRegistry, FactoryRegistry factoryRegistry, ModifierRegistry modiferRegistry) { string path = string.Format(@"{0}{1}", directoryPath, FILE_NAME); StoreSaveState storage = null; try { using (FileStream fileStream = new FileStream(path, FileMode.Open)) { using (StreamReader reader = new StreamReader(fileStream)) { storage = JsonConvert.DeserializeObject <StoreSaveState>(reader.ReadToEnd()); } } } catch (FileNotFoundException) { throw new FileNotFoundException(string.Format("An existing save file could not be found to load at: {0}", path)); } ResourceCheckpoint checkpoint = new ResourceCheckpoint(storage.ResourceCheckpoint.CheckpointTimeUTC, storage.ResourceCheckpoint.ResourceAmounts, resourceRegistry); FactoryManager factoryManager = new FactoryManager(storage.FactoryManager.FactoryAmounts, factoryRegistry); ModifierManager modifierManager = new ModifierManager(storage.ModiferManager.ModifierDurations, modiferRegistry); return(new StoreSaveState() { ResourceCheckpoint = checkpoint, FactoryManager = factoryManager, ModiferManager = modifierManager }); }