/// <summary> /// Called when [load yaml files changed]. Gets available sequences from the attract file. /// </summary> /// <returns></returns> public async override Task OnLoadYamlFilesChanged() { //Assign the attract config if (AttractConfig == null) { AttractConfig = _skeletonGameProvider.AttractConfig; } _skeletonGameProvider.SequenceYamls.Clear(); SequenceYamls?.Clear(); if (AttractConfig != null) { //Assign the attract config AttractConfig = _skeletonGameProvider.AttractConfig; //add attract file to provider var attractFile = _skeletonGameProvider.GameFolder + @"\config\attract.yaml"; var defaultSequenceFile = _skeletonGameProvider.GameFolder + @"\config\sequences.yaml"; _skeletonGameProvider.SequenceYamls.Add(attractFile); _skeletonGameProvider.SequenceYamls.Add(defaultSequenceFile); //Assign from all files found in config/sequences foreach (var item in _skeletonGameProvider.SequenceYamls) { bool seqAdded = false; try { if (!File.Exists(item)) { throw new FileNotFoundException(item); } SequenceYamls.Add(new SequenceYamlItemViewModel(item, _skeletonGameProvider.GetSequence(item))); seqAdded = true; _skeletonGameAttract.GetAvailableSequences(SequenceYamls.Last().SequenceYaml); } catch (Exception ex) { if (seqAdded) { SequenceYamls.Remove(SequenceYamls.Last()); } Log($"Error deserializing sequence file. {item}"); _eventAggregator.GetEvent <ErrorMessageEvent>().Publish($"Sequences loading error. {ex.Message}"); } } this.SelectedSequenceFile = SequenceYamls[0]; } }
public Task LoadYamlEntriesAsync() { if (string.IsNullOrWhiteSpace(this.GameFolder)) { throw new System.NullReferenceException("Game folder cannot be an empty string"); } if (!Directory.Exists(GameFolder)) { throw new FileNotFoundException($"Cannot find game folder: {GameFolder}"); } ClearConfigs(); return(Task.Run(async() => { var errored = false; var args = new ProviderUpdatedEventArgs() { Status = 2 }; this.OnProviderFinished(args); try { GameConfig = _skeletonGameSerializer.DeserializeSkeletonYaml <GameConfig>(Path.Combine(GameFolder, YamlFiles[0])); if (GameConfig == null) { throw new NullReferenceException("Config.yaml returned null, please check your config.yaml"); } #region MACHINE CONFIG try { var machineConfig = Path.Combine(GameFolder, YamlFiles[5]); MachineConfig = _skeletonGameSerializer.DeserializeSkeletonYaml <MachineConfig>(machineConfig); } catch (FileNotFoundException ex) { Dispatcher.CurrentDispatcher.Invoke(() => { System.Windows.MessageBox.Show($"{ex.Message}"); }); } catch (System.Exception ex) { var msg = $"Failed loading Game. \r\n {ex.Data["yaml"]} {ex.Message}"; msg += $"\n\r {ex.Data["err"]}"; Log(msg, Category.Exception); try { Dispatcher.CurrentDispatcher.Invoke(() => { ParseMachineConfigWithKeyValues(ex); }); } catch (Exception exee) { msg = $"Failed loading Game. \r\n {exee.Data["yaml"]} {exee.Message}"; msg += $"\n\r {exee.Data["err"]}"; Log(msg); throw; } } #endregion AssetsConfig = null; if (File.Exists(Path.Combine(GameFolder, YamlFiles[1]))) { AssetsConfig = _skeletonGameSerializer.DeserializeSkeletonYaml <AssetsFile>(Path.Combine(GameFolder, YamlFiles[1])); } if (!File.Exists(Path.Combine(GameFolder, YamlFiles[2]))) { throw new FileNotFoundException("attract.yaml not found."); } AttractConfig = GetSequence(Path.Combine(GameFolder, YamlFiles[2])); var newScoreDisplayYaml = Path.Combine(GameFolder, YamlFiles[3]); var scoreDisplayYaml = Path.Combine(GameFolder, YamlFiles[4]); //Deal with the updated score display if (File.Exists(newScoreDisplayYaml)) { ScoreDisplayConfig = _skeletonGameSerializer.DeserializeSkeletonYaml <ScoreDisplay>(newScoreDisplayYaml); } else if (File.Exists(scoreDisplayYaml)) { ScoreDisplayConfig = _skeletonGameSerializer.DeserializeSkeletonYaml <ScoreDisplay>(scoreDisplayYaml); } SequenceYamls.Clear(); //Add the base sequences.yaml found in config var baseSeqFile = Path.Combine(GameFolder, @"config\sequences.yaml"); if (File.Exists(baseSeqFile)) { SequenceYamls.Add(baseSeqFile); } //Get sequence files and add to list var seqDir = Path.Combine(GameFolder, @"config\sequences"); Directory.CreateDirectory(seqDir); var seqFiles = await _skeletonGameFiles.GetFilesAsync(seqDir, AssetTypes.Sequences); foreach (var item in seqFiles) { SequenceYamls.Add(item); } Directory.CreateDirectory(GameFolder + @"\recordings"); RecordingManager.GetPlaybackFiles(GameFolder + @"\recordings"); //Trophy Data var trophydefaultData = Path.Combine(GameFolder, YamlFiles[6]); if (!File.Exists(trophydefaultData)) { string msg = $"Couldn't find default trophy data at {trophydefaultData}"; _eventAggregator.GetEvent <ErrorMessageEvent>().Publish(msg); Log(msg, Category.Warn); } else { TrophyData = _skeletonGameSerializer.DeserializeSkeletonYaml <TrophyData>(trophydefaultData); } } catch (System.Exception) { ClearConfigs(); errored = true; throw; } finally { if (errored) { args.Status = 0; } else { args.Status = -1; } OnProviderFinished(args); } })); }