public static void AfterSelectedWorld()
        {
            var textureMapping = new ItemTypesServer.TextureMapping(new JSONNode());

            textureMapping.AlbedoPath = MultiPath.Combine(ConstructionModEntries.AssetsDirectory, "textures", "albedo", "capsulesTop.png");
            ItemTypesServer.SetTextureMapping(ConstructionModEntries.MOD_PREFIX + "capsuletop", textureMapping);
        }
예제 #2
0
 public static void localize(string locName, string locFilename, JSONNode jsonFromMod, string keyprefix, bool verbose)
 {
     try {
         string   patchPath = MultiPath.Combine("gamedata", "localization", locName, locFilename);
         JSONNode jsonToPatch;
         if (Pipliz.JSON.JSON.Deserialize(patchPath, out jsonToPatch, false))
         {
             foreach (KeyValuePair <string, JSONNode> entry in jsonFromMod.LoopObject())
             {
                 string realkey = keyprefix + entry.Key;
                 string val     = jsonFromMod.GetAs <string>(entry.Key);
                 if (!jsonToPatch.HasChild(realkey))
                 {
                     Pipliz.Log.Write(string.Format("translation '{0}' => '{1}' added to '{2}/{3}'. This will apply AFTER next restart!!!", realkey, val, locName, locFilename));
                 }
                 else if (!jsonToPatch.GetAs <string>(realkey).Equals(val))
                 {
                     Pipliz.Log.Write(string.Format("translation '{0}' => '{1}' changed in '{2}/{3}'. This will apply AFTER next restart!!!", realkey, val, locName, locFilename));
                 }
                 jsonToPatch.SetAs(realkey, val);
             }
             Pipliz.JSON.JSON.Serialize(patchPath, jsonToPatch);
             log(string.Format("Patched mod localization file '{0}/{1}' into '{2}'", locName, locFilename, patchPath), verbose);
         }
         else
         {
             log(string.Format("Could not deserialize json from '{0}'", patchPath), verbose);
         }
     } catch (Exception) {
         log(string.Format("Exception while localizing {0}", Path.Combine(locName, locFilename)), verbose);
     }
 }
        public static void AfterAddingBaseTypes(Dictionary <string, ItemTypesServer.ItemTypeRaw> itemTypes)
        {
            string iconFilepath = MultiPath.Combine(ConstructionModEntries.AssetsDirectory, "icons", "capsule.png");

            foreach (string blueprintTypename in ManagerBlueprints.Blueprints.Keys)
            {
                itemTypes.Add(blueprintTypename + CAPSULE_SUFFIX, new ItemTypesServer.ItemTypeRaw(blueprintTypename + CAPSULE_SUFFIX,
                                                                                                  new JSONNode()
                                                                                                  .SetAs("onPlaceAudio", "woodPlace")
                                                                                                  .SetAs("onRemoveAudio", "woodDeleteLight")
                                                                                                  .SetAs("icon", iconFilepath)
                                                                                                  .SetAs("sideall", "planks")
                                                                                                  .SetAs("sidey+", ConstructionModEntries.MOD_PREFIX + "capsuletop")
                                                                                                  .SetAs("isRotatable", "true")
                                                                                                  .SetAs("rotatablex+", blueprintTypename + CAPSULE_SUFFIX + "x+")
                                                                                                  .SetAs("rotatablex-", blueprintTypename + CAPSULE_SUFFIX + "x-")
                                                                                                  .SetAs("rotatablez+", blueprintTypename + CAPSULE_SUFFIX + "z+")
                                                                                                  .SetAs("rotatablez-", blueprintTypename + CAPSULE_SUFFIX + "z-")
                                                                                                  .SetAs("npcLimit", "0")
                                                                                                  ));
                foreach (string xz in new string [] { "x+", "x-", "z+", "z-" })
                {
                    itemTypes.Add(blueprintTypename + CAPSULE_SUFFIX + xz, new ItemTypesServer.ItemTypeRaw(blueprintTypename + CAPSULE_SUFFIX + xz,
                                                                                                           new JSONNode()
                                                                                                           .SetAs("parentType", blueprintTypename + CAPSULE_SUFFIX)
                                                                                                           ));
                }
            }
        }
예제 #4
0
 public static void OnAssemblyLoaded(string path)
 {
     ModDirectory    = Path.GetDirectoryName(path);
     AssetsDirectory = Path.Combine(ModDirectory, "assets");
     ModLocalizationHelper.localize(Path.Combine(AssetsDirectory, "localization"), MOD_PREFIX, false);
     // TODO this is really hacky (maybe better in future ModAPI)
     RelativeTexturesPath = new Uri(MultiPath.Combine(Path.GetFullPath("gamedata"), "textures", "materials", "blocks", "albedo", "dummyfile")).MakeRelativeUri(new Uri(Path.Combine(AssetsDirectory, "textures"))).OriginalString;
     RelativeIconsPath    = new Uri(MultiPath.Combine(Path.GetFullPath("gamedata"), "textures", "icons", "dummyfile")).MakeRelativeUri(new Uri(MultiPath.Combine(AssetsDirectory, "icons"))).OriginalString;
 }
