示例#1
0
        public void ConvertPalettes()
        {
            ProjectService  projectService  = new ProjectService(new ErrorService());
            Project         project         = projectService.LoadProject(@"C:\Projects\Mario Adventure 3\Mushroom Mayhem\Mushroom Mayhem.json");
            LevelService    levelService    = new LevelService(new ErrorService(), project);
            WorldService    worldService    = new WorldService(new ErrorService(), project);
            PalettesService palettesService = new PalettesService(new ErrorService(), project);
            var             palettes        = palettesService.GetPalettes();

            foreach (IInfo info in levelService.AllWorldsLevels())
            {
                if (info.InfoType == InfoType.Level)
                {
                    LevelInfo levelInfo = info as LevelInfo;
                    Level     level     = levelService.LoadLevel(levelInfo);
                    Palette   palette   = palettes.Where(p => p.Id == level.PaletteId).FirstOrDefault();
                    if (!palette.Renamed)
                    {
                        palette.Name    = level.Name;
                        palette.Renamed = true;
                        palettesService.CommitPalette(palette);
                    }
                }

                if (info.InfoType == InfoType.World)
                {
                    WorldInfo worldInfo = info as WorldInfo;
                    World     world     = worldService.LoadWorld(worldInfo);
                    Palette   palette   = palettes.Where(p => p.Id == world.PaletteId).FirstOrDefault();
                    if (!palette.Renamed)
                    {
                        palette.Name    = world.Name;
                        palette.Renamed = true;
                        palettesService.CommitPalette(palette);
                    }
                }
            }

            projectService.SaveProject();
        }
示例#2
0
        private void LevelList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            _ignoreChanges = true;
            if (LevelList.SelectedItem is LevelInfo)
            {
                PSwitchSection.IsEnabled      = IceballSection.IsEnabled = FireballSection.IsEnabled = true;
                TileDefinitions.Visibility    = LevelTileSection.Visibility = Visibility.Visible;
                MapTileDefinitions.Visibility = MapTileSection.Visibility = Visibility.Collapsed;

                LevelInfo levelInfo = (LevelInfo)LevelList.SelectedItem;
                _currentLevel = _levelService.LoadLevel(levelInfo);
                _currentWorld = null;

                Tile[]  staticTiles   = _graphicsService.GetTileSection(_currentLevel.StaticTileTableIndex);
                Tile[]  animatedTiles = _graphicsService.GetTileSection(_currentLevel.AnimationTileTableIndex);
                Palette palette       = _palettesService.GetPalette(_currentLevel.PaletteId);

                _graphicsAccessor.SetBottomTable(animatedTiles);
                _graphicsAccessor.SetTopTable(staticTiles);

                _localTileSet = JsonConvert.DeserializeObject <TileSet>(JsonConvert.SerializeObject(_tileService.GetTileSet(_currentLevel.TileSetIndex)));

                _ignoreChanges = false;
                _graphicsSetRenderer.Update(palette);
                BlockSelector.Update(tileSet: _localTileSet, palette: palette, withProjectileInteractions: false);
                UpdateGraphics();
                UpdateTileBlock();
                LoadInteractions();
            }
            else if (LevelList.SelectedItem is WorldInfo)
            {
                PSwitchSection.IsEnabled      = IceballSection.IsEnabled = FireballSection.IsEnabled = false;
                TileDefinitions.Visibility    = LevelTileSection.Visibility = Visibility.Collapsed;
                MapTileDefinitions.Visibility = MapTileSection.Visibility = Visibility.Visible;

                if (MapInteractionList.SelectedIndex == -1)
                {
                    MapInteractionList.SelectedIndex = 0;
                }

                WorldInfo worldInfo = (WorldInfo)LevelList.SelectedItem;
                _currentWorld = _worldService.LoadWorld(worldInfo);
                _currentLevel = null;

                Tile[]  staticTiles   = _graphicsService.GetTileSection(_currentWorld.TileTableIndex);
                Tile[]  animatedTiles = _graphicsService.GetTileSection(_currentWorld.AnimationTileTableIndex);
                Palette palette       = _palettesService.GetPalette(_currentWorld.PaletteId);

                _graphicsAccessor.SetBottomTable(staticTiles);
                _graphicsAccessor.SetTopTable(animatedTiles);

                _localTileSet = JsonConvert.DeserializeObject <TileSet>(JsonConvert.SerializeObject(_tileService.GetTileSet(0)));
                _graphicsSetRenderer.Update(palette);

                _ignoreChanges = false;

                _graphicsSetRenderer.Update(palette);
                BlockSelector.Update(tileSet: _localTileSet, palette: palette, withProjectileInteractions: false);
                UpdateGraphics();
                UpdateTileBlock();
            }
        }
