Ejemplo n.º 1
0
 protected void Application_Start()
 {
     GlobalConfiguration.Configure(WebApiConfig.Configure); //registers WebApi routes
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);         //register MVC routes
     BackgroundConfig.Configure();
     BundleConfig.RegisterBundles(BundleTable.Bundles);
 }
Ejemplo n.º 2
0
 /*Assign colors to background. The material has to be assigned to the background, otherwise it won't work*/
 private void CreateBackground(Material Mat, BackgroundConfig b)
 {
     Mat.SetColor("_SkyColor1", b.TopColor);
     Mat.SetFloat("_SkyExponent1", b.TopExponent);
     Mat.SetColor("_SkyColor2", b.HorizonColor);
     Mat.SetColor("_SkyColor3", b.BottomColor);
     Mat.SetFloat("_SkyExponent2", b.BottomExponent);
     Mat.SetFloat("_SkyIntensity", b.SkyIntensity);
 }
    public void loadJSON()
    {
        config = null;
        menu.DirectoryCheck();

        //ファイルがない場合: 初期設定ファイルの生成
        if (!File.Exists(jsonPath))
        {
            config = new BackgroundConfig();
            makeJSON();
        }

        //ファイルの読込を試行
        try
        {
            //ファイルの内容を一括読み出し
            string jsonString = File.ReadAllText(jsonPath, new UTF8Encoding(false));
            //設定クラスをJSONデコードして生成
            config = JsonUtility.FromJson <BackgroundConfig>(jsonString);

            //ファイルのバージョンが古い場合は、デフォルト設定にして警告(nullの可能性も考慮してtry内)
            if (config.jsonVer != jsonVerMaster)
            {
                menu.ShowDialogOKCancel(LanguageManager.config.jsonloaders.OLD_CONFIG_HEAD, "" + jsonPath + LanguageManager.config.jsonloaders.OLD_CONFIG_BODY, 3f, () => {
                    //OK
                    makeJSON();
                }, () => {
                    //キャンセル
                });
                config = new BackgroundConfig();
            }
        }
        catch (System.Exception e)
        {
            //JSONデコードに失敗した場合
            Debug.Log(e.ToString());
            config = null;
        }

        //デコード失敗した場合は、デフォルト設定にして警告
        if (config == null)
        {
            config = new BackgroundConfig();
            menu.ShowDialogOKCancel(LanguageManager.config.jsonloaders.CORRUPT_CONFIG_HEAD, "" + jsonPath + LanguageManager.config.jsonloaders.CORRUPT_CONFIG_BODY, 3f, () => {
                //OK
                makeJSON();
            }, () => {
                //キャンセル
            });
        }
    }
Ejemplo n.º 4
0
        private void GenerateChrImageAndSaveFiles(BackgroundConfig config, List <MyBitmap> sprites)
        {
            // Find the empty tile, move it to the end, update the config
            int emptyTileIndex = -1;

            for (var i = 0; i < sprites.Count; i++)
            {
                if (sprites[i].IsNesColor(0))
                {
                    emptyTileIndex = i;
                }
            }

            if (emptyTileIndex == -1)
            {
                throw new Exception("Empty tile not found for some reason");
            }

            // Move empty tile to the beginning.
            var emptyTile = sprites[emptyTileIndex];

            sprites.RemoveAt(emptyTileIndex);
            var newEmptyTileIndex = 0;

            sprites.Insert(0, emptyTile);

            // Update the config.
            foreach (var tile in config.Tiles)
            {
                var newSprites = new int[4];
                Array.Copy(tile.Sprites, newSprites, 4);
                for (var i = 0; i < 4; i++)
                {
                    if (newSprites[i] == emptyTileIndex)
                    {
                        newSprites[i] = newEmptyTileIndex;
                    }
                    else if (newSprites[i] < emptyTileIndex)
                    {
                        newSprites[i] = newSprites[i] + 1;
                    }
                }

                tile.Sprites = newSprites;
            }

            // Generate chr image
            var chrImage = new MyBitmap(Constants.SpriteWidth * Constants.ChrFileSpritesPerRow, Constants.SpriteHeight * Constants.ChrFileRows, Color.Black);
            {
                var x = 0;
                var y = 0;

                foreach (var sprite in sprites)
                {
                    chrImage.DrawImage(sprite, x, y);
                    x += 8;
                    if (x >= Constants.SpriteWidth * Constants.ChrFileSpritesPerRow)
                    {
                        x  = 0;
                        y += 8;
                    }
                }
            }

            // Generate actual chr file
            // CHR format:
            //  each sprite is 16 bytes:
            //  first 8 bytes are low bits per sprite row
            //  second 8 bytes are high bits per sprite row
            var bytes = new List <byte>();

            foreach (var sprite in sprites)
            {
                var lowBits  = new List <byte>();
                var highBits = new List <byte>();

                for (var y = 0; y < Constants.SpriteHeight; y++)
                {
                    byte lowBit  = 0;
                    byte highBit = 0;

                    for (var x = 0; x < Constants.SpriteWidth; x++)
                    {
                        lowBit  = (byte)(lowBit << 1);
                        highBit = (byte)(highBit << 1);

                        var pixel = sprite.GetNesPixel(x, y);

                        if (pixel == 1 || pixel == 3)
                        {
                            // low bit set
                            lowBit |= 1;
                        }

                        if (pixel == 2 || pixel == 3)
                        {
                            // high bit set
                            highBit |= 1;
                        }
                    }

                    lowBits.Add(lowBit);
                    highBits.Add(highBit);
                }

                bytes.AddRange(lowBits);
                bytes.AddRange(highBits);
            }

            while (bytes.Count < 4096)
            {
                bytes.Add(0);
            }

            // Save everything
            chrImage.ToBitmap().Save(outputImageTextBox.Text);

            config.Write(outputSpecTextBox.Text);

            if (File.Exists(outputChrTextBox.Text))
            {
                File.Delete(outputChrTextBox.Text);
            }

            File.WriteAllBytes(outputChrTextBox.Text, bytes.ToArray());
        }
