Example #1
0
        /// <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);
            }
        }
Example #2
0
    /// <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"]);
        }
    }
Example #3
0
    /// <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);
        }
    }