示例#3
0
        public WorldPanel(GraphicsService graphicsService, PalettesService palettesService, TextService textService, TileService tileService, WorldService worldService, LevelService levelService, GameObjectService gameObjectService, WorldInfo worldInfo)
        {
            InitializeComponent();

            _worldInfo         = worldInfo;
            _textService       = textService;
            _graphicsService   = graphicsService;
            _tileService       = tileService;
            _palettesService   = palettesService;
            _worldService      = worldService;
            _gameObjectService = gameObjectService;

            _historyService     = new HistoryService();
            _interactions       = _tileService.GetMapTileInteractions();
            _world              = _worldService.LoadWorld(_worldInfo);
            _compressionService = new CompressionService();
            Tile[] bottomTableSet = _graphicsService.GetTileSection(_world.TileTableIndex);
            Tile[] topTableSet    = _graphicsService.GetTileSection(_world.AnimationTileTableIndex);
            _graphicsAccessor  = new GraphicsAccessor(topTableSet, bottomTableSet, _graphicsService.GetGlobalTiles(), _graphicsService.GetExtraTiles());
            _worldDataAccessor = new WorldDataAccessor(_world);

            _bitmap        = new WriteableBitmap(WorldRenderer.BITMAP_WIDTH, WorldRenderer.BITMAP_HEIGHT, 96, 96, PixelFormats.Bgra32, null);
            _worldRenderer = new WorldRenderer(_graphicsAccessor, _worldDataAccessor, _palettesService, _tileService.GetMapTileInteractions());
            _worldRenderer.Initializing();

            _tileSet = _tileService.GetTileSet(_world.TileSetIndex);

            Palette palette = _palettesService.GetPalette(_world.PaletteId);

            _worldRenderer.Update(tileSet: _tileSet, palette: palette);

            WorldRenderSource.Source = _bitmap;
            WorldRenderSource.Width  = _bitmap.PixelWidth;
            WorldRenderSource.Height = _bitmap.PixelHeight;
            CanvasContainer.Width    = RenderContainer.Width = _world.ScreenLength * 16 * 16;

            SelectedEditMode.SelectedIndex = 0;
            SelectedDrawMode.SelectedIndex = 0;

            TileSelector.Initialize(_graphicsAccessor, _tileService, _tileSet, palette);
            ObjectSelector.Initialize(_gameObjectService, _palettesService, _graphicsAccessor, palette);
            PointerEditor.Initialize(levelService, _worldInfo);

            _world.ObjectData.ForEach(o => o.GameObject = gameObjectService.GetObject(o.GameObjectId));


            UpdateTextTables();

            _graphicsService.GraphicsUpdated      += _graphicsService_GraphicsUpdated;
            _graphicsService.ExtraGraphicsUpdated += _graphicsService_GraphicsUpdated;
            _palettesService.PalettesChanged      += _palettesService_PalettesChanged;
            _tileService.TileSetUpdated           += _tileService_TileSetUpdated;
            _worldService.WorldUpdated            += _worldService_WorldUpdated;
            gameObjectService.GameObjectUpdated   += GameObjectService_GameObjectsUpdated;


            _world.ObjectData.ForEach(o =>
            {
                o.CalcBoundBox();
                o.CalcVisualBox(true);
            });

            _initializing = false;
            _worldRenderer.Ready();
            Update();
        }