Ejemplo n.º 5
0
        private void GetConfigAndSprites(
            string nonBlockingFile,
            string blockingFile,
            string threatFile,
            bool handleEmptyTile,
            out BackgroundConfig configRes,
            out List <MyBitmap> spritesRes,
            out Dictionary <string, MyBitmap> tilesWithImagesRes)
        {
            // Create config with file names.
            var config = new BackgroundConfig
            {
                NonBlockingFile = nonBlockingFile,
                BlockingFile    = blockingFile,
                ThreatFile      = threatFile
            };

            // Get all files. Handle some not existing.
            var nonBlocking = File.Exists(nonBlockingFile) ? MyBitmap.FromFile(config.NonBlockingFile) : null;
            var blocking    = File.Exists(blockingFile) ? MyBitmap.FromFile(config.BlockingFile) : null;
            var threat      = File.Exists(threatFile) ? MyBitmap.FromFile(config.ThreatFile) : null;

            // Get all tiles and sprites
            var allTiles        = new List <MyBitmap>();
            var tiles           = new List <Tile>();
            var sprites         = new List <MyBitmap>();
            var tilesWithImages = new Dictionary <string, MyBitmap>();

            // Processing function
            Tile emptyTile = null;
            Action <MyBitmap, TileType> processList = (bitmap, tileType) =>
            {
                bitmap.MakeNesGreyscale();

                for (var x = 0; x < bitmap.Width; x += Constants.BackgroundTileWidth)
                {
                    for (var y = 0; y < bitmap.Height; y += Constants.BackgroundTileHeight)
                    {
                        var newTile     = bitmap.GetPart(x, y, Constants.BackgroundTileWidth, Constants.BackgroundTileHeight);
                        var isEmptyTile = newTile.IsNesColor(0);
                        if (allTiles.Any(tile => tile.Equals(newTile)))
                        {
                            if (!isEmptyTile)
                            {
                                throw new Exception(string.Format("Tile {0}/{1} in file {2} is repeated somewhere", x, y, bitmap.FileName));
                            }

                            continue;
                        }

                        if (isEmptyTile && tileType != TileType.NonBlocking)
                        {
                            throw new Exception("Empty tile found first in file other than non-blocking");
                        }

                        var tileConfig = new Tile
                        {
                            Type = tileType,
                            X    = x / Constants.BackgroundTileWidth,
                            Y    = y / Constants.BackgroundTileHeight
                        };

                        if (isEmptyTile)
                        {
                            emptyTile = tileConfig;
                        }

                        tileConfig.Sprites = new int[4];

                        var spritesInTile = new MyBitmap[]
                        {
                            newTile.GetPart(0, 0, Constants.SpriteWidth, Constants.SpriteHeight),
                            newTile.GetPart(0, Constants.SpriteHeight, Constants.SpriteWidth, Constants.SpriteHeight),
                            newTile.GetPart(Constants.SpriteWidth, 0, Constants.SpriteWidth, Constants.SpriteHeight),
                            newTile.GetPart(Constants.SpriteWidth, Constants.SpriteHeight, Constants.SpriteWidth, Constants.SpriteHeight),
                        };

                        for (var i = 0; i < spritesInTile.Length; i++)
                        {
                            var sprite         = spritesInTile[i];
                            var indexOfSprite  = -1;
                            var spriteFromList = sprites.FirstOrDefault(s => s.Equals(sprite));

                            if (spriteFromList != null)
                            {
                                indexOfSprite = sprites.IndexOf(spriteFromList);
                            }
                            else
                            {
                                sprites.Add(sprite);
                                indexOfSprite = sprites.Count - 1;
                            }

                            tileConfig.Sprites[i] = indexOfSprite;
                        }

                        tiles.Add(tileConfig);
                        allTiles.Add(newTile);

                        tilesWithImages.Add(tileConfig.Id, newTile);
                    }
                }
            };

            // Process all tiles (non blocking first)
            if (nonBlocking != null)
            {
                processList(nonBlocking, TileType.NonBlocking);
            }

            if (blocking != null)
            {
                processList(blocking, TileType.Blocking);
            }

            if (threat != null)
            {
                processList(threat, TileType.Threat);
            }

            // Move empty tile to the 1st place
            if (handleEmptyTile)
            {
                if (emptyTile == null)
                {
                    throw new Exception("Empty tile not found");
                }

                tiles.Remove(emptyTile);
                tiles.Insert(0, emptyTile);
            }

            // Set tiles in the config
            config.Tiles = tiles.ToArray();

            // Set results.
            configRes          = config;
            spritesRes         = sprites;
            tilesWithImagesRes = tilesWithImages;
        }