public override void ParseCue(string cueToken, string cueData) { if (mSettings.KnownInitGunks.Contains(cueToken)) { int gunkAmount = int.Parse(cueData); def.Actions.Add(StageActionFactory.NewGunkInit(cueToken, gunkAmount)); return; } if (mSettings.KnownIndexedGunks.Contains(cueToken)) { int[] data = cueData.AsIntArray(); def.Actions.Add(StageActionFactory.NewGunkIndices(cueToken, data)); return; } if (mSettings.KnownSpeakerNames.Contains(cueToken)) { mCurrentCharacterDevName = cueToken; mLastDialogueAction = StageActionFactory.NewDialogueAction(mCurrentCharacterDevName, ""); def.Actions.Add(mLastDialogueAction); return; } switch (cueToken) { case "ACTION_NEW_PATIENT": ZLog.Warn("Need to handle ACTION_NEW_PATIENT"); return; case "VO": def.Actions.Add(StageActionFactory.NewVOAction(cueData)); return; } throw new InvalidOperationException($"[PHASE] Unknown cue token! token: {cueToken}, is this a speaker or surgery gunk?"); }
private void ParseNode(IDefParser parentParser, IDefParser defParser, TokenNode rootToken, List <ParsingError> errors) { if (rootToken.Data != null) { try { defParser.ParseOptions(rootToken.Options); } catch (Exception e) { errors.Add(new ParsingError { Node = rootToken, Exception = e, }); } } if (rootToken.Children == null) { throw new InvalidOperationException($"Expected keyword token to contain children: {rootToken}, parentParser: {parentParser}"); } foreach (TokenNode childToken in rootToken.Children) { try { switch (childToken.Type) { case TokenType.KEYWORD: if (childToken.IsLeaf) { try { defParser.ParseCue(childToken.Keyword, childToken.Data); } catch (Exception e) { errors.Add(new ParsingError { Node = childToken, Exception = e, }); } } else { if (!GetParser(childToken.Keyword, out IDefParser subParser)) { throw new InvalidOperationException($"Unknown top-level token keyword: {childToken.Keyword}"); } Type subtype = subParser.DefType; object subdata = Activator.CreateInstance(subtype); subParser.Def = subdata; ParseNode(defParser, subParser, childToken, errors); subParser.Def = null; // object data = //n // childToken.Keyword try { defParser.ParseChildToken(subdata); } catch (Exception e) { errors.Add(new ParsingError { Node = childToken, Exception = e, }); } } break; case TokenType.MISC: if (childToken.Content != null) { defParser.ParseMisc(childToken.Content); } break; case TokenType.BREAK: defParser.ParseBreak(); break; default: ZLog.Warn($"Unhandled token type: {childToken.Type}"); break; } } catch (Exception e) { errors.Add(new ParsingError { Node = childToken, Exception = e, }); } } }