public void Load(SLData sonicLevel) { Loading = true; Status = "Decoding"; Status = "Determining Level Information"; SonicLevel = new SonicLevel(); for (var n = 0; n < sonicLevel.Rings.Length; n++) { SonicLevel.Rings[n] = new Ring(true); SonicLevel.Rings[n].X = sonicLevel.Rings[n].X; SonicLevel.Rings[n].Y = sonicLevel.Rings[n].Y; } SonicLevel.LevelWidth = sonicLevel.ForegroundWidth; SonicLevel.LevelHeight = sonicLevel.ForegroundHeight; SonicLevel.ChunkMap = sonicLevel.Foreground; SonicLevel.BGChunkMap = sonicLevel.Background; for (int l = 0; l < sonicLevel.Objects.Length; l++) { SonicLevel.Objects[l] = new LevelObjectInfo(sonicLevel.Objects[l]); SonicLevel.Objects[l].Index = l; } var objectKeys = new List<string>(); foreach (LevelObjectInfo t in SonicLevel.Objects) { var o = t.Key; if (objectKeys.All(p => p != o)) objectKeys.Add(o); } loadObjects(objectKeys); for (int j = 0; j < sonicLevel.Tiles.Length; j++) { var fc = sonicLevel.Tiles[j]; var tiles = fc; List<int> mj = new List<int>(); for (int i = 0; i < tiles.Length; i++) { var value = sonicLevel.Tiles[j][i]; mj.Add((value >> 4)); mj.Add((value & 0xF)); } var mfc = new int[8][]; for (int o = 0; o < 8; o++) { mfc[o] = new int[8]; } for (int n = 0; n < mj.Count; n++) { mfc[n % 8][n / 8] = mj[n]; } SonicLevel.Tiles[j] = new Tile(mfc); SonicLevel.Tiles[j].Index = j; } var acs = SonicLevel.AnimatedChunks = new List<TileChunk>(); if (sonicLevel.AnimatedFiles.Truthy()) { SonicLevel.AnimatedTileFiles = new Tile[sonicLevel.AnimatedFiles.Length][]; for (var animatedFileIndex = 0; animatedFileIndex < sonicLevel.AnimatedFiles.Length; animatedFileIndex++) { var animatedFile = sonicLevel.AnimatedFiles[animatedFileIndex]; SonicLevel.AnimatedTileFiles[animatedFileIndex] = new Tile[animatedFile.Length]; for (int filePiece = 0; filePiece < animatedFile.Length; filePiece++) { var c = animatedFile[filePiece]; var tiles = c; List<int> mjc = new List<int>(); for (int l = 0; l < tiles.Length; l++) { var value = animatedFile[filePiece][l]; mjc.Add((value >> 4)); mjc.Add((value & 0xF)); } var mfc = new int[8][]; for (int o = 0; o < 8; o++) { mfc[o] = new int[8]; } for (int n = 0; n < mjc.Count; n++) { mfc[n % 8][n / 8] = mjc[n]; } Tile tile = new Tile(mfc); tile.IsTileAnimated = true; tile.Index = filePiece * 10000 + animatedFileIndex; SonicLevel.AnimatedTileFiles[animatedFileIndex][filePiece] = tile; } } } for (int j = 0; j < sonicLevel.Blocks.Length; j++) { var fc = sonicLevel.Blocks[j]; var mj = new TilePiece(); mj.Index = j; mj.Tiles = new List<TileInfo>(); for (int p = 0; p < fc.Length; p++) { mj.Tiles.Add(new TileInfo() { _Tile = fc[p].Tile, Index = p, Palette = fc[p].Palette, Priority = fc[p].Priority, XFlip = fc[p].XFlip, YFlip = fc[p].YFlip, }); } mj.Init(); SonicLevel.TilePieces[j] = mj; } SonicLevel.Angles = sonicLevel.Angles; SonicLevel.TileAnimations = new List<TileAnimationData>( sonicLevel.Animations.Map( a => new TileAnimationData() { AnimationTileFile = a.AnimationFile, AnimationTileIndex = a.AnimationTileIndex, AutomatedTiming = a.AutomatedTiming, NumberOfTiles = a.NumberOfTiles, DataFrames = (TileAnimationDataFrame[]) a.Frames.Map( b => new TileAnimationDataFrame() { Ticks = b.Ticks, StartingTileIndex = b.StartingTileIndex }).Slice(0) })); SonicLevel.CollisionIndexes1 = sonicLevel.CollisionIndexes1; SonicLevel.CollisionIndexes2 = sonicLevel.CollisionIndexes2; for (int i = 0; i < sonicLevel.HeightMaps.Length; i++) { var b1 = true; var b2 = true; for (int m = 0; m < sonicLevel.HeightMaps[i].Length; m++) { if (b1 && sonicLevel.HeightMaps[i][m] != 0) b1 = false; if (b2 && sonicLevel.HeightMaps[i][m] != 16) b2 = false; } if (b1) SonicLevel.HeightMaps[i] = new HeightMap(false); else if (b2) SonicLevel.HeightMaps[i] = new HeightMap(true); else SonicLevel.HeightMaps[i] = new HeightMap(sonicLevel.HeightMaps[i], i); } for (int j = 0; j < sonicLevel.Chunks.Length; j++) { var fc = sonicLevel.Chunks[j]; var mj = new TileChunk(); mj.Index = j; mj.TilePieces = new TilePieceInfo[8][]; for (int i = 0; i < 8; i++) { mj.TilePieces[i] = new TilePieceInfo[8]; } for (int p = 0; p < fc.Length; p++) { mj.TilePieces[p % 8][p / 8] = new TilePieceInfo() { Index = p, Block = fc[p].Block, Solid1 = fc[p].Solid1, Solid2 = fc[p].Solid2, XFlip = fc[p].XFlip, YFlip = fc[p].YFlip }; } SonicLevel.TileChunks[j] = mj; mj.TileAnimations = new JsDictionary<int, TileAnimationData>(); for (int tpX = 0; tpX < mj.TilePieces.Length; tpX++) { for (int tpY = 0; tpY < mj.TilePieces[tpX].Length; tpY++) { var pm = mj.TilePieces[tpX][tpY].GetTilePiece(); if (pm != null) { foreach (var mjc in pm.Tiles) { var fa = containsAnimatedTile(mjc._Tile, SonicLevel); if (fa.Truthy()) { mj.TileAnimations[tpY * 8 + tpX] = fa; acs[j] = mj; } } } } } } SonicLevel.Palette = sonicLevel.Palette.Map(a => a.Map(b => "#"+b)); SonicLevel.StartPositions = sonicLevel.StartPositions.Map(a => new Point(a.X, a.Y)).Array(); SonicLevel.AnimatedPalettes = new List<PaletteItem>(); if (sonicLevel.PaletteItems.Length > 0) { for (int k = 0; k < sonicLevel.PaletteItems[0].Length; k++) { AnimatedPaletteItem pal = sonicLevel.PaletteItems[0][k]; SonicLevel.AnimatedPalettes.Add(new PaletteItem() { Palette = ((string[])Script.Eval(pal.Palette)).Map(b => "#" + b), SkipIndex = pal.SkipIndex, TotalLength = pal.TotalLength, Pieces = pal.Pieces.Map(a => new PaletteItemPieces() { PaletteIndex = a.PaletteIndex, PaletteMultiply = a.PaletteMultiply, PaletteOffset = a.PaletteOffset }) }); } } foreach (var tilePiece in SonicLevel.TilePieces) { tilePiece.AnimatedPaletteIndexes = new List<int>(); tilePiece.AnimatedTileIndexes = new List<int>(); if (SonicLevel.AnimatedPalettes.Count > 0) { foreach (var mj in tilePiece.Tiles) { Tile tile = mj.GetTile(); if (tile.Truthy()) { tile.AnimatedPaletteIndexes = new List<int>(); var pl = tile.GetAllPaletteIndexes(); tile.PaletteIndexesToBeAnimated = new JsDictionary<int, List<int>>(); tile.AnimatedTileIndexes = new List<int>(); for (int tileAnimationIndex = 0; tileAnimationIndex < SonicLevel.TileAnimations.Count; tileAnimationIndex++) { var tileAnimationData = SonicLevel.TileAnimations[tileAnimationIndex]; var anin = tileAnimationData.AnimationTileIndex; var num = tileAnimationData.NumberOfTiles; if (tile.Index >= anin && tile.Index < anin + num) { tilePiece.AnimatedTileIndexes.Add(tileAnimationIndex); tile.AnimatedTileIndexes.Add(tileAnimationIndex); } } for (int animatedPaletteIndex = 0; animatedPaletteIndex < SonicLevel.AnimatedPalettes.Count; animatedPaletteIndex++) { var pal = SonicLevel.AnimatedPalettes[animatedPaletteIndex]; tile.PaletteIndexesToBeAnimated[animatedPaletteIndex] = new List<int>(); foreach (var mjce in pal.Pieces) { PaletteItemPieces mje1 = mjce; if (mj.Palette == mje1.PaletteIndex) { if (pl.Any(j => j == mje1.PaletteOffset / 2 || j == mje1.PaletteOffset / 2 + 1)) { tilePiece.AnimatedPaletteIndexes.Add(animatedPaletteIndex); tile.AnimatedPaletteIndexes.Add(animatedPaletteIndex); foreach (var pIndex in pl) { if (pIndex == mje1.PaletteOffset / 2 || pIndex == mje1.PaletteOffset / 2 + 1) { tile.PaletteIndexesToBeAnimated[animatedPaletteIndex].Add(pIndex); } } } } } } } } } } var finished = new Action(() => { Loading = false; }); PreloadSprites(() => { finished(); ForceResize(); }, (s) => { }); ForceResize(); OnLevelLoad(SonicLevel); /* var finished = function () { sonicManager.uiManager.levelManagerArea.visible = true; sonicManager.loading = false; sonicManager.uiManager.modifyTC.tileChunk = sonicManager.SonicLevel.TileChunks[0]; sonicManager.uiManager.modifyTilePieceArea.tilePiece = sonicManager.uiManager.modifyTP.tilePiece = sonicManager.SonicLevel.TilePieces[0]; }; // var inds = sonicManager.inds = { r:0,t: 0, tp: 0, tc: 0, total: (sonicManager.SonicLevel.TileChunks.length * 2 + sonicManager.SonicLevel.TilePieces.length * 5 + sonicManager.SonicLevel.Tiles.length), done: false }; sonicManager.CACHING = true; sonicManager.preLoadSprites(scale, function () { // inds.r = 1; sonicManager.CACHING = false; finished(); sonicManager.uiManager.updateTitle("Level Loaded"); sonicManager.forceResize(); var dl = _H.getQueryString(); if (dl["run"]) { setTimeout(sonicManager.uiManager.runSonic, 1000); } }, sonicManager.uiManager.updateTitle); */ }
public void RunSonic(SLData level) { sonicManager.ClearCache(); sonicManager.Load(level); sonicManager.WindowLocation.X = 0; sonicManager.WindowLocation.Y = 0; sonicManager.BigWindowLocation.X = (int) ( sonicManager.WindowLocation.X - sonicManager.WindowLocation.Width * 0.2 ); sonicManager.BigWindowLocation.Y = (int) ( sonicManager.WindowLocation.Y - sonicManager.WindowLocation.Height * 0.2 ); sonicManager.BigWindowLocation.Width = (int) ( sonicManager.WindowLocation.Width * 1.8 ); sonicManager.BigWindowLocation.Height = (int) ( sonicManager.WindowLocation.Height * 1.8 ); var dl = Help.GetQueryString(); if (dl.ContainsKey("run")) { if (sonicManager.CurrentGameState == GameState.Playing) runGame(); runGame(); } sonicManager.CacheTiles(); }