예제 #5
0
        public static void AfterSelectedWorld()
        {
            Pipliz.Log.Write(string.Format("Started loading door texture mappings..."));
            JSONNode jsonTextureMapping;

            JSON.Deserialize(Path.Combine(DoorsDirectory, "doorstexturemapping.json"), out jsonTextureMapping, true);
            if (jsonTextureMapping.NodeType == NodeType.Object)
            {
                foreach (KeyValuePair <string, JSONNode> textureEntry in jsonTextureMapping.LoopObject())
                {
                    try {
                        foreach (string suffix in new string[] { "", OPEN_SUFFIX })
                        {
                            ItemTypesServer.TextureMapping textureMapping = new ItemTypesServer.TextureMapping(new JSONNode());
                            string textureTypeValue;
                            if (textureEntry.Value.TryGetAs <string> ("albedo", out textureTypeValue) && !textureTypeValue.Equals("neutral"))
                            {
                                string realTextureTypeValue = MultiPath.Combine(DoorsDirectory, "textures", "albedo", textureTypeValue + ".png");
                                Pipliz.Log.Write(string.Format("Rewriting {0} texture path from '{1}' to '{2}'", "albedo", textureTypeValue, realTextureTypeValue));
                                textureMapping.AlbedoPath = realTextureTypeValue;
                            }
                            if (textureEntry.Value.TryGetAs <string> ("normal", out textureTypeValue) && !textureTypeValue.Equals("neutral"))
                            {
                                string realTextureTypeValue = MultiPath.Combine(DoorsDirectory, "textures", "normal", textureTypeValue + ".png");
                                Pipliz.Log.Write(string.Format("Rewriting {0} texture path from '{1}' to '{2}'", "normal", textureTypeValue, realTextureTypeValue));
                                textureMapping.NormalPath = realTextureTypeValue;
                            }
                            if (textureEntry.Value.TryGetAs <string> ("emissive", out textureTypeValue) && !textureTypeValue.Equals("neutral"))
                            {
                                string realTextureTypeValue = MultiPath.Combine(DoorsDirectory, "textures", "emissive", textureTypeValue + ".png");
                                Pipliz.Log.Write(string.Format("Rewriting {0} texture path from '{1}' to '{2}'", "emissive", textureTypeValue, realTextureTypeValue));
                                textureMapping.EmissivePath = realTextureTypeValue;
                            }
                            if (textureEntry.Value.TryGetAs <string> ("height", out textureTypeValue) && !textureTypeValue.Equals("neutral"))
                            {
                                string realTextureTypeValue = MultiPath.Combine(DoorsDirectory, "textures", "height", textureTypeValue + ".png");
                                Pipliz.Log.Write(string.Format("Rewriting {0} texture path from '{1}' to '{2}'", "height", textureTypeValue, realTextureTypeValue));
                                textureMapping.HeightPath = realTextureTypeValue;
                            }
                            string realkey = MOD_PREFIX + textureEntry.Key + suffix;
                            Pipliz.Log.Write(string.Format("Adding texture mapping for '{0}'", realkey));
                            ItemTypesServer.SetTextureMapping(realkey, textureMapping);
                        }
                    } catch (Exception exception) {
                        Pipliz.Log.WriteError(string.Format("Exception while loading from {0}; {1}", "doorstexturemapping.json", exception.Message));
                    }
                }
            }
        }
예제 #6
0
 public static void AfterAddingBaseTypes()
 {
     ItemTypesServer.AddTextureMapping(SCAFFOLD_ITEM_TYPE, new JSONNode()
                                       .SetAs("albedo", MultiPath.Combine(ConstructionModEntries.RelativeTexturesPath, "albedo", "scaffold"))
                                       .SetAs("normal", "neutral")
                                       .SetAs("emissive", "neutral")
                                       .SetAs("height", "neutral")
                                       );
     ItemTypes.AddRawType(SCAFFOLD_ITEM_TYPE, new JSONNode(NodeType.Object)
                          .SetAs("sideall", SCAFFOLD_ITEM_TYPE)
                          .SetAs("onRemove", new JSONNode(NodeType.Array))
                          .SetAs("isSolid", false)
                          .SetAs("destructionTime", 100)
                          );
 }
예제 #7
0
 public static void AfterAddingBaseTypes()
 {
     ItemTypesServer.AddTextureMapping(ConstructionModEntries.MOD_PREFIX + "architecttop", new JSONNode()
                                       .SetAs("albedo", MultiPath.Combine(ConstructionModEntries.RelativeTexturesPath, "albedo", "architectTop"))
                                       .SetAs("normal", "neutral")
                                       .SetAs("emissive", "neutral")
                                       .SetAs("height", "neutral")
                                       );
     ItemTypes.AddRawType(JOB_ITEM_KEY, new JSONNode(NodeType.Object)
                          .SetAs("icon", Path.Combine(ConstructionModEntries.RelativeIconsPath, "architect.png"))
                          .SetAs("onPlaceAudio", "woodPlace")
                          .SetAs("onRemoveAudio", "woodDeleteLight")
                          .SetAs("sideall", "planks")
                          .SetAs("sidey+", ConstructionModEntries.MOD_PREFIX + "architecttop")
                          .SetAs("npcLimit", 0)
                          );
 }
 public static void AfterWorldLoad()
 {
     foreach (string fullDirPath in Directory.GetDirectories(BlocksDirectory))
     {
         string packageName = Path.GetFileName(fullDirPath);
         if (packageName.Equals("examples"))
         {
             continue;
         }
         try {
             Pipliz.Log.Write(string.Format("Loading localizations from package {0}", packageName));
             ModLocalizationHelper.localize(MultiPath.Combine(BlocksDirectory, packageName, "localization"), MOD_PREFIX + packageName + ".");
         } catch (Exception exception) {
             Pipliz.Log.WriteError(string.Format("Exception while loading {0} package; {1}", packageName, exception.Message));
         }
     }
 }
예제 #9
0
        public static void AfterAddingBaseTypes()
        {
            Pipliz.Log.Write(string.Format("Blueprints relative texture path is {0}", ConstructionModEntries.RelativeTexturesPath));
            ItemTypesServer.AddTextureMapping(ConstructionModEntries.MOD_PREFIX + "blueprinttop", new JSONNode()
                                              .SetAs("albedo", MultiPath.Combine(ConstructionModEntries.RelativeTexturesPath, "albedo", "blueprintsTop"))
                                              .SetAs("normal", "neutral")
                                              .SetAs("emissive", "neutral")
                                              .SetAs("height", "neutral")
                                              );
            string iconFilepath = MultiPath.Combine(ConstructionModEntries.RelativeIconsPath, "blueprint.png");

            foreach (string blueprintTypename in ManagerBlueprints.blueprints.Keys)
            {
                ItemTypes.AddRawType(blueprintTypename,
                                     new JSONNode(NodeType.Object)
                                     .SetAs("onRemoveAudio", "woodDeleteLight")
                                     .SetAs("onPlaceAudio", "woodPlace")
                                     .SetAs("icon", iconFilepath)
                                     .SetAs("sideall", "planks")
                                     .SetAs("sidey+", ConstructionModEntries.MOD_PREFIX + "blueprinttop")
                                     .SetAs("npcLimit", "0")
                                     .SetAs("isRotatable", "true")
                                     .SetAs("rotatablex+", blueprintTypename + "x+")
                                     .SetAs("rotatablex-", blueprintTypename + "x-")
                                     .SetAs("rotatablez+", blueprintTypename + "z+")
                                     .SetAs("rotatablez-", blueprintTypename + "z-")
                                     );
                ItemTypes.AddRawType(blueprintTypename + "x+",
                                     new JSONNode(NodeType.Object)
                                     .SetAs("parentType", blueprintTypename)
                                     );
                ItemTypes.AddRawType(blueprintTypename + "x-",
                                     new JSONNode(NodeType.Object)
                                     .SetAs("parentType", blueprintTypename)
                                     );
                ItemTypes.AddRawType(blueprintTypename + "z+",
                                     new JSONNode(NodeType.Object)
                                     .SetAs("parentType", blueprintTypename)
                                     );
                ItemTypes.AddRawType(blueprintTypename + "z-",
                                     new JSONNode(NodeType.Object)
                                     .SetAs("parentType", blueprintTypename)
                                     );
            }
        }
예제 #10
0
        public static void AfterAddingBaseTypes()
        {
            ItemTypesServer.AddTextureMapping(ConstructionModEntries.MOD_PREFIX + "capsuletop", new JSONNode()
                                              .SetAs("albedo", MultiPath.Combine(ConstructionModEntries.RelativeTexturesPath, "albedo", "capsulesTop"))
                                              .SetAs("normal", "neutral")
                                              .SetAs("emissive", "neutral")
                                              .SetAs("height", "neutral")
                                              );
            string iconFilepath = Path.Combine(ConstructionModEntries.RelativeIconsPath, "capsule.png");

            foreach (string blueprintTypename in ManagerBlueprints.blueprints.Keys)
            {
                ItemTypes.AddRawType(blueprintTypename + CAPSULE_SUFFIX,
                                     new JSONNode(NodeType.Object)
                                     .SetAs("onPlaceAudio", "woodPlace")
                                     .SetAs("icon", iconFilepath)
                                     .SetAs("sideall", "planks")
                                     .SetAs("sidey+", ConstructionModEntries.MOD_PREFIX + "capsuletop")
                                     .SetAs("isSolid", "false")
                                     .SetAs("isRotatable", "true")
                                     .SetAs("rotatablex+", blueprintTypename + CAPSULE_SUFFIX + "x+")
                                     .SetAs("rotatablex-", blueprintTypename + CAPSULE_SUFFIX + "x-")
                                     .SetAs("rotatablez+", blueprintTypename + CAPSULE_SUFFIX + "z+")
                                     .SetAs("rotatablez-", blueprintTypename + CAPSULE_SUFFIX + "z-")
                                     .SetAs("npcLimit", "0")
                                     );
                ItemTypes.AddRawType(blueprintTypename + CAPSULE_SUFFIX + "x+",
                                     new JSONNode(NodeType.Object)
                                     .SetAs("parentType", blueprintTypename + CAPSULE_SUFFIX)
                                     );
                ItemTypes.AddRawType(blueprintTypename + CAPSULE_SUFFIX + "x-",
                                     new JSONNode(NodeType.Object)
                                     .SetAs("parentType", blueprintTypename + CAPSULE_SUFFIX)
                                     );
                ItemTypes.AddRawType(blueprintTypename + CAPSULE_SUFFIX + "z+",
                                     new JSONNode(NodeType.Object)
                                     .SetAs("parentType", blueprintTypename + CAPSULE_SUFFIX)
                                     );
                ItemTypes.AddRawType(blueprintTypename + CAPSULE_SUFFIX + "z-",
                                     new JSONNode(NodeType.Object)
                                     .SetAs("parentType", blueprintTypename + CAPSULE_SUFFIX)
                                     );
            }
        }
