Example #1
0
 public void SaveProject(Project project, string basePath)
 {
     try
     {
         File.WriteAllText(string.Format(@"{0}\{1}.json", basePath, project.Name), JsonConvert.SerializeObject(project, Newtonsoft.Json.Formatting.Indented));
     }
     catch (Exception e)
     {
         _errorService.LogError(e);
     }
 }
Example #2
0
 public World LoadWorld(WorldInfo worldInfo)
 {
     try
     {
         string fileName = _project.DirectoryPath + @"\worlds\" + worldInfo.Name + ".json";
         return(JsonConvert.DeserializeObject <World>(File.ReadAllText(fileName)));
     }
     catch (Exception e)
     {
         _errorService.LogError(e);
         return(null);
     }
 }
Example #3
0
        public Level LoadLevel(LevelInfo levelInfo)
        {
            try
            {
                string safeFileName = levelInfo.Name.Replace("!", "").Replace("?", "");

                string fileName = _project.DirectoryPath + @"\levels\" + safeFileName + ".json";
                return(JsonConvert.DeserializeObject <Level>(File.ReadAllText(fileName)));
            }
            catch (Exception e)
            {
                _errorService.LogError(e);
                return(null);
            }
        }
Example #4
0
        private int CompileLevels()
        {
            string region = "";

            try
            {
                _levelIndexTable.Clear();
                _levelTypeTable.Clear();
                _levelAddressTable.Clear();

                byte levelIndex = 0;
                foreach (LevelInfo levelInfo in _levelService.AllLevels())
                {
                    _levelIndexTable.Add(levelInfo.Id, levelIndex++);
                }

                levelIndex = 0;

                foreach (LevelInfo levelInfo in _levelService.AllLevels())
                {
                    region = "Loading level " + levelInfo.Name;

                    Level level = _levelService.LoadLevel(levelInfo);

                    _levelTypeTable[levelIndex++] = level.TileSetIndex;

                    if (level != null)
                    {
                        _levelAddressTable.Add(_levelIndexTable[level.Id], _dataPointer);

                        _dataPointer   = WriteLevel(level, _dataPointer);
                        levelInfo.Size = level.CompressedData.Length;
                        if (_dataPointer >= 0xFC000)
                        {
                            return(-1);
                        }
                    }
                    else
                    {
                        _errorService.LogError("Unable to load level " + levelInfo.Name);
                    }
                }

                int bank, address, lastLevelPointer = _dataPointer;

                foreach (var index in _levelAddressTable.Keys)
                {
                    region = "Updating level pointer table.";

                    _dataPointer = _levelAddressTable[index];
                    bank         = (byte)((_dataPointer - 0x10) / 0x2000);
                    address      = (_dataPointer - 0x10 - (bank * 0x2000) + 0xA000);
                    _rom[0xDC10 + (index * 4)] = (byte)bank;
                    _rom[0xDC11 + (index * 4)] = (byte)(address & 0x00FF);
                    _rom[0xDC12 + (index * 4)] = (byte)((address & 0xFF00) >> 8);
                    _rom[0xDC13 + (index * 4)] = (byte)_levelTypeTable[index];
                }

                return(lastLevelPointer);
            }
            catch (Exception e)
            {
                _errorService.LogError(e, string.Format("Error occurred in writing level data data. Region: {0}\n Address: {1}", region, _dataPointer));
            }

            return(-1);
        }
Example #5
0
        public List <TileSet> ConvertLegacy(string fileName)
        {
            try
            {
                var data     = File.ReadAllBytes(fileName);
                var tileSets = new List <TileSet>();

                for (int i = 0; i < 16; i++)
                {
                    int bankOffset = i * 0x400;
                    var tileSet    = new TileSet();

                    for (int j = 0; j < 256; j++)
                    {
                        TileBlock tile = new TileBlock();

                        tile.UpperLeft  = data[bankOffset + j];
                        tile.LowerLeft  = data[bankOffset + 0x100 + j];
                        tile.UpperRight = data[bankOffset + 0x200 + j];
                        tile.LowerRight = data[bankOffset + 0x300 + j];

                        tileSet.TileBlocks[j] = tile;
                    }

                    tileSets.Add(tileSet);
                }

                var propertyOffset = 0x4000;
                for (int i = 0; i < 16; i++)
                {
                    for (int j = 0; j < 256; j++)
                    {
                        tileSets[i].TileBlocks[j].Property = data[propertyOffset++];
                    }
                }

                for (int i = 0; i < 16; i++)
                {
                    for (int k = 0; k < 8; k++)
                    {
                        tileSets[i].FireBallInteractions.Add(data[propertyOffset++]);
                    }

                    for (int k = 0; k < 8; k++)
                    {
                        tileSets[i].IceBallInteractions.Add(data[propertyOffset++]);
                    }

                    for (int k = 0; k < 8; k++)
                    {
                        tileSets[i].PSwitchAlterations.Add(new PSwitchAlteration(data[propertyOffset++], data[propertyOffset++]));
                    }
                }

                return(tileSets);
            }
            catch (Exception e)
            {
                _errorService.LogError(e);
                return(null);
            }
        }