public bool FinishArrayItem() { if (ContentTable.Count > 1) { return(Program.ReportFailure("Unexpected failure")); } Debug.Assert(ContentTypeTable.Count == ContentTable.Count); foreach (KeyValuePair <string, object> Entry in ContentTable) { string Key = Entry.Key; Debug.Assert(ContentTypeTable.ContainsKey(Key)); if (ItemCollection.Count > 0) { if (ContentTypeTable[Key] != LastItemType) { return(Program.ReportFailure("Mixed array types")); } } ItemCollection.Add(Entry.Value); LastItemType = ContentTypeTable[Key]; } ContentTable.Clear(); ContentTypeTable.Clear(); return(true); }
public Json.Token Read() { if (reader.BaseStream.Position >= reader.BaseStream.Length) { return(token = Json.Token.EndOfFile); } token = (Json.Token)reader.ReadByte(); if (token == Json.Token.ObjectKey || token == Json.Token.String) { value = StringHandler.ReadString(reader.ReadString()); } else if (token == Json.Token.Float) { value = reader.ReadSingle(); } else if (token == Json.Token.Integer) { value = reader.ReadInt32(); } else if (token == Json.Token.Boolean) { value = reader.ReadBoolean(); } else if (token == Json.Token.Null) { value = null; } return(token); }
public bool SetContent(string key, object?value, Json.Token jsonType) { if (ContentTable.ContainsKey(key)) { return(Program.ReportFailure($"Key '{key}' already parsed for object")); } Debug.Assert(!ContentTypeTable.ContainsKey(key)); ContentTable.Add(key, value !); ContentTypeTable.Add(key, jsonType); return(true); }
public override bool FinishItem(ref object?item, string objectKey, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { if (item is not PgItemSkillLink AsPgItemSkillLink) { return(Program.ReportFailure("Unexpected failure")); } return(FinishItem(AsPgItemSkillLink, contentTable, contentTypeTable, itemCollection, lastItemType, parsedFile, parsedKey)); }
private bool FinishItem(PgStorageVault item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { bool Result = true; foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; switch (Key) { case "ID": Result = SetIntProperty((int valueInt) => item.RawId = valueInt, Value); break; case "NpcFriendlyName": Result = SetStringProperty((string valueString) => item.NpcFriendlyName = valueString, Value); break; case "Area": Result = ParseArea((MapAreaName valueEnum) => item.Area = valueEnum, Value, parsedFile, parsedKey); break; case "NumSlots": Result = SetIntProperty((int valueInt) => item.RawNumSlots = valueInt, Value); break; case "HasAssociatedNpc": Result = SetBoolProperty((bool valueBool) => item.RawHasAssociatedNpc = valueBool, Value); break; case "Levels": Result = Inserter <PgStorageFavorLevel> .SetItemProperty((PgStorageFavorLevel valueStorageFavorLevel) => item.Levels = valueStorageFavorLevel, Value); break; case "Requirements": Result = Inserter <PgStorageRequirement> .SetItemProperty((PgStorageRequirement valueStorageRequirement) => item.Requirement = valueStorageRequirement, Value); break; case "RequirementDescription": Result = SetStringProperty((string valueString) => item.RequirementDescription = valueString, Value); break; case "Grouping": Result = ParseArea((MapAreaName valueEnum) => item.Grouping = valueEnum, Value, parsedFile, parsedKey); break; case "RequiredItemKeywords": Result = StringToEnumConversion <ItemKeyword> .TryParseList(Value, item.RequiredItemKeywordList); break; case "SlotAttribute": Result = Inserter <PgAttribute> .SetItemByKey((PgAttribute valueAttribute) => item.SlotAttribute_Key = valueAttribute.Key, Value); break; case "EventLevels": Result = Inserter <PgStorageEventList> .SetItemProperty((PgStorageEventList valueStorageEventLevel) => item.EventLevels = valueStorageEventLevel, Value); break; default: Result = Program.ReportFailure(parsedFile, parsedKey, $"Key '{Key}' not handled"); break; } if (!Result) { break; } } if (Result) { if (!item.RawHasAssociatedNpc.HasValue || item.HasAssociatedNpc) { Inserter <PgQuest> .SetNpc((PgNpcLocation npcLocation) => item.AssociatedNpc = npcLocation, item.Key, parsedFile, parsedKey, ErrorControl.IgnoreIfNotFound); } } return(Result); }
private bool FinishItem(PgXpTable item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { bool Result = true; foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; switch (Key) { case "InternalName": Result = ParseInternamName(item, Value, parsedFile, parsedKey); break; case "XpAmounts": Result = ParseXpAmounts(item, Value, parsedFile, parsedKey); break; default: Result = Program.ReportFailure(parsedFile, parsedKey, $"Key '{Key}' not handled"); break; } if (!Result) { break; } } return(Result); }
public override bool FinishItem(ref object?item, string objectKey, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { if (item is not PgAdvancementTable AsPgAdvancementTable) { return(Program.ReportFailure("Unexpected failure")); } AsPgAdvancementTable.Key = objectKey; int Index = objectKey.IndexOf("_"); if (Index < 0) { return(Program.ReportFailure($"Invalid advancement table key '{objectKey}'")); } AsPgAdvancementTable.InternalName = objectKey.Substring(Index + 1); return(FinishItem(AsPgAdvancementTable, contentTable, contentTypeTable, itemCollection, lastItemType, parsedFile, parsedKey)); }
private bool FinishItem(PgReportList item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; if (!int.TryParse(Key, out int EntryLevel)) { return(Program.ReportFailure($"Invalid report key '{Key}'")); } if (!(Value is string EntryString)) { return(Program.ReportFailure($"Invalid report value '{Value}'")); } PgReport NewReport = new PgReport() { RawReportLevel = EntryLevel, Text = EntryString }; ParsingContext.AddSuplementaryObject(NewReport); item.List.Add(NewReport); } return(true); }
public override bool FinishItem(ref object?item, string objectKey, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { if (item != null) { return(Program.ReportFailure("Unexpected failure")); } if (!contentTable.ContainsKey("T")) { return(Program.ReportFailure(parsedFile, parsedKey, $"Quest reward is missing a Type qualifier")); } object TypeValue = contentTable["T"]; if (!(TypeValue is string AsTypeString)) { return(Program.ReportFailure(parsedFile, parsedKey, $"Value {TypeValue} was expected to be a string")); } if (!StringToEnumConversion <QuestRewardType> .TryParse(AsTypeString, out QuestRewardType rewardType)) { return(false); } if (!HandlerTable.ContainsKey(rewardType)) { return(Program.ReportFailure(parsedFile, parsedKey, $"Reward {rewardType} has no handler")); } Debug.Assert(KnownFieldTable.ContainsKey(rewardType)); VariadicObjectHandler Handler = HandlerTable[rewardType]; List <string> KnownFieldList = KnownFieldTable[rewardType]; List <string> UsedFieldList = new List <string>(); if (!Handler(ref item, contentTable, contentTypeTable, itemCollection, lastItemType, KnownFieldList, UsedFieldList, parsedFile, parsedKey)) { return(false); } if (!HandledTable.ContainsKey(rewardType)) { HandledTable.Add(rewardType, new List <string>()); } List <string> ReportedFieldList = HandledTable[rewardType]; foreach (string FieldName in UsedFieldList) { if (!ReportedFieldList.Contains(FieldName)) { ReportedFieldList.Add(FieldName); } } return(true); }
private bool FinishItem(PgPowerTierList item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; if (!Key.StartsWith("id_") || !int.TryParse(Key.Substring(3), out int Level)) { return(Program.ReportFailure($"Invalid power tier key '{Key}'")); } if (!(Value is ParsingContext Context)) { return(Program.ReportFailure($"Value '{Value}' was expected to be a context")); } if (!(Context.Item is PgPowerTier AsPowerTier)) { return(Program.ReportFailure($"Object '{Value}' was unexpected")); } AsPowerTier.Level = Level; item.TierList.Add(AsPowerTier); } item.TierList.Sort(SortByLevel); return(true); }
private bool FinishItem(PgLoreBookInfoCategory item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { bool Result = true; foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; switch (Key) { case "Title": Result = SetStringProperty((string valueString) => item.Title = valueString, Value); break; case "SubTitle": Result = SetStringProperty((string valueString) => item.SubTitle = valueString, Value); break; case "SortTitle": Result = SetStringProperty((string valueString) => item.SortTitle = valueString, Value); break; default: Result = Program.ReportFailure(parsedFile, parsedKey, $"Key '{Key}' not handled"); break; } if (!Result) { break; } } return(Result); }
private bool FinishItem(PgLevelCapInteractionList item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; if (!(Value is int EntryLevel)) { return(Program.ReportFailure($"Invalid level cap interaction '{Value}'")); } if (!ParseInteraction(item, Key, EntryLevel, parsedFile, parsedKey)) { return(false); } } return(true); }
private bool FinishItem(PgDoT item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { bool Result = true; foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; switch (Key) { case "DamagePerTick": Result = SetIntProperty((int valueInt) => item.RawDamagePerTick = valueInt, Value); break; case "NumTicks": Result = SetIntProperty((int valueInt) => item.RawNumTicks = valueInt, Value); break; case "Duration": Result = SetIntProperty((int valueInt) => item.RawDuration = valueInt, Value); break; case "DamageType": Result = StringToEnumConversion <DamageType> .SetEnum((DamageType valueEnum) => item.DamageType = valueEnum, Value); break; case "SpecialRules": Result = StringToEnumConversion <DoTSpecialRule> .TryParseList(Value, item.SpecialRuleList); break; case "AttributesThatDelta": Result = Inserter <PgAttribute> .AddPgObjectArrayByKey <PgAttribute>(item.AttributesThatDeltaList, Value); break; case "AttributesThatMod": Result = Inserter <PgAttribute> .AddPgObjectArrayByKey <PgAttribute>(item.AttributesThatModList, Value); break; case "Preface": Result = SetStringProperty((string valueString) => item.Preface = valueString, Value); break; default: Result = Program.ReportFailure(parsedFile, parsedKey, $"Key '{Key}' not handled"); break; } if (!Result) { break; } } if (!Result) { return(false); } if (item.RawDamagePerTick == null) { return(Program.ReportFailure(parsedFile, parsedKey, $"Unexpected empty damage per tick")); } if (item.DamageType == DamageType.Internal_None || item.DamageType == DamageType.Internal_Empty) { return(Program.ReportFailure(parsedFile, parsedKey, $"Unexpected empty damage type")); } if (item.RawNumTicks == null) { return(Program.ReportFailure(parsedFile, parsedKey, $"Unexpected empty num tick")); } if (item.RawDuration == null) { return(Program.ReportFailure(parsedFile, parsedKey, $"Unexpected empty duration")); } return(true); }
private bool FinishItem(PgAdvancementHint item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; if (!int.TryParse(Key, out int EntryLevel)) { return(Program.ReportFailure($"Invalid skill hint level '{Key}'")); } if (item.HintTable.ContainsKey(EntryLevel)) { return(Program.ReportFailure($"Level {EntryLevel} already added")); } if (!(Value is string HintString)) { return(Program.ReportFailure($"Value '{Value}' was expected to be a string")); } item.HintTable.Add(EntryLevel, HintString); } return(true); }
private bool FinishItem(PgStorageEventList item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; if (!StringToEnumConversion <EventLevel> .TryParse(Key, out EventLevel Event)) { return(Program.ReportFailure(parsedFile, parsedKey, $"Unknown favor level '{Key}'")); } if (!(Value is int SlotCount)) { return(Program.ReportFailure($"Value {Value} was expected to be an int")); } item.EventTable.Add(Event, SlotCount); } return(true); }
private static bool FinishItemAbility(ref object?item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, List <string> knownFieldList, List <string> usedFieldList, string parsedFile, string parsedKey) { PgQuestRewardAbility NewItem = new PgQuestRewardAbility(); bool Result = true; foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; if (!knownFieldList.Contains(Key)) { Result = Program.ReportFailure($"Unknown field {Key}"); } else { usedFieldList.Add(Key); switch (Key) { case "T": break; case "Ability": Result = Inserter <PgAbility> .SetItemByInternalName((PgAbility valueAbility) => NewItem.Ability_Key = valueAbility.Key, Value); break; default: Result = Program.ReportFailure("Unexpected failure"); break; } } if (!Result) { break; } } if (Result) { item = NewItem; return(true); } else { return(false); } }
private static bool FinishItemWorkOrderCurrency(ref object?item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, List <string> knownFieldList, List <string> usedFieldList, string parsedFile, string parsedKey) { PgQuestRewardWorkOrderCurrency NewItem = new PgQuestRewardWorkOrderCurrency(); bool Result = true; foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; if (!knownFieldList.Contains(Key)) { Result = Program.ReportFailure($"Unknown field {Key}"); } else { usedFieldList.Add(Key); switch (Key) { case "T": break; case "Currency": Result = StringToEnumConversion <Currency> .SetEnum((Currency valueEnum) => NewItem.Currency = valueEnum, Value); break; case "Amount": Result = SetIntProperty((int valueInt) => NewItem.RawAmount = valueInt, Value); break; default: Result = Program.ReportFailure("Unexpected failure"); break; } } if (!Result) { break; } } if (Result) { item = NewItem; return(true); } else { return(false); } }
private bool FinishItem(PgItem item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { bool Result = true; Dictionary <ItemKeyword, List <float> > KeywordTable = new Dictionary <ItemKeyword, List <float> >(); List <string> KeywordValueList = new List <string>(); Dictionary <string, int> SkillRequirementTable = new Dictionary <string, int>(); foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; switch (Key) { case "BestowRecipes": Result = ParseBestowRecipeList(item, Value, parsedFile, parsedKey); break; case "BestowAbility": Result = Inserter <PgAbility> .SetItemByInternalName((PgAbility valueAbility) => item.BestowAbility_Key = valueAbility.Key, Value); break; case "BestowQuest": Result = Inserter <PgQuest> .SetItemByInternalName((PgQuest valueQuest) => item.BestowQuest_Key = valueQuest.Key, Value); break; case "AllowPrefix": Result = SetBoolProperty((bool valueBool) => item.SetAllowPrefix(valueBool), Value); break; case "AllowSuffix": Result = SetBoolProperty((bool valueBool) => item.SetAllowSuffix(valueBool), Value); break; case "CraftPoints": Result = SetIntProperty((int valueInt) => item.RawCraftPoints = valueInt, Value); break; case "CraftingTargetLevel": Result = SetIntProperty((int valueInt) => item.RawCraftingTargetLevel = valueInt, Value); break; case "Description": Result = SetStringProperty((string valueString) => item.Description = valueString, Value); break; case "DroppedAppearance": Result = ParseDroppedAppearance(item, Value, parsedFile, parsedKey); break; case "EffectDescs": Result = ParseEffectDescriptionList(item.EffectDescriptionList, Value, parsedFile, parsedKey); break; case "DyeColor": Result = ParseDyeColor(item, Value, parsedFile, parsedKey); break; case "EquipAppearance": Result = SetStringProperty((string valueString) => item.EquipAppearance = valueString, Value); // TODO: parse break; case "EquipSlot": Result = StringToEnumConversion <ItemSlot> .SetEnum((ItemSlot valueEnum) => item.EquipSlot = valueEnum, Value); break; case "FoodDesc": Result = SetStringProperty((string valueString) => item.FoodDesc = valueString, Value); // TODO: parse break; case "IconId": Result = SetIconIdProperty((int valueInt) => item.RawIconId = valueInt, Value); break; case "InternalName": Result = SetStringProperty((string valueString) => item.InternalName = valueString, Value); break; case "IsTemporary": Result = SetBoolProperty((bool valueBool) => item.SetIsTemporary(valueBool), Value); break; case "IsCrafted": Result = SetBoolProperty((bool valueBool) => item.SetIsCrafted(valueBool), Value); break; case "Keywords": Result = ParseKeywordList(item, Value, KeywordTable, KeywordValueList, parsedFile, parsedKey); break; case "MacGuffinQuestName": Result = Inserter <PgQuest> .SetItemByInternalName((PgQuest valueQuest) => item.MacGuffinQuest_Key = valueQuest.Key, Value); break; case "MaxCarryable": Result = SetIntProperty((int valueInt) => item.RawMaxCarryable = valueInt, Value); break; case "MaxOnVendor": Result = SetIntProperty((int valueInt) => item.RawMaxOnVendor = valueInt, Value); break; case "MaxStackSize": Result = SetIntProperty((int valueInt) => item.RawMaxStackSize = valueInt, Value); break; case "Name": Result = SetStringProperty((string valueString) => item.Name = valueString, Value); break; case "RequiredAppearance": Result = StringToEnumConversion <Appearance> .SetEnum((Appearance valueEnum) => item.RequiredAppearance = valueEnum, Value); break; case "SkillReqs": Result = ParseSkillRequirements(item, Value, SkillRequirementTable, parsedFile, parsedKey); break; case "StockDye": Result = ParseStockDye(item, Value, parsedFile, parsedKey); break; case "TSysProfile": Result = StringToEnumConversion <Profile> .SetEnum((Profile valueEnum) => item.TSysProfile = valueEnum, Value); break; case "Value": Result = SetFloatProperty((float valueFloat) => item.RawValue = valueFloat, Value); break; case "NumUses": Result = SetIntProperty((int valueInt) => item.RawNumUses = valueInt, Value); break; case "DestroyWhenUsedUp": Result = SetBoolProperty((bool valueBool) => item.SetDestroyWhenUsedUp(valueBool), Value); break; case "Behaviors": Result = Inserter <PgItemBehavior> .AddKeylessArray(item.BehaviorList, Value); break; case "DynamicCraftingSummary": Result = SetStringProperty((string valueString) => item.DynamicCraftingSummary = valueString, Value); break; case "IsSkillReqsDefaults": Result = SetBoolProperty((bool valueBool) => item.SetIsSkillReqsDefaults(valueBool), Value); break; case "BestowTitle": Result = Inserter <PgPlayerTitle> .SetItemByKey((PgPlayerTitle valuePlayerTitle) => item.BestowTitle_Key = valuePlayerTitle.Key, $"Title_{Value}"); break; case "BestowLoreBook": Result = Inserter <PgLoreBook> .SetItemByKey((PgLoreBook valueLoreBook) => item.BestowLoreBook_Key = valueLoreBook.Key, $"Book_{Value}"); break; case "Lint_VendorNpc": Result = StringToEnumConversion <WorkOrderSign> .SetEnum((WorkOrderSign valueEnum) => item.LintVendorNpc = valueEnum, Value); break; case "MountedAppearance": Result = SetStringProperty((string valueString) => item.MountedAppearance = valueString, Value); break; case "AttuneOnPickup": Result = SetBoolProperty((bool valueBool) => item.SetAttuneOnPickup(valueBool), Value); break; default: Result = Program.ReportFailure(parsedFile, parsedKey, $"Key '{Key}' not handled"); break; } if (!Result) { break; } } if (Result) { item.KeywordTable = KeywordTable; item.SkillRequirementTable = SkillRequirementTable; } return(Result); }
private bool FinishItem(PgLoreBookInfo item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; if (!(Value is ParsingContext Context)) { return(Program.ReportFailure($"Value '{Value}' was expected to be a context")); } if (!(Context.Item is PgLoreBookInfoCategory AsCategory)) { return(Program.ReportFailure($"Object '{Value}' was unexpected")); } AsCategory.Key = Key; item.Categories.Add(AsCategory); } return(true); }
private bool ParseSourceItem(ref object?item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { bool Result = true; PgSourceItem NewSource = new PgSourceItem(); foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; switch (Key) { case "Type": break; case "ItemTypeId": Result = Inserter <PgItem> .SetItemByKey((PgItem valueItem) => NewSource.Item_Key = valueItem.Key, $"item_{Value}"); break; default: Result = Program.ReportFailure(parsedFile, parsedKey, $"Key '{Key}' not handled"); break; } if (!Result) { break; } } if (Result) { item = NewSource; return(true); } else { return(false); } }
public Json.Token Read() { if (token == Json.Token.EndOfFile) { return(token); } int next; while ((next = reader.Read()) >= 0) { char ch = Convert.ToChar(next); if (ch == '{') { lastIsKey = false; stack.Push(Json.Token.ObjectStart); value = null; return(token = Json.Token.ObjectStart); } else if (ch == '}') { stack.Pop(); value = null; return(token = Json.Token.ObjectEnd); } else if (ch == '"') { var isKey = !lastIsKey && stack.Peek() == Json.Token.ObjectStart; lastIsKey = isKey; value = ReadString(); return(token = isKey ? Json.Token.ObjectKey : Json.Token.String); } else if (ch == '[') { lastIsKey = false; stack.Push(Json.Token.ArrayStart); value = null; return(token = Json.Token.ArrayStart); } else if (ch == ']') { stack.Pop(); value = null; return(token = Json.Token.ArrayEnd); } else if (ch != ',' && ch != ':' && !Char.IsWhiteSpace(ch)) { lastIsKey = false; builder.Clear(); builder.Append(ch); while ((next = reader.Peek()) >= 0) { ch = Convert.ToChar(next); if (ch != ']' && ch != '}' && ch != ',') { builder.Append(token); reader.Read(); } else { break; } } var str = builder.ToString(); if (int.TryParse(str, out int integer)) { value = integer; return(token = Json.Token.Integer); } else if (float.TryParse(str, NumberStyles.Float, CultureInfo.InvariantCulture, out float single)) { value = single; return(token = Json.Token.Float); } else if (bool.TryParse(str, out bool truefalse)) { value = truefalse; return(token = Json.Token.Boolean); } else { value = null; return(token = Json.Token.Null); } } } value = null; return(token = Json.Token.EndOfFile); }
public override bool FinishItem(ref object?item, string objectKey, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { if (item != null) { return(Program.ReportFailure("Unexpected failure")); } if (!contentTable.ContainsKey("Type")) { return(Program.ReportFailure(parsedFile, parsedKey, "Source has no type")); } if (!(contentTable["Type"] is string TypeString)) { return(Program.ReportFailure("Source type was expected to be a string")); } bool Result; switch (TypeString) { case "AutomaticFromSkill": Result = ParseSourceAutomaticFromSkill(ref item, contentTable, contentTypeTable, itemCollection, lastItemType, parsedFile, parsedKey); break; case "Item": Result = ParseSourceItem(ref item, contentTable, contentTypeTable, itemCollection, lastItemType, parsedFile, parsedKey); break; case "Training": Result = ParseSourceTraining(ref item, contentTable, contentTypeTable, itemCollection, lastItemType, parsedFile, parsedKey); break; case "Effect": Result = ParseSourceEffect(ref item, contentTable, contentTypeTable, itemCollection, lastItemType, parsedFile, parsedKey); break; case "Quest": Result = ParseSourceQuest(ref item, contentTable, contentTypeTable, itemCollection, lastItemType, parsedFile, parsedKey); break; case "Gift": Result = ParseSourceGift(ref item, contentTable, contentTypeTable, itemCollection, lastItemType, parsedFile, parsedKey); break; case "HangOut": Result = ParseSourceHangOut(ref item, contentTable, contentTypeTable, itemCollection, lastItemType, parsedFile, parsedKey); break; default: Result = Program.ReportFailure(parsedFile, parsedKey, $"Unnown source type '{TypeString}'"); break; } Debug.Assert(!Result || item is PgSource); if (item is PgSource NewItem) { NewItem.SourceKey = parsedKey; } return(Result); }
private bool FinishItem(PgAdvancementTable item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { foreach (KeyValuePair <string, object> Entry in contentTable) { string LevelKey = Entry.Key; object Value = Entry.Value; if (!LevelKey.StartsWith("Level_")) { return(Program.ReportFailure($"Invalid advancement key format '{LevelKey}'")); } if (!int.TryParse(LevelKey.Substring(6), out int EntryLevel)) { return(Program.ReportFailure($"Invalid level in key '{LevelKey}'")); } if (item.LevelTable.ContainsKey(EntryLevel)) { return(Program.ReportFailure($"Level {EntryLevel} already added")); } if (!(Value is ParsingContext Context)) { return(Program.ReportFailure($"Value '{Value}' was expected to be a context")); } if (!(Context.Item is PgAdvancement AsAdvancement)) { return(Program.ReportFailure($"Object '{Value}' was unexpected")); } item.LevelTable.Add(EntryLevel, AsAdvancement); } return(true); }
private bool ParseSourceEffect(ref object?item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { if (!contentTable.ContainsKey("EffectName")) { return(Program.ReportFailure(parsedFile, parsedKey, "Source has no effect name")); } if (!(contentTable["EffectName"] is string EffectNameString)) { return(Program.ReportFailure("Source effect name was expected to be a string")); } if (EffectNameString == "Learn Ability") { item = new PgSourceLearnAbility(); return(true); } PgRecipe ParsedRecipe = null !; if (Inserter <PgRecipe> .SetItemByInternalName((PgRecipe valueRecipe) => ParsedRecipe = valueRecipe, EffectNameString, ErrorControl.IgnoreIfNotFound)) { item = new PgSourceRecipe() { Recipe_Key = ParsedRecipe.Key }; return(true); } if (Inserter <PgRecipe> .SetItemByName((PgRecipe valueRecipe) => ParsedRecipe = valueRecipe, EffectNameString, ErrorControl.IgnoreIfNotFound)) { item = new PgSourceRecipe() { Recipe_Key = ParsedRecipe.Key }; return(true); } PgEffect ParsedEffect = null !; if (Inserter <PgEffect> .SetItemByName((PgEffect valueEffect) => ParsedEffect = valueEffect, EffectNameString, ErrorControl.IgnoreIfNotFound)) { item = new PgSourceEffect() { Effect_Key = ParsedEffect.Key }; return(true); } if (!contentTable.ContainsKey("EffectTypeId")) { return(Program.ReportFailure($"Unknown effect name {EffectNameString}")); } if (!(contentTable["EffectTypeId"] is string ValueString)) { return(Program.ReportFailure($"Effect type id was expected to be a string")); } string EffectKey = $"effect_{ValueString}"; if (Inserter <PgEffect> .SetItemByKey((PgEffect valueEffect) => ParsedEffect = valueEffect, EffectKey, ErrorControl.IgnoreIfNotFound)) { item = new PgSourceEffect() { Effect_Key = ParsedEffect.Key }; return(true); } return(Program.ReportFailure($"Unknown effect name {EffectNameString}")); }
private bool FinishItem(PgSpecialValue item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { bool Result = true; foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; switch (Key) { case "Label": Result = SetStringProperty((string valueString) => item.Label = valueString, Value); break; case "Suffix": Result = SetStringProperty((string valueString) => item.Suffix = valueString, Value); break; case "Value": Result = SetFloatProperty((float valueFloat) => item.RawValue = valueFloat, Value); break; case "AttributesThatDelta": Result = Inserter <PgAttribute> .AddPgObjectArrayByKey <PgAttribute>(item.AttributesThatDeltaList, Value); break; case "AttributesThatMod": Result = Inserter <PgAttribute> .AddPgObjectArrayByKey <PgAttribute>(item.AttributesThatModList, Value); break; case "AttributesThatModBase": Result = Inserter <PgAttribute> .AddPgObjectArrayByKey <PgAttribute>(item.AttributesThatModBaseList, Value); break; case "DisplayType": Result = StringToEnumConversion <DisplayType> .SetEnum((DisplayType valueEnum) => item.DisplayType = valueEnum, Value); break; case "SkipIfZero": Result = SetBoolProperty((bool valueBool) => item.RawSkipIfZero = valueBool, Value); break; default: Result = Program.ReportFailure(parsedFile, parsedKey, $"Key '{Key}' not handled"); break; } if (!Result) { break; } } return(Result); }
private bool ParseSourceHangOut(ref object?item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { bool Result = true; PgSourceHangOut NewSource = new PgSourceHangOut(); foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; switch (Key) { case "Type": break; case "Npc": Result = Inserter <PgSource> .SetNpc((PgNpcLocation location) => NewSource.Npc = location, Value, parsedFile, parsedKey); break; default: Result = Program.ReportFailure(parsedFile, parsedKey, $"Key '{Key}' not handled"); break; } if (!Result) { break; } } if (Result) { item = NewSource; return(true); } else { return(false); } }
private bool FinishItem(PgAI item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { bool Result = true; foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; switch (Key) { case "Abilities": Result = Inserter <PgAIAbilitySet> .SetItemProperty((PgAIAbilitySet valueAIAbilitySet) => item.Abilities = valueAIAbilitySet, Value); break; case "Melee": Result = SetBoolProperty((bool valueBool) => item.SetIsMelee(valueBool), Value); break; case "Comment": Result = SetStringProperty((string valueString) => item.Comment = valueString, Value); break; case "UncontrolledPet": Result = SetBoolProperty((bool valueBool) => item.SetIsUncontrolledPet(valueBool), Value); break; case "ServerDriven": Result = SetBoolProperty((bool valueBool) => item.SetIsServerDriven(valueBool), Value); break; case "MinDelayBetweenAbilities": Result = SetFloatProperty((float valueFloat) => item.RawMinDelayBetweenAbilities = valueFloat, Value); break; case "UseAbilitiesWithoutEnemyTarget": Result = SetBoolProperty((bool valueBool) => item.SetUseAbilitiesWithoutEnemyTarget(valueBool), Value); break; case "Swimming": Result = SetBoolProperty((bool valueBool) => item.SetIsSwimming(valueBool), Value); break; case "MobilityType": Result = StringToEnumConversion <MobilityType> .SetEnum((MobilityType valueEnum) => item.MobilityType = valueEnum, Value); break; case "Flying": Result = SetBoolProperty((bool valueBool) => item.SetIsFlying(valueBool), Value); break; case "Description": Result = SetStringProperty((string valueString) => item.Description = valueString, Value); break; default: Result = Program.ReportFailure(parsedFile, parsedKey, $"Key '{Key}' not handled"); break; } if (!Result) { break; } } return(Result); }
private bool ParseSourceAutomaticFromSkill(ref object?item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { bool Result = true; PgSourceAutomaticFromSkill NewSource = new PgSourceAutomaticFromSkill(); foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; switch (Key) { case "Type": break; case "SkillTypeId": Result = ParserSkill.Parse((PgSkill valueSkill) => NewSource.Skill_Key = valueSkill.Key, Value, parsedFile, parsedKey); break; default: Result = Program.ReportFailure(parsedFile, parsedKey, $"Key '{Key}' not handled"); break; } if (!Result) { break; } } if (Result) { item = NewSource; return(true); } else { return(false); } }
private bool FinishItem(PgItemSkillLink item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { if (contentTable.Count == 0) { return(Program.ReportFailure(parsedFile, parsedKey, $"At least one skill expected in a skill link")); } foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; PgSkill ParsedSkill = null !; if (!ParserSkill.Parse((PgSkill valueSkill) => ParsedSkill = valueSkill, Key, parsedFile, parsedKey)) { return(false); } int ParsedLevel = -1; if (!SetIntProperty((int valueInt) => ParsedLevel = valueInt, Value)) { return(false); } if (item.SkillTable.ContainsKey(ParsedSkill.Key)) { return(Program.ReportFailure(parsedFile, parsedKey, $"Skill {Key} already parsed in skill link")); } item.SkillTable.Add(ParsedSkill.Key, ParsedLevel); } return(true); }
private static bool FinishItemSkillXp(ref object?item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, List <string> knownFieldList, List <string> usedFieldList, string parsedFile, string parsedKey) { PgQuestRewardSkillXp NewItem = new PgQuestRewardSkillXp(); bool Result = true; if (contentTable.Count < 3) { Result = Program.ReportFailure(parsedFile, parsedKey, "Missing fields in Skill Xp reward"); } foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; if (!knownFieldList.Contains(Key)) { Result = Program.ReportFailure($"Unknown field {Key}"); } else { usedFieldList.Add(Key); switch (Key) { case "T": break; case "Skill": Result = Inserter <PgSkill> .SetItemByKey((PgSkill valueSkill) => NewItem.Skill_Key = valueSkill.Key, Value); break; case "Xp": Result = SetIntProperty((int valueInt) => NewItem.RawXp = valueInt, Value); break; default: Result = Program.ReportFailure("Unexpected failure"); break; } } if (!Result) { break; } } if (Result) { item = NewItem; return(true); } else { return(false); } }