예제 #11
0
        public static void IntegrateAudio(string audioFilesPath, string namesPrefix, string relativeAudioPath)
        {
            try {
                string[] jsonfiles = Directory.GetFiles(audioFilesPath, "*.json", SearchOption.TopDirectoryOnly);
                foreach (string jsonfilepath in jsonfiles)
                {
                    JSONNode jsonAudio;
                    Pipliz.JSON.JSON.Deserialize(jsonfilepath, out jsonAudio, true);
                    string colName;
                    if (jsonAudio.TryGetAs("clipCollectionName", out colName))
                    {
                        string realColName = namesPrefix + colName;
                        Pipliz.Log.Write(string.Format("Rewriting audio collection name from '{0}' to '{1}'", colName, realColName));
                        jsonAudio.SetAs("clipCollectionName", realColName);
                    }
                    JSONNode jsonFileList;
                    if (jsonAudio.TryGetAs("fileList", out jsonFileList) && jsonFileList.NodeType == NodeType.Array)
                    {
                        foreach (JSONNode fileNode in jsonFileList.LoopArray())
                        {
                            string audioPath;
                            if (fileNode.TryGetAs("path", out audioPath))
                            {
                                string realAudioPath = Path.Combine(relativeAudioPath, audioPath);
                                Pipliz.Log.Write(string.Format("Rewriting audio file path from '{0}' to '{1}'", audioPath, realAudioPath));
                                fileNode.SetAs("path", realAudioPath);
                            }
                        }
                    }
                    string jsontargetfilepath = MultiPath.Combine(Path.GetFullPath("gamedata"), "audio", namesPrefix + Path.GetFileName(jsonfilepath));
                    Pipliz.JSON.JSON.Serialize(jsontargetfilepath, jsonAudio);
                }
            } catch (DirectoryNotFoundException) {
//        Pipliz.Log.Write(string.Format("No audio directory found at {0}", audioFilesPath));
            }
        }
 public static void AfterAddingBaseTypes(Dictionary <string, ItemTypesServer.ItemTypeRaw> itemTypes)
 {
     itemTypes.Add(JOB_ITEM_KEY, new ItemTypesServer.ItemTypeRaw(JOB_ITEM_KEY, new JSONNode()
                                                                 .SetAs("onPlaceAudio", "woodPlace")
                                                                 .SetAs("onRemoveAudio", "woodDeleteLight")
                                                                 .SetAs("icon", MultiPath.Combine(ConstructionModEntries.AssetsDirectory, "icons", "architect.png"))
                                                                 .SetAs("sideall", "planks")
                                                                 .SetAs("sidey+", ConstructionModEntries.MOD_PREFIX + "architecttop")
                                                                 .SetAs("npcLimit", 0)
                                                                 ));
 }
예제 #13
0
        public static void AfterAddingBaseTypes(Dictionary <string, ItemTypesServer.ItemTypeRaw> itemTypes)
        {
            Pipliz.Log.Write(string.Format("Started loading door types..."));
            JSONNode jsonTypes;

            if (!JSON.Deserialize(Path.Combine(DoorsDirectory, "doorstypes.json"), out jsonTypes, false))
            {
                Pipliz.Log.Write("No door types file found, so no doors loaded");
                return;
            }
            if (jsonTypes.NodeType != NodeType.Object)
            {
                Pipliz.Log.WriteError(string.Format("Expected json object in {0}, but got {1} instead", "doorstypes.json", jsonTypes.NodeType));
                return;
            }
            foreach (KeyValuePair <string, JSONNode> typeEntry in jsonTypes.LoopObject())
            {
                try {
                    foreach (string suffix in new string[] { "", OPEN_SUFFIX })
                    {
                        JSONNode jsonType = new JSONNode();
                        string   icon;
                        if (typeEntry.Value.TryGetAs("icon", out icon) && suffix.Length < 1)
                        {
                            string realicon = MultiPath.Combine(DoorsDirectory, "icons", icon);
                            Pipliz.Log.Write(string.Format("Rewriting icon path from '{0}' to '{1}'", icon, realicon));
                            jsonType.SetAs("icon", realicon);
                        }
                        string mesh;
                        if (typeEntry.Value.TryGetAs("mesh" + suffix, out mesh))
                        {
                            string realmesh = MultiPath.Combine(DoorsDirectory, "meshes", mesh);
                            Pipliz.Log.Write(string.Format("Rewriting mesh path from '{0}' to '{1}'", mesh, realmesh));
                            jsonType.SetAs("mesh", realmesh);
                        }
                        string parentType;
                        if (typeEntry.Value.TryGetAs("parentType", out parentType))
                        {
                            string realParentType = MOD_PREFIX + parentType + suffix;
                            Pipliz.Log.Write(string.Format("Rewriting parentType from '{0}' to '{1}'", parentType, realParentType));
                            jsonType.SetAs("parentType", realParentType);
                        }
                        JSONNode onRemove;
                        if (typeEntry.Value.TryGetAs <JSONNode> ("onRemove", out onRemove))
                        {
                            JSONNode jsonOnRemove = new JSONNode();
                            foreach (JSONNode onRemovePart in onRemove.LoopArray())
                            {
                                string removeType;
                                if (onRemovePart.TryGetAs("type", out removeType))
                                {
                                    string realOnRemove = MOD_PREFIX + removeType;
                                    Pipliz.Log.Write(string.Format("Rewriting onRemove type from '{0}' to '{1}'", removeType, realOnRemove));
                                    jsonOnRemove.SetAs("type", realOnRemove);
                                    jsonOnRemove.SetAs("amount", 1);
                                    jsonOnRemove.SetAs("chance", 1);
                                }
                            }
                            JSONNode jsonOnRemoveGroup = new JSONNode(NodeType.Array);
                            jsonOnRemoveGroup.AddToArray(jsonOnRemove);
                            jsonType.SetAs("onRemove", jsonOnRemoveGroup);
                        }
                        else if (suffix.Length > 0)
                        {
                            string plainKey = MOD_PREFIX + typeEntry.Key;
                            if (typeEntry.Key.EndsWith("x+") || typeEntry.Key.EndsWith("x-") || typeEntry.Key.EndsWith("z+") || typeEntry.Key.EndsWith("z-"))
                            {
                                plainKey = plainKey.Substring(0, plainKey.Length - 2);
                            }
                            ItemTypesServer.ItemTypeRaw removeType;
                            if (itemTypes.TryGetValue(plainKey, out removeType))
                            {
                                plainKey = ItemTypes.IndexLookup.GetName(removeType.OnRemoveItems [0].item.Type);
                            }
                            JSONNode jsonOnRemove = new JSONNode();
                            jsonOnRemove.SetAs("type", plainKey);
                            jsonOnRemove.SetAs("amount", 1);
                            jsonOnRemove.SetAs("chance", 1);
                            JSONNode jsonOnRemoveGroup = new JSONNode(NodeType.Array);
                            jsonOnRemoveGroup.AddToArray(jsonOnRemove);
                            jsonType.SetAs("onRemove", jsonOnRemoveGroup);
                            Pipliz.Log.Write(string.Format("Setting onRemove type for '{0}' to '{1}'", typeEntry.Key + suffix, plainKey));
                        }
                        string realkey;
                        if (!(typeEntry.Key.EndsWith("x+") || typeEntry.Key.EndsWith("x-") || typeEntry.Key.EndsWith("z+") || typeEntry.Key.EndsWith("z-")))
                        {
                            jsonType
                            .SetAs("isSolid", suffix.Length < 1)
                            .SetAs("needsBase", false)
                            .SetAs("isRotatable", true)
                            .SetAs("sideall", "SELF")
                            .SetAs("npcLimit", 0);
                            foreach (string rotatable in new string[] { "rotatablex+", "rotatablex-", "rotatablez+", "rotatablez-" })
                            {
                                string key;
                                if (typeEntry.Value.TryGetAs(rotatable, out key))
                                {
                                    string rotatablekey = MOD_PREFIX + key.Substring(0, key.Length - 2) + suffix + key.Substring(key.Length - 2);
                                    Pipliz.Log.Write(string.Format("Rewriting rotatable key '{0}' to '{1}'", key, rotatablekey));
                                    jsonType.SetAs(rotatable, rotatablekey);
                                }
                                else
                                {
                                    Pipliz.Log.WriteError(string.Format("Attribute {0} not found for base type {1}", rotatable, typeEntry.Key));
                                }
                            }
                            if (suffix.Length < 1)
                            {
                                foreach (string propName in new string[] { "onDoorOpenAudio", "onRemoveAudio" })
                                {
                                    string openAudio;
                                    if (typeEntry.Value.TryGetAs(propName, out openAudio))
                                    {
                                        jsonType.SetAs("onRemoveAudio", openAudio);
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                foreach (string propName in new string[] { "onDoorCloseAudio", "onPlaceAudio" })
                                {
                                    string closeAudio;
                                    if (typeEntry.Value.TryGetAs(propName, out closeAudio))
                                    {
                                        jsonType.SetAs("onRemoveAudio", closeAudio);
                                        break;
                                    }
                                }
                            }
                            realkey = MOD_PREFIX + typeEntry.Key + suffix;
                            Pipliz.Log.Write(string.Format("Adding door base type '{0}'", realkey));
                            if (suffix.Length < 1)
                            {
                                doorClosedTypeKeys.Add(realkey);
                            }
                            else
                            {
                                doorOpenTypeKeys.Add(realkey);
                            }
                        }
                        else
                        {
                            realkey = MOD_PREFIX + typeEntry.Key.Substring(0, typeEntry.Key.Length - 2) + suffix + typeEntry.Key.Substring(typeEntry.Key.Length - 2);
                            Pipliz.Log.Write(string.Format("Adding door rotatable type '{0}'", realkey));
                        }
                        itemTypes.Add(realkey, new ItemTypesServer.ItemTypeRaw(realkey, jsonType));
                    }
                } catch (Exception exception) {
                    Pipliz.Log.WriteError(string.Format("Exception while loading door type {0}; {1}", typeEntry.Key, exception.Message));
                }
            }
        }
예제 #14
0
 public static void AfterAddingBaseTypes(Dictionary <string, ItemTypesServer.ItemTypeRaw> itemTypes)
 {
     itemTypes.Add(JOB_ITEM_KEY, new ItemTypesServer.ItemTypeRaw(JOB_ITEM_KEY, new JSONNode()
                                                                 .SetAs("npcLimit", 1)
                                                                 .SetAs("icon", MultiPath.Combine(AssetsDirectory, "icons", "buildtool.png"))
                                                                 .SetAs("isPlaceable", false)
                                                                 ));
 }
 public static void AfterAddingBaseTypes(Dictionary <string, ItemTypesServer.ItemTypeRaw> itemTypes)
 {
     itemTypes.Add(SCAFFOLD_ITEM_TYPE, new ItemTypesServer.ItemTypeRaw(SCAFFOLD_ITEM_TYPE, new JSONNode()
                                                                       .SetAs("onRemove", new JSONNode(NodeType.Array))
                                                                       .SetAs("isSolid", false)
                                                                       .SetAs("mesh", MultiPath.Combine(ConstructionModEntries.AssetsDirectory, "meshes", "scaffold.obj"))
                                                                       .SetAs("sideall", "planks")
                                                                       .SetAs("destructionTime", 100)
                                                                       ));
 }
 public static void AfterSelectedWorld()
 {
     foreach (string fullDirPath in Directory.GetDirectories(BlocksDirectory))
     {
         string packageName = Path.GetFileName(fullDirPath);
         if (packageName.Equals("examples"))
         {
             continue;
         }
         Pipliz.Log.Write(string.Format("Started loading '{0}' texture mappings...", packageName));
         JSONNode jsonTextureMapping;
         if (Pipliz.JSON.JSON.Deserialize(MultiPath.Combine(BlocksDirectory, packageName, "texturemapping.json"), out jsonTextureMapping, false))
         {
             if (jsonTextureMapping.NodeType == NodeType.Object)
             {
                 foreach (KeyValuePair <string, JSONNode> textureEntry in jsonTextureMapping.LoopObject())
                 {
                     try {
                         string albedoPath   = null;
                         string normalPath   = null;
                         string emissivePath = null;
                         string heightPath   = null;
                         foreach (string textureType in new string[] { "albedo", "normal", "emissive", "height" })
                         {
                             string textureTypeValue     = textureEntry.Value.GetAs <string> (textureType);
                             string realTextureTypeValue = textureTypeValue;
                             if (!textureTypeValue.Equals("neutral"))
                             {
                                 if (textureTypeValue.StartsWith(VANILLA_PREFIX))
                                 {
                                     realTextureTypeValue = realTextureTypeValue.Substring(VANILLA_PREFIX.Length);
                                 }
                                 else
                                 {
                                     realTextureTypeValue = MultiPath.Combine(BlocksDirectory, packageName, "textures", textureType, textureTypeValue + ".png");
                                     if (textureType.Equals("albedo"))
                                     {
                                         albedoPath = realTextureTypeValue;
                                     }
                                     else if (textureType.Equals("normal"))
                                     {
                                         normalPath = realTextureTypeValue;
                                     }
                                     else if (textureType.Equals("emissive"))
                                     {
                                         emissivePath = realTextureTypeValue;
                                     }
                                     else if (textureType.Equals("height"))
                                     {
                                         heightPath = realTextureTypeValue;
                                     }
                                 }
                                 Pipliz.Log.Write(string.Format("Rewriting {0} texture path from '{1}' to '{2}'", textureType, textureTypeValue, realTextureTypeValue));
                             }
                             textureEntry.Value.SetAs(textureType, realTextureTypeValue);
                         }
                         var textureMapping = new ItemTypesServer.TextureMapping(textureEntry.Value);
                         if (albedoPath != null)
                         {
                             textureMapping.AlbedoPath = albedoPath;
                         }
                         if (normalPath != null)
                         {
                             textureMapping.NormalPath = normalPath;
                         }
                         if (emissivePath != null)
                         {
                             textureMapping.EmissivePath = emissivePath;
                         }
                         if (heightPath != null)
                         {
                             textureMapping.HeightPath = heightPath;
                         }
                         string realkey = MOD_PREFIX + packageName + "." + textureEntry.Key;
                         Pipliz.Log.Write(string.Format("Adding texture mapping for '{0}'", realkey));
                         ItemTypesServer.SetTextureMapping(realkey, textureMapping);
                     } catch (Exception exception) {
                         Pipliz.Log.WriteError(string.Format("Exception while loading from {0}; {1}", "texturemapping.json", exception.Message));
                     }
                 }
             }
             else
             {
                 Pipliz.Log.WriteError(string.Format("Expected json object in {0}, but got {1} instead", "texturemapping.json", jsonTextureMapping.NodeType));
             }
         }
     }
 }
 public static void LoadRecipes()
 {
     foreach (string fullDirPath in Directory.GetDirectories(BlocksDirectory))
     {
         string packageName = Path.GetFileName(fullDirPath);
         if (packageName.Equals("examples"))
         {
             continue;
         }
         Pipliz.Log.Write(string.Format("Started loading '{0}' recipes...", packageName));
         try {
             foreach (string[] jobAndFilename in new string[][] {
                 new string[] { "workbench", "crafting.json" },
                 new string[] { "tailorshop", "tailoring.json" },
                 new string[] { "grindstone", "grinding.json" },
                 new string[] { "mint", "minting.json" },
                 new string[] { "shop", "shopping.json" },
                 new string[] { "technologisttable", "technologist.json" },
                 new string[] { "furnace", "smelting.json" },
                 new string[] { "oven", "baking.json" }
             })
             {
                 JSONNode jsonRecipes;
                 if (Pipliz.JSON.JSON.Deserialize(MultiPath.Combine(BlocksDirectory, packageName, jobAndFilename [1]), out jsonRecipes, false))
                 {
                     if (jsonRecipes.NodeType == NodeType.Array)
                     {
                         foreach (JSONNode craftingEntry in jsonRecipes.LoopArray())
                         {
                             foreach (string recipePart in new string[] { "results", "requires" })
                             {
                                 JSONNode jsonRecipeParts = craftingEntry.GetAs <JSONNode> (recipePart);
                                 foreach (JSONNode jsonRecipePart in jsonRecipeParts.LoopArray())
                                 {
                                     string type = jsonRecipePart.GetAs <string> ("type");
                                     string realtype;
                                     if (type.StartsWith(VANILLA_PREFIX))
                                     {
                                         realtype = type.Substring(VANILLA_PREFIX.Length);
                                     }
                                     else
                                     {
                                         realtype = MOD_PREFIX + packageName + "." + type;
                                     }
                                     Pipliz.Log.Write(string.Format("Rewriting block recipe type from '{0}' to '{1}'", type, realtype));
                                     jsonRecipePart.SetAs("type", realtype);
                                 }
                             }
                             Recipe craftingRecipe = new Recipe(craftingEntry);
                             RecipeStorage.AddRecipe(craftingRecipe);
                             RecipeStorage.AddBlockToRecipeMapping(jobAndFilename [0], craftingRecipe.Name);
                             if (jobAndFilename [1].Equals("crafting.json"))
                             {
                                 RecipePlayer.AddDefaultRecipe(craftingRecipe);
                             }
                         }
                     }
                     else
                     {
                         Pipliz.Log.WriteError(string.Format("Expected json array in {0}, but got {1} instead", jobAndFilename [1], jsonRecipes.NodeType));
                     }
                 }
             }
         } catch (Exception exception) {
             Pipliz.Log.WriteError(string.Format("Exception while loading recipes from {0}; {1}", packageName, exception.Message));
         }
     }
 }
 public static void AfterAddingBaseTypes(Dictionary <string, ItemTypesServer.ItemTypeRaw> itemTypes)
 {
     foreach (string fullDirPath in Directory.GetDirectories(BlocksDirectory))
     {
         string packageName = Path.GetFileName(fullDirPath);
         if (packageName.Equals("examples"))
         {
             continue;
         }
         Pipliz.Log.Write(string.Format("Started loading '{0}' types...", packageName));
         JSONNode jsonTypes;
         if (Pipliz.JSON.JSON.Deserialize(MultiPath.Combine(BlocksDirectory, packageName, "types.json"), out jsonTypes, false))
         {
             if (jsonTypes.NodeType == NodeType.Object)
             {
                 foreach (KeyValuePair <string, JSONNode> typeEntry in jsonTypes.LoopObject())
                 {
                     try {
                         string icon;
                         if (typeEntry.Value.TryGetAs("icon", out icon))
                         {
                             string realicon;
                             if (icon.StartsWith(VANILLA_PREFIX))
                             {
                                 realicon = MultiPath.Combine("gamedata", "textures", "icons", icon.Substring(VANILLA_PREFIX.Length));
                             }
                             else
                             {
                                 realicon = MultiPath.Combine(BlocksDirectory, packageName, "icons", icon);
                             }
                             Pipliz.Log.Write(string.Format("Rewriting icon path from '{0}' to '{1}'", icon, realicon));
                             typeEntry.Value.SetAs("icon", realicon);
                         }
                         string mesh;
                         if (typeEntry.Value.TryGetAs("mesh", out mesh))
                         {
                             string realmesh;
                             if (mesh.StartsWith(VANILLA_PREFIX))
                             {
                                 realmesh = mesh.Substring(VANILLA_PREFIX.Length);
                             }
                             else
                             {
                                 realmesh = MultiPath.Combine(BlocksDirectory, packageName, "meshes", mesh);
                             }
                             Pipliz.Log.Write(string.Format("Rewriting mesh path from '{0}' to '{1}'", mesh, realmesh));
                             typeEntry.Value.SetAs("mesh", realmesh);
                         }
                         string parentType;
                         if (typeEntry.Value.TryGetAs("parentType", out parentType))
                         {
                             string realParentType;
                             if (parentType.StartsWith(VANILLA_PREFIX))
                             {
                                 realParentType = parentType.Substring(VANILLA_PREFIX.Length);
                             }
                             else
                             {
                                 realParentType = MOD_PREFIX + packageName + "." + parentType;
                             }
                             Pipliz.Log.Write(string.Format("Rewriting parentType from '{0}' to '{1}'", parentType, realParentType));
                             typeEntry.Value.SetAs("parentType", realParentType);
                         }
                         foreach (string rotatable in new string[] { "rotatablex+", "rotatablex-", "rotatablez+", "rotatablez-" })
                         {
                             string key;
                             if (typeEntry.Value.TryGetAs(rotatable, out key))
                             {
                                 string rotatablekey;
                                 if (key.StartsWith(VANILLA_PREFIX))
                                 {
                                     rotatablekey = key.Substring(VANILLA_PREFIX.Length);
                                 }
                                 else
                                 {
                                     rotatablekey = MOD_PREFIX + packageName + "." + key;
                                 }
                                 Pipliz.Log.Write(string.Format("Rewriting rotatable key '{0}' to '{1}'", key, rotatablekey));
                                 typeEntry.Value.SetAs(rotatable, rotatablekey);
                             }
                         }
                         foreach (string side in new string[] { "sideall", "sidex+", "sidex-", "sidey+", "sidey-", "sidez+", "sidez-" })
                         {
                             string key;
                             if (typeEntry.Value.TryGetAs(side, out key))
                             {
                                 if (!key.Equals("SELF"))
                                 {
                                     string sidekey;
                                     if (key.StartsWith(VANILLA_PREFIX))
                                     {
                                         sidekey = key.Substring(VANILLA_PREFIX.Length);
                                     }
                                     else
                                     {
                                         sidekey = MOD_PREFIX + packageName + "." + key;
                                     }
                                     Pipliz.Log.Write(string.Format("Rewriting side key from '{0}' to '{1}'", key, sidekey));
                                     typeEntry.Value.SetAs(side, sidekey);
                                 }
                             }
                         }
                         string onRemoveType;
                         if (typeEntry.Value.TryGetAs("onRemoveType", out onRemoveType))
                         {
                             string realOnRemoveType;
                             if (onRemoveType.StartsWith(VANILLA_PREFIX))
                             {
                                 realOnRemoveType = onRemoveType.Substring(VANILLA_PREFIX.Length);
                             }
                             else
                             {
                                 realOnRemoveType = MOD_PREFIX + packageName + "." + onRemoveType;
                             }
                             Pipliz.Log.Write(string.Format("Rewriting onRemoveType from '{0}' to '{1}'", onRemoveType, realOnRemoveType));
                             typeEntry.Value.SetAs("onRemoveType", realOnRemoveType);
                         }
                         string onPlaceAudio;
                         if (typeEntry.Value.TryGetAs("onPlaceAudio", out onPlaceAudio))
                         {
                             string realOnPlaceAudio;
                             if (onPlaceAudio.StartsWith(VANILLA_PREFIX))
                             {
                                 realOnPlaceAudio = onPlaceAudio.Substring(VANILLA_PREFIX.Length);
                             }
                             else
                             {
                                 realOnPlaceAudio = MOD_PREFIX + packageName + "." + onPlaceAudio;
                             }
                             Pipliz.Log.Write(string.Format("Rewriting onPlaceAudio from '{0}' to '{1}'", onPlaceAudio, realOnPlaceAudio));
                             typeEntry.Value.SetAs("onPlaceAudio", realOnPlaceAudio);
                         }
                         string onRemoveAudio;
                         if (typeEntry.Value.TryGetAs("onRemoveAudio", out onRemoveAudio))
                         {
                             string realOnRemoveAudio;
                             if (onRemoveAudio.StartsWith(VANILLA_PREFIX))
                             {
                                 realOnRemoveAudio = onRemoveAudio.Substring(VANILLA_PREFIX.Length);
                             }
                             else
                             {
                                 realOnRemoveAudio = MOD_PREFIX + packageName + "." + onRemoveAudio;
                             }
                             Pipliz.Log.Write(string.Format("Rewriting onRemoveAudio from '{0}' to '{1}'", onRemoveAudio, realOnRemoveAudio));
                             typeEntry.Value.SetAs("onRemoveAudio", realOnRemoveAudio);
                         }
                         string realkey = MOD_PREFIX + packageName + "." + typeEntry.Key;
                         bool   isCrate;
                         if (typeEntry.Value.TryGetAs("isCrate", out isCrate) && isCrate)
                         {
                             Pipliz.Log.Write(string.Format("Adding crate type '{0}'", realkey));
                             crateTypeKeys.Add(realkey);
                         }
                         else
                         {
                             Pipliz.Log.Write(string.Format("Adding block type '{0}'", realkey));
                         }
                         itemTypes.Add(realkey, new ItemTypesServer.ItemTypeRaw(realkey, typeEntry.Value));
                     } catch (Exception exception) {
                         Pipliz.Log.WriteException(exception);
                         Pipliz.Log.WriteError(string.Format("Exception while loading block type {0}; {1}", typeEntry.Key, exception.Message));
                     }
                 }
             }
             else
             {
                 Pipliz.Log.WriteError(string.Format("Expected json object in {0}, but got {1} instead", "types.json", jsonTypes.NodeType));
             }
         }
     }
 }