Esempio n. 1
0
        internal static void CreateTile(Tile baseTile, Dictionary <Color, Color> replaceColorsWith, string newVariantTileCode, DirectoryManager directory, Blob overrides)
        {
            if (GameContext.TileDatabase.AllMaterials().Any(x =>
                                                            string.Equals(x.Code, newVariantTileCode, StringComparison.CurrentCultureIgnoreCase)))
            {
                return;
            }

            var file = Regex.Replace(baseTile.Configuration.Source, @"\/|\\", Path.DirectorySeparatorChar.ToString());

            var stream = GameContext.ContentLoader.ReadStream(file).ReadAllText();

            var blob = BlobAllocator.AcquireAllocator().NewBlob(false);

            blob.ReadJson(stream);

            var voxelFile = Regex.Replace(blob.GetString("voxels"), @"\/|\\", Path.DirectorySeparatorChar.ToString());

            var output = ChangeColor(voxelFile, replaceColorsWith);

            directory.WriteQBFile(newVariantTileCode, output);

            blob.SetString("code", newVariantTileCode);
            blob.SetString("voxels", directory.GetPath('/') + newVariantTileCode + ".qb");

            blob.MergeFrom(overrides);

            var wait = true;

            directory.WriteFile(newVariantTileCode + ".tile", blob, () => { wait = false; }, true);

            while (wait)
            {
            }
        }
Esempio n. 2
0
        internal static void CreateItem(Dictionary <Color, Color> replaceColorsWith, string kind, string newVariantTileCode, string source, DirectoryManager directory, Blob overrides)
        {
            if (!File.Exists(Path.GetFullPath(Path.Combine(GameContext.ContentLoader.RootDirectory, source))))
            {
                return;
            }

            if (GameContext.ItemDatabase.GetConfigsByKind(kind).Any(x =>
                                                                    string.Equals(x.Value.Code, newVariantTileCode, StringComparison.CurrentCultureIgnoreCase)))
            {
                return;
            }

            var file = Regex.Replace(source, @"\/|\\", Path.DirectorySeparatorChar.ToString());

            var stream = GameContext.ContentLoader.ReadStream(file).ReadAllText();

            var blob = BlobAllocator.AcquireAllocator().NewBlob(false);

            blob.ReadJson(stream);

            var voxelIconFile   = Regex.Replace(blob.GetString("icon"), @"\/|\\", Path.DirectorySeparatorChar.ToString());
            var voxelInHandFile =
                Regex.Replace(blob.GetString("inHand"), @"\/|\\", Path.DirectorySeparatorChar.ToString());

            var iconOutput   = ChangeColor(voxelIconFile, replaceColorsWith);
            var inHandOutput = ChangeColor(voxelInHandFile, replaceColorsWith);

            directory.WriteQBFile(newVariantTileCode + ".icon", iconOutput);
            directory.WriteQBFile(newVariantTileCode + ".inHand", inHandOutput);

            blob.SetString("code", newVariantTileCode);
            blob.SetString("icon", directory.GetPath('/') + newVariantTileCode + ".icon.qb");
            blob.SetString("inHand", directory.GetPath('/') + newVariantTileCode + ".inHand.qb");

            blob.MergeFrom(overrides);

            var wait = true;

            directory.WriteFile(newVariantTileCode + ".item", blob, () => { wait = false; }, true);

            while (wait)
            {
            }
        }