public static OrderAction FromJson(JProperty orderActionProp) { if (orderActionTypes == null) { orderActionTypes = FindOrderActionsInAssembly(); } string orderActionType = orderActionProp.Name; Type t; if (orderActionTypes.TryGetValue(orderActionType, out t)) { JToken innerJson = orderActionProp.Value; OrderAction orderAction = (OrderAction)orderActionProp.Value.ToObject(t); orderAction.Type = orderActionProp.Name; string prevCategory = string.Empty; if (orderAction.Category != null) { prevCategory = orderAction.Category.Type; } string tempCategory = PrototypeReader.ReadJson(prevCategory, innerJson["JobCategory"]); orderAction.Category = PrototypeManager.JobCategory.Get(tempCategory); orderAction.Priority = (Job.JobPriority)PrototypeReader.ReadJson((int)orderAction.Priority, innerJson["JobPriority"]); return(orderAction); } else { UnityDebugger.Debugger.Log(OrderActionsLogChannel, string.Format("There is no deserializer for OrderAction '{0}'", orderActionType)); return(null); } }
/// <summary> /// Reads the prototype from the specified JObject. /// </summary> /// <param name="jsonProto">The JProperty containing the prototype.</param> public void ReadJsonPrototype(JProperty jsonProto) { Type = jsonProto.Name; JToken innerJson = jsonProto.Value; Slot = PrototypeReader.ReadJson(Slot, innerJson["Slot"]); LocalizationName = PrototypeReader.ReadJson("gear_" + Type, innerJson["LocalizationName"]); LocalizationDescription = PrototypeReader.ReadJson("gear_" + Type + "_desc", innerJson["LocalizationDescription"]); if (innerJson["Stats"] != null) { foreach (JToken stat in innerJson["Stats"]) { Stat prototypeStat = PrototypeManager.Stat.Get(((JProperty)stat).Name); Stat newStat = prototypeStat.Clone(); int value = 0; value = PrototypeReader.ReadJson(value, stat); newStat.Value = value; Stats.Add(((JProperty)stat).Name, newStat); } } if (innerJson["Slots"] != null) { string[] slots = new string[0]; slots = PrototypeReader.ReadJson(slots, innerJson["Slots"]); foreach (string slot in slots) { Slots.Add(slot, false); } } }
/// <summary> /// Reads the prototype from the specified JObject. /// </summary> /// <param name="jsonProto">The JProperty containing the prototype.</param> public void ReadJsonPrototype(JProperty jsonProto) { Type = jsonProto.Name; JToken innerJson = jsonProto.Value; Name = PrototypeReader.ReadJson(Name, innerJson["Name"]); }
/// <summary> /// Reads the prototype from the specified JObject. /// </summary> /// <param name="jsonProto">The JProperty containing the prototype.</param> public void ReadJsonPrototype(JProperty jsonProto) { Type = jsonProto.Name; JToken innerJson = jsonProto.Value; typeTags = new HashSet <string>(PrototypeReader.ReadJsonArray <string>(innerJson["TypeTags"])); LocalizationName = PrototypeReader.ReadJson(LocalizationName, innerJson["LocalizationName"]); LocalizationDescription = PrototypeReader.ReadJson(LocalizationDescription, innerJson["LocalizationDescription"]); EventActions.ReadJson(innerJson["EventActions"]); contextMenuLuaActions = PrototypeReader.ReadContextMenuActions(innerJson["ContextMenuActions"]); if (innerJson["Parameters"] != null) { Parameters.FromJson(innerJson["Parameters"]); } if (innerJson["Requirements"] != null) { ReadJsonRequirements((JArray)innerJson["Requirements"]); } if (innerJson["Optional"] != null) { ReadJsonRequirements((JArray)innerJson["Optional"], true); } }
/// <summary> /// Reads the prototype from the specified JProperty. /// </summary> /// <param name="jsonProto">The JProperty containing the prototype.</param> public void ReadJsonPrototype(JProperty jsonProto) { JToken innerJson = jsonProto.Value; type = jsonProto.Name; IsHidden = PrototypeReader.ReadJson(false, innerJson["hidden"]); LocalizationName = (string)innerJson["LocalizationName"]; }
/// <summary> /// Reads the prototype from the specified JObject. /// </summary> /// <param name="jsonProto">The JProperty containing the prototype.</param> public void ReadJsonPrototype(JProperty jsonProto) { Type = jsonProto.Name; JToken innerJson = jsonProto.Value; ColorMap = PrototypeReader.ReadJson(ColorMap, innerJson["ColorMap"]); LuaFunctionName = PrototypeReader.ReadJson(LuaFunctionName, innerJson["LuaFunctionName"]); }
/// <summary> /// Reads the prototype from the specified JObject. /// </summary> /// <param name="jsonProto">The JProperty containing the prototype.</param> public void ReadJsonPrototype(JProperty jsonProto) { Name = jsonProto.Name; JToken innerJson = jsonProto.Value; LuaFunctionName = PrototypeReader.ReadJson(LuaFunctionName, innerJson["FunctionName"]); this.EventType = EventType.Lua; }
/// <summary> /// A nice little helper (pass it a reader class that is up to the subtree). /// </summary> public SettingsOption(JToken innerJson) { name = PrototypeReader.ReadJson("name", innerJson["Name"]); key = PrototypeReader.ReadJson("key", innerJson["Key"]); defaultValue = PrototypeReader.ReadJson("defaultValue", innerJson["DefaultValue"]); classData = new UIComponent(); classData.ReadJson(innerJson); }
/// <summary> /// Reads the prototype from the specified JObject. /// </summary> /// <param name="jsonProto">The JProperty containing the prototype.</param> public void ReadJsonPrototype(JProperty jsonProto) { Type = jsonProto.Name; JToken innerJson = jsonProto.Value; MaxStackSize = PrototypeReader.ReadJson(50, innerJson["MaxStackSize"]); BasePrice = PrototypeReader.ReadJson(1f, innerJson["BasePrice"]); Category = PrototypeReader.ReadJson(Category, innerJson["Category"]); LocalizationName = PrototypeReader.ReadJson(LocalizationName, innerJson["LocalizationName"]); LocalizationDescription = PrototypeReader.ReadJson(LocalizationDescription, innerJson["LocalizationDescription"]); }
public void ReadJsonPrototype(JToken token) { if (token != null) { Description = PrototypeReader.ReadJson(Description, token["Description"]); IsCompletedLuaFunction = PrototypeReader.ReadJson(IsCompletedLuaFunction, token["IsCompletedLuaFunction"]); Parameters = new Parameter(); Parameters.FromJson(token["Parameters"]); } }
public void ReadJson(JProperty jsonProto) { State = jsonProto.Name; JToken innerJson = jsonProto.Value; delay = PrototypeReader.ReadJson(delay, innerJson["Delay"]); loops = PrototypeReader.ReadJson(loops, innerJson["Loops"]); FlipX = PrototypeReader.ReadJson(FlipX, innerJson["FlipX"]); ValueBased = PrototypeReader.ReadJson(ValueBased, innerJson["ValueBased"]); frames = PrototypeReader.ReadJsonArray <string>(innerJson["Frames"]); }
private Vector2 ReadVector(JToken vectorToken) { Vector2 vector = new Vector2(); if (vectorToken != null) { int x = PrototypeReader.ReadJson(0, vectorToken["X"]); int y = PrototypeReader.ReadJson(0, vectorToken["Y"]); vector.x = x; vector.y = y; } return(vector); }
/// <summary> /// Reads the prototype from the specified JProperty. /// </summary> /// <param name="jsonProto">The JProperty containing the prototype.</param> public void ReadJsonPrototype(JProperty jsonProto) { Title = jsonProto.Name; JToken innerJson = jsonProto.Value; FunctionName = (string)innerJson["FunctionName"]; Description = (string)innerJson["Description"]; DetailedDescription = (string)innerJson["DetailedDescription"]; Parameters = PrototypeReader.ReadJson(Parameters, innerJson["Parameters"]); ParseParameterToTypeInfo(); DefaultValue = (string)innerJson["DefaultValue"] ?? string.Empty; Tags = ((JArray)innerJson["Tags"]).ToObject <string[]>(); }
/// <summary> /// Reads the prototype from the specified JObject. /// </summary> /// <param name="jsonProto">The JProperty containing the prototype.</param> public void ReadJsonPrototype(JProperty jsonProto) { Type = jsonProto.Name; JToken innerJson = jsonProto.Value; BaseMovementCost = PrototypeReader.ReadJson(BaseMovementCost, innerJson["BaseMovementCost"]); PathfindingModifier = PrototypeReader.ReadJson(PathfindingModifier, innerJson["PathfindingModifier"]); PathfindingWeight = PrototypeReader.ReadJson(PathfindingWeight, innerJson["PathfindingWeight"]); LinksToNeighbours = PrototypeReader.ReadJson(LinksToNeighbours, innerJson["LinksToNeighbours"]); CanBuildHereLua = PrototypeReader.ReadJson(CanBuildHereLua, innerJson["CanBuildHereLua"]); LocalizationName = PrototypeReader.ReadJson(LocalizationName, innerJson["LocalizationName"]); LocalizationDescription = PrototypeReader.ReadJson(LocalizationDescription, innerJson["LocalizationDescription"]); OrderActions = PrototypeReader.ReadOrderActions(innerJson["OrderActions"]); }
/// <summary> /// Reads the prototype from the specified JObject. /// </summary> /// <param name="jsonProto">The JProperty containing the prototype.</param> public void ReadJsonPrototype(JProperty jsonProto) { Type = jsonProto.Name; JToken innerJson = jsonProto.Value; Width = PrototypeReader.ReadJson(Width, innerJson["Width"]); Height = PrototypeReader.ReadJson(Height, innerJson["Height"]); BerthPointX = PrototypeReader.ReadJson(BerthPointX, innerJson["BerthPointX"]); BerthPointY = PrototypeReader.ReadJson(BerthPointY, innerJson["BerthPointY"]); BerthDirection = PrototypeReader.ReadJson(BerthDirection, innerJson["BerthDirection"]); ReadJsonStorages(innerJson["Storages"]); ReadJsonTiles(innerJson["Tiles"]); ReadJsonFurnitures(innerJson["Furnitures"]); }
/// <summary> /// Reads the prototype from the specified JObject. /// </summary> /// <param name="jsonProto">The JProperty containing the prototype.</param> public void ReadJsonPrototype(JProperty jsonProto) { Type = jsonProto.Name; JToken innerJson = jsonProto.Value; PotentialNames = new List <string>(PrototypeReader.ReadJsonArray <string>(innerJson["PotentialNames"])); CurrencyName = PrototypeReader.ReadJson(CurrencyName, innerJson["CurrencyName"]); MinCurrencyBalance = PrototypeReader.ReadJson(MinCurrencyBalance, innerJson["MinCurrencyBalance"]); MaxCurrencyBalance = PrototypeReader.ReadJson(MaxCurrencyBalance, innerJson["MaxCurrencyBalance"]); MinSaleMarginMultiplier = PrototypeReader.ReadJson(MinSaleMarginMultiplier, innerJson["MinSaleMarginMultiplier"]); MaxSaleMarginMultiplier = PrototypeReader.ReadJson(MaxSaleMarginMultiplier, innerJson["MaxSaleMarginMultiplier"]); PotentialStock = PrototypeReader.ReadTraderPotentialInventory(innerJson["PotentialStock"]); Animations = PrototypeReader.ReadAnimations(innerJson["Animations"]); }
/// <summary> /// Reads the prototype from the specified JObject. /// </summary> /// <param name="jsonProto">The JProperty containing the prototype.</param> public void ReadJsonPrototype(JProperty jsonProto) { Type = jsonProto.Name; JToken innerJson = jsonProto.Value; typeTags = new HashSet <string>(PrototypeReader.ReadJsonArray <string>(innerJson["TypeTags"])); LocalizationName = PrototypeReader.ReadJson(LocalizationName, innerJson["LocalizationName"]); LocalizationDescription = PrototypeReader.ReadJson(LocalizationDescription, innerJson["LocalizationDescription"]); tileTypeBuildPermissions = new HashSet <string>(PrototypeReader.ReadJsonArray <string>(innerJson["tileTypeBuildPermissions"])); orderActions = PrototypeReader.ReadOrderActions(innerJson["OrderActions"]); contextMenuLuaActions = PrototypeReader.ReadContextMenuActions(innerJson["ContextMenuActions"]); EventActions.ReadJson(innerJson["EventActions"]); if (innerJson["Parameters"] != null) { Parameters.FromJson(innerJson["Parameters"]); } }
/// <summary> /// Reads the sprite from data file for the image. /// </summary> /// <param name="spriteCategory">Sprite category.</param> /// <param name="obj">The Json Object Reader.</param> /// <param name="imageTexture">Image texture.</param> private static void ReadSpriteFromJson(string spriteCategory, JObject obj, Texture2D imageTexture) { string name = PrototypeReader.ReadJson(string.Empty, obj["name"]); int x = PrototypeReader.ReadJson(0, obj["x"]); int y = PrototypeReader.ReadJson(0, obj["y"]); int w = PrototypeReader.ReadJson(1, obj["w"]); int h = PrototypeReader.ReadJson(1, obj["h"]); float pivotX = PrototypeReader.ReadJson(0.5f, obj["pivotX"]); float pivotY = PrototypeReader.ReadJson(0.5f, obj["pivotY"]); if (pivotX < 0 || pivotX > 1 || pivotY < 0 || pivotY > 1) { UnityDebugger.Debugger.LogWarning("SpriteManager", "Pivot for object " + name + " has pivots of " + pivotX + "," + pivotY); } int pixelPerUnit = int.Parse(obj["pixelPerUnit"].ToString()); LoadSprite(spriteCategory, name, imageTexture, new Rect(x * pixelPerUnit, y * pixelPerUnit, w * pixelPerUnit, h * pixelPerUnit), pixelPerUnit, new Vector2(pivotX, pivotY)); }
/// <summary> /// Reads the prototype from the specified JObject. /// </summary> /// <param name="jsonProto">The JProperty containing the prototype.</param> public void ReadJsonPrototype(JProperty jsonProto) { Type = jsonProto.Name; JToken innerJson = jsonProto.Value; string furniture = PrototypeReader.ReadJson(string.Empty, innerJson["RestoreNeedFurn"]); if (furniture != string.Empty) { RestoreNeedFurn = PrototypeManager.Furniture.Get(furniture); } RestoreNeedTime = PrototypeReader.ReadJson(RestoreNeedTime, innerJson["RestoreNeedTime"]); Damage = PrototypeReader.ReadJson(Damage, innerJson["Damage"]); CompleteOnFail = PrototypeReader.ReadJson(CompleteOnFail, innerJson["CompleteOnFail"]); highToLow = PrototypeReader.ReadJson(highToLow, innerJson["HighToLow"]); GrowthRate = PrototypeReader.ReadJson(GrowthRate, innerJson["GrowthRate"]); RestoreNeedAmount = PrototypeReader.ReadJson(RestoreNeedAmount, innerJson["RestoreNeedAmount"]); LocalizationName = PrototypeReader.ReadJson(LocalizationName, innerJson["LocalizationName"]); EventActions.ReadJson(innerJson["EventActions"]); }
public static List <ContextMenuLuaAction> ReadContextMenuActions(JToken contextMenuActionsToken) { List <ContextMenuLuaAction> contextMenu = new List <ContextMenuLuaAction>(); if (contextMenuActionsToken != null) { foreach (JToken action in contextMenuActionsToken) { ContextMenuLuaAction menuItem = new ContextMenuLuaAction(); menuItem.LuaFunction = PrototypeReader.ReadJson(menuItem.LuaFunction, action["LuaFunction"]); menuItem.LocalizationKey = PrototypeReader.ReadJson(menuItem.LocalizationKey, action["LocalizationKey"]); menuItem.RequireCharacterSelected = PrototypeReader.ReadJson(menuItem.RequireCharacterSelected, action["RequireCharacterSelected"]); menuItem.DevModeOnly = PrototypeReader.ReadJson(menuItem.DevModeOnly, action["DevModeOnly"]); contextMenu.Add(menuItem); } } return(contextMenu); }
public static List <TraderPotentialInventory> ReadTraderPotentialInventory(JToken potentialInventoryToken) { List <TraderPotentialInventory> potentialInventory = new List <TraderPotentialInventory>(); if (potentialInventoryToken != null) { foreach (JToken inventoryToken in potentialInventoryToken) { TraderPotentialInventory inventory = new TraderPotentialInventory(); inventory.Type = PrototypeReader.ReadJson(inventory.Type, inventoryToken["Type"]); inventory.Category = PrototypeReader.ReadJson(inventory.Category, inventoryToken["Category"]); inventory.MinQuantity = PrototypeReader.ReadJson(inventory.MinQuantity, inventoryToken["MinQuantity"]); inventory.MaxQuantity = PrototypeReader.ReadJson(inventory.MaxQuantity, inventoryToken["MaxQuantity"]); inventory.Rarity = PrototypeReader.ReadJson(inventory.Rarity, inventoryToken["Rarity"]); potentialInventory.Add(inventory); } } return(potentialInventory); }
/// <summary> /// Reads the prototype from the specified JObject. /// </summary> /// <param name="jsonProto">The JProperty containing the prototype.</param> public void ReadJsonPrototype(JProperty jsonProto) { Name = jsonProto.Name; JToken innerJson = jsonProto.Value; Goals = new List <QuestGoal>(); Rewards = new List <QuestReward>(); RequiredQuests = new List <string>(); Description = PrototypeReader.ReadJson(Description, innerJson["Description"]); if (innerJson["RequiredQuests"] != null) { foreach (JToken token in innerJson["RequiredQuests"]) { RequiredQuests.Add((string)token); } } if (innerJson["Goals"] != null) { foreach (JToken token in innerJson["Goals"]) { QuestGoal goal = new QuestGoal(); goal.ReadJsonPrototype(token); Goals.Add(goal); } } if (innerJson["Rewards"] != null) { foreach (JToken token in innerJson["Rewards"]) { QuestReward reward = new QuestReward(); reward.ReadJsonPrototype(token); Rewards.Add(reward); } } }
private void ReadJsonRequirements(JArray requirementsArray, bool isOptional = false) { foreach (var requirementToken in requirementsArray) { if (requirementToken["Furniture"] != null) { // Furniture must have either Type or TypeTag, try both, check for null later string type = (string)requirementToken["Furniture"]["Type"]; string typeTag = (string)requirementToken["Furniture"]["TypeTag"]; int count = 0; if (!isOptional) { count = PrototypeReader.ReadJson(count, requirementToken["Furniture"]["Count"]); } requiredFurniture.Add(new FurnitureRequirement(type, typeTag, count)); } else if (requirementToken["Size"] != null && !isOptional) { requiredSize = PrototypeReader.ReadJson(requiredSize, requirementToken["Size"]); } } }
/// <summary> /// Reads the prototype from the specified JObject. /// </summary> /// <param name="jsonProto">The JProperty containing the prototype.</param> public void ReadJsonPrototype(JProperty jsonProto) { Type = jsonProto.Name; JToken innerJson = jsonProto.Value; MovementCost = PrototypeReader.ReadJson(MovementCost, innerJson["MovementCost"]); PathfindingModifier = PrototypeReader.ReadJson(PathfindingModifier, innerJson["PathfindingModifier"]); PathfindingWeight = PrototypeReader.ReadJson(PathfindingWeight, innerJson["PathfindingWeight"]); Width = PrototypeReader.ReadJson(Width, innerJson["Width"]); Height = PrototypeReader.ReadJson(Height, innerJson["Height"]); /* TODO: This may need altered, for now it is built to match the functionality of the xml reader * in that if no value is set it is invincible, and the furniture's health system will make it invincible if access while null. * It may be preferable to have the HealthSystem constructor detect an "invalid" health amount such as -1, and autoset to invincible as appropriate */ float healthValue = PrototypeReader.ReadJson(-1f, innerJson["Health"]); if (Mathf.Abs(healthValue - -1) > Mathf.Epsilon) { health = new HealthSystem(healthValue, false, true, false, false); } LinksToNeighbours = PrototypeReader.ReadJson(LinksToNeighbours, innerJson["LinksToNeighbours"]); EnclosesRoom = PrototypeReader.ReadJson(EnclosesRoom, innerJson["EnclosesRoom"]); CanRotate = PrototypeReader.ReadJson(CanRotate, innerJson["CanRotate"]); DragType = PrototypeReader.ReadJson(DragType, innerJson["DragType"]); isEnterableAction = PrototypeReader.ReadJson(isEnterableAction, innerJson["IsEnterableAction"]); getProgressInfoNameAction = PrototypeReader.ReadJson(getProgressInfoNameAction, innerJson["GetProgressInfoNameAction"]); LocalizationName = PrototypeReader.ReadJson("furn_" + Type, innerJson["LocalizationName"]); LocalizationDescription = PrototypeReader.ReadJson("furn_" + Type + "_desc", innerJson["LocalizationDescription"]); typeTags = new HashSet <string>(PrototypeReader.ReadJsonArray <string>(innerJson["TypeTags"])); if (innerJson["CanReplaceFurniture"] != null) { replaceableFurniture = ((JArray)innerJson["CanReplaceFurniture"]).ToObject <List <string> >(); } tileTypeBuildPermissions = new HashSet <string>(PrototypeReader.ReadJsonArray <string>(innerJson["TileTypeBuildPermissions"])); orderActions = PrototypeReader.ReadOrderActions(innerJson["OrderActions"]); contextMenuLuaActions = PrototypeReader.ReadContextMenuActions(innerJson["ContextMenuActions"]); Animations = PrototypeReader.ReadFurnitureAnimations(innerJson["Animations"]); EventActions.ReadJson(innerJson["EventActions"]); Jobs.ReadOffsets(innerJson["Jobs"]); Parameters.FromJson(innerJson["Parameters"]); if (innerJson["Components"] != null) { JToken componentsJArray = innerJson["Components"]; foreach (JToken componentJson in componentsJArray) { BuildableComponent component = BuildableComponent.FromJson(componentJson); if (component != null) { component.InitializePrototype(this); components.Add(component); if (component.IsValid() == false) { UnityDebugger.Debugger.LogError("BuildableComponent", "Error parsing " + component.GetType() + " for " + Type); } } } } if (orderActions.ContainsKey("Uninstall")) { Inventory asInventory = Inventory.CreatePrototype(Type, 1, 0f, "crated_furniture", LocalizationName, LocalizationDescription); PrototypeManager.Inventory.Add(asInventory); } }