Exemple #1
0
        public void PasteBlueprint(EditorRoomScene scene, short xStart, short yStart)
        {
            if (this.isActive == false)
            {
                return;
            }

            xStart = (short)(xStart + this.xOffset < 0 ? 0 : xStart + this.xOffset);
            yStart = (short)(yStart + this.yOffset < 0 ? 0 : yStart + this.yOffset);

            RoomFormat roomData = scene.levelContent.data.rooms[scene.roomID];

            var mainData = roomData.main;
            var objData  = roomData.obj;
            var bgData   = roomData.bg;
            var fgData   = roomData.fg;

            // Loop through the blueprint:
            for (short y = 0; y < this.blueprintHeight; y++)
            {
                for (short x = 0; x < this.blueprintWidth; x++)
                {
                    this.PasteBlueprintByLayer(scene, objData, LayerEnum.obj, x, y, xStart, yStart);
                    this.PasteBlueprintByLayer(scene, mainData, LayerEnum.main, x, y, xStart, yStart);
                    this.PasteBlueprintByLayer(scene, bgData, LayerEnum.bg, x, y, xStart, yStart);
                    this.PasteBlueprintByLayer(scene, fgData, LayerEnum.fg, x, y, xStart, yStart);
                }
            }
        }
Exemple #2
0
        public void PrepareBlueprint(EditorRoomScene scene, short xStart, short yStart, short xEnd, short yEnd, sbyte xOffset = 0, sbyte yOffset = 0)
        {
            this.isActive = true;

            short left = xStart <= xEnd ? xStart : xEnd;
            short top  = yStart <= yEnd ? yStart : yEnd;

            this.blueprintWidth  = (short)(Math.Abs(xEnd - xStart) + 1);
            this.blueprintHeight = (short)(Math.Abs(yEnd - yStart) + 1);
            this.xOffset         = xOffset;
            this.yOffset         = yOffset;

            RoomFormat roomData = scene.levelContent.data.rooms[scene.roomID];

            var mainData = roomData.main;
            var objData  = roomData.obj;
            var bgData   = roomData.bg;
            var fgData   = roomData.fg;

            // Loop through the blueprint:
            for (short y = 0; y < this.blueprintHeight; y++)
            {
                string yPos = (top + y).ToString();

                for (short x = 0; x < this.blueprintWidth; x++)
                {
                    string xPos = (left + x).ToString();

                    this.AddToBlueprintTile(mainData, LayerEnum.main, x, y, xPos, yPos);
                    this.AddToBlueprintTile(objData, LayerEnum.obj, x, y, xPos, yPos);
                    this.AddToBlueprintTile(bgData, LayerEnum.bg, x, y, xPos, yPos);
                    this.AddToBlueprintTile(fgData, LayerEnum.fg, x, y, xPos, yPos);
                }
            }
        }
Exemple #3
0
        public override void Draw()
        {
            RoomFormat roomData = this.levelContent.data.rooms[this.roomID];

            //Systems.timer.stopwatch.Start();

            if (roomData.bg != null)
            {
                DrawLayer(roomData.bg);
            }
            if (roomData.main != null)
            {
                DrawLayer(roomData.main);
            }
            if (roomData.fg != null)
            {
                DrawLayer(roomData.fg);
            }
            if (roomData.obj != null)
            {
                DrawObjectLayer(roomData.obj);
            }

            // Debugging
            //Systems.timer.stopwatch.Stop();
            //System.Console.WriteLine("Benchmark: " + Systems.timer.stopwatch.ElapsedTicks + ", " + Systems.timer.stopwatch.ElapsedMilliseconds);
        }
Exemple #4
0
        // Run Object Limiter Removal When Deleting Objects
        public void RunLimiterDeletion(LayerEnum layerEnum, short gridX, short gridY)
        {
            if (layerEnum == LayerEnum.main)
            {
                RoomFormat roomData = this.levelContent.data.rooms[roomID];

                string strX = gridX.ToString();
                string strY = gridY.ToString();

                if (roomData.main.ContainsKey(strY) && roomData.main[strY].ContainsKey(strX))
                {
                    byte tileId  = byte.Parse(roomData.main[strY][strX][0].ToString());
                    byte subType = byte.Parse(roomData.main[strY][strX][1].ToString());
                    this.scene.limiter.RemoveLimitTile(this.scene.curRoomID, tileId, subType);
                }
            }

            else if (layerEnum == LayerEnum.obj)
            {
                RoomFormat roomData = this.levelContent.data.rooms[roomID];

                string strX = gridX.ToString();
                string strY = gridY.ToString();

                if (roomData.obj.ContainsKey(strY) && roomData.obj[strY].ContainsKey(strX))
                {
                    byte objectID = byte.Parse(roomData.obj[strY][strX][0].ToString());
                    this.scene.limiter.RemoveObject(this.scene.curRoomID, objectID);
                }
            }
        }
Exemple #5
0
        protected override void ProcessLevel(string levelId)
        {
            System.Console.WriteLine("Processing Level ID: " + levelId);

            // Load the Level Content
            // Update the Level ID, or use existing Level ID if applicable.
            string fullLevelPath = LevelContent.GetFullLevelPath(levelId);

            // Make sure the level exists:
            if (!File.Exists(fullLevelPath))
            {
                return;
            }

            string json = File.ReadAllText(fullLevelPath);

            // If there is no JSON content, end the attempt to load level:
            if (json == "")
            {
                return;
            }

            // Load the Data
            LevelFormatOldV1 oldData = JsonConvert.DeserializeObject <LevelFormatOldV1>(json);

            // New Level Format
            LevelFormat newData = new LevelFormat();

            newData.account     = oldData.account;
            newData.description = oldData.description;
            newData.gameClass   = oldData.gameClass;
            newData.icon        = oldData.icon;
            newData.id          = oldData.id;
            newData.music       = oldData.music;
            newData.rooms       = new List <RoomFormat>();
            newData.timeLimit   = oldData.timeLimit;
            newData.title       = oldData.title;

            // Add the Rooms to New Format:
            foreach (KeyValuePair <string, RoomFormat> kvp in oldData.oldRooms)
            {
                RoomFormat room = kvp.Value;
                newData.rooms.Add(room);
            }

            // Assign the Level Content
            this.levelContent.data    = newData;
            this.levelContent.levelId = levelId;
            this.levelContent.data.id = levelId;

            // Save the level content.
            this.levelContent.SaveLevel(this.deliveryPath, levelId);
        }
Exemple #6
0
        // Moves the Tile JSON (per the currently indexed [static] grid coordinate trackers) with the new data:
        protected void MoveTileDataToLayer(LayerEnum newLayerEnum, byte tileId, byte subTypeId, Dictionary <string, short> paramList = null)
        {
            RoomFormat roomData = this.levelContent.data.rooms[curRoomId];
            Dictionary <string, Dictionary <string, ArrayList> > roomLayer = null;

            // Get the layer property with a switch.
            if (LevelConvert.curRoomLayerId == "main")
            {
                roomLayer = roomData.main;
            }
            else if (LevelConvert.curRoomLayerId == "obj")
            {
                roomLayer = roomData.obj;
            }
            else if (LevelConvert.curRoomLayerId == "bg")
            {
                roomLayer = roomData.bg;
            }
            else if (LevelConvert.curRoomLayerId == "fg")
            {
                roomLayer = roomData.fg;
            }

            // Remove the Layer
            if (roomLayer != null)
            {
                roomLayer[curGridY.ToString()].Remove(curGridX.ToString());
            }

            // Move to New Layer
            var newLayer = LevelContent.GetLayerData(roomData, newLayerEnum);

            if (paramList == null)
            {
                if (!newLayer.ContainsKey(curGridY.ToString()))
                {
                    newLayer.Add(curGridY.ToString(), new Dictionary <string, ArrayList>());
                }
                newLayer[curGridY.ToString()][curGridX.ToString()] = new ArrayList {
                    tileId, subTypeId
                };
            }
            else
            {
                if (!newLayer.ContainsKey(curGridY.ToString()))
                {
                    newLayer.Add(curGridY.ToString(), new Dictionary <string, ArrayList>());
                }
                newLayer[curGridY.ToString()][curGridX.ToString()] = new ArrayList {
                    tileId, subTypeId, paramList
                };
            }
        }
Exemple #7
0
        public async Task <ApiResultLite> CreateAsync(RoomFormatCreateRequest model)
        {
            var room = new RoomFormat()
            {
                Name  = model.Name,
                Price = model.Price,
            };

            await _context.AddAsync(room);

            if ((await _context.SaveChangesAsync()) == 0)
            {
                return(new ApiErrorResultLite("Không thể thêm định dạng"));
            }
            return(new ApiSuccessResultLite("Thêm thành công"));
        }
Exemple #8
0
        // Overwrites the Tile JSON (per the currently indexed [static] grid coordinate trackers) with the new data:
        protected void OverwriteTileData(byte tileId, byte subTypeId, Dictionary <string, short> paramList = null)
        {
            RoomFormat roomData = this.levelContent.data.rooms[curRoomId];
            Dictionary <string, Dictionary <string, ArrayList> > roomLayer = null;

            // Need to load the layer property with a switch.
            if (LevelConvert.curRoomLayerId == "main")
            {
                roomLayer = roomData.main;
            }
            else if (LevelConvert.curRoomLayerId == "obj")
            {
                roomLayer = roomData.obj;
            }
            else if (LevelConvert.curRoomLayerId == "bg")
            {
                roomLayer = roomData.bg;
            }
            else if (LevelConvert.curRoomLayerId == "fg")
            {
                roomLayer = roomData.fg;
            }

            if (roomLayer != null)
            {
                if (paramList == null)
                {
                    if (!roomLayer.ContainsKey(curGridY.ToString()))
                    {
                        roomLayer.Add(curGridY.ToString(), new Dictionary <string, ArrayList>());
                    }
                    roomLayer[curGridY.ToString()][curGridX.ToString()] = new ArrayList {
                        tileId, subTypeId
                    };
                }
                else
                {
                    if (!roomLayer.ContainsKey(curGridY.ToString()))
                    {
                        roomLayer.Add(curGridY.ToString(), new Dictionary <string, ArrayList>());
                    }
                    roomLayer[curGridY.ToString()][curGridX.ToString()] = new ArrayList {
                        tileId, subTypeId, paramList
                    };
                }
            }
        }
Exemple #9
0
        public void CloneTile(short gridX, short gridY)
        {
            RoomFormat roomData = this.levelContent.data.rooms[this.roomID];
            Dictionary <string, Dictionary <string, ArrayList> > layerData = null;
            bool isObject = false;

            if (LevelContent.VerifyTiles(roomData.obj, gridX, gridY))
            {
                layerData = roomData.obj; isObject = true;
            }
            else if (LevelContent.VerifyTiles(roomData.main, gridX, gridY))
            {
                layerData = roomData.main;
            }
            else if (LevelContent.VerifyTiles(roomData.fg, gridX, gridY))
            {
                layerData = roomData.fg;
            }
            else if (LevelContent.VerifyTiles(roomData.bg, gridX, gridY))
            {
                layerData = roomData.bg;
            }

            // If no tile is cloned, set the current Function Tool to "Select"
            if (layerData == null)
            {
                FuncToolSelect selectFunc = (FuncToolSelect)FuncTool.funcToolMap[(byte)FuncToolEnum.Select];
                EditorTools.SetFuncTool(selectFunc);
                selectFunc.ClearSelection();
                return;
            }

            // Get the Object from the Highlighted Tile (Search Front to Back until a tile is identified)
            byte[] tileData = LevelContent.GetTileData(layerData, gridX, gridY);

            // Identify the tile, and set it as the current editing tool (if applicable)
            TileTool clonedTool = TileTool.GetTileToolFromTileData(tileData, isObject);

            if (clonedTool is TileTool == true)
            {
                byte subIndex = clonedTool.subIndex;                 // Need to save this value to avoid subIndexSaves[] tracking.
                EditorTools.SetTileTool(clonedTool, (byte)clonedTool.index);
                clonedTool.SetSubIndex(subIndex);
            }
        }
Exemple #10
0
        public async Task <ApiResultLite> UpdateAsync(RoomFormatUpdateRequest model)
        {
            RoomFormat room = await _context.RoomFormats.FindAsync(model.Id);

            if (room == null)
            {
                return(new ApiErrorResultLite("Không tìm thấy định dạng"));
            }
            else
            {
                room.Name  = model.Name;
                room.Price = model.Price;
                _context.Update(room);
                await _context.SaveChangesAsync();

                return(new ApiSuccessResultLite("Cập nhật thành công"));
            }
        }
Exemple #11
0
        public async Task <ApiResultLite> DeleteAsync(int id)
        {
            RoomFormat room = await _context.RoomFormats.FindAsync(id);

            if (room == null)
            {
                return(new ApiErrorResultLite("Không tìm thấy định dạng"));
            }
            else
            {
                _context.RoomFormats.Remove(room);
                if (await _context.SaveChangesAsync() != 0)
                {
                    return(new ApiSuccessResultLite("Xóa thành công"));
                }
                else
                {
                    return(new ApiSuccessResultLite("Không xóa được"));
                }
            }
        }
Exemple #12
0
        public void RunRoomCount(byte roomID, RoomFormat room)
        {
            if (roomID > 5)
            {
                return;
            }

            // Scan Through Objects Layer
            foreach (KeyValuePair <string, Dictionary <string, ArrayList> > yData in room.obj)
            {
                short gridY = short.Parse(yData.Key);

                // Loop through XData
                foreach (KeyValuePair <string, ArrayList> xData in yData.Value)
                {
                    byte objectID = byte.Parse(xData.Value[0].ToString());

                    // Add the object to the list, if applicable.
                    this.AddLimitObject(roomID, objectID, true);
                }
            }

            // Scan Through Main Tile Layer
            foreach (KeyValuePair <string, Dictionary <string, ArrayList> > yData in room.main)
            {
                short gridY = short.Parse(yData.Key);

                // Loop through XData
                foreach (KeyValuePair <string, ArrayList> xData in yData.Value)
                {
                    byte objectID = byte.Parse(xData.Value[0].ToString());
                    byte subType  = byte.Parse(xData.Value[1].ToString());

                    // Add the object to the list, if applicable.
                    this.AddLimitTile(roomID, objectID, subType);
                }
            }
        }
Exemple #13
0
        protected virtual void ProcessLevel(string levelId)
        {
            System.Console.WriteLine("Processing Level ID: " + levelId);

            // Load the Level Content
            this.levelContent.LoadLevelData(levelId);

            // If the level content wasn't loaded correctly:
            if (this.levelContent.levelId != levelId)
            {
                throw new Exception("Level content was not loaded correctly.");
            }

            for (byte roomID = 0; roomID < this.levelContent.data.rooms.Count; roomID++)
            {
                LevelConvert.curRoomId = roomID;
                RoomFormat roomData = this.levelContent.data.rooms[roomID];

                if (roomData.obj != null)
                {
                    LevelConvert.curRoomLayerId = "obj";
                    this.ProcessLayerData(roomData.obj, true);
                }
                else
                {
                    roomData.obj = new Dictionary <string, Dictionary <string, ArrayList> >();
                }

                if (roomData.bg != null)
                {
                    LevelConvert.curRoomLayerId = "bg";
                    this.ProcessLayerData(roomData.bg);
                }
                else
                {
                    roomData.bg = new Dictionary <string, Dictionary <string, ArrayList> >();
                }

                if (roomData.main != null)
                {
                    LevelConvert.curRoomLayerId = "main";
                    this.ProcessLayerData(roomData.main);
                }
                else
                {
                    roomData.main = new Dictionary <string, Dictionary <string, ArrayList> >();
                }

                if (roomData.fg != null)
                {
                    LevelConvert.curRoomLayerId = "fg";
                    this.ProcessLayerData(roomData.fg);
                }
                else
                {
                    roomData.fg = new Dictionary <string, Dictionary <string, ArrayList> >();
                }
            }

            // Save the level content.
            this.levelContent.SaveLevel(this.deliveryPath, levelId);
        }
Exemple #14
0
        // Initialize Wand Data
        public static bool InitializeWandData(EditorRoomScene scene, short gridX, short gridY)
        {
            // Get Scene References
            WandData.editorScene   = scene;
            WandData.moveParamMenu = WandData.editorScene.scene.editorUI.moveParamMenu;
            WandData.actParamMenu  = WandData.editorScene.scene.editorUI.actParamMenu;
            WandData.levelContent  = WandData.editorScene.levelContent;

            RoomFormat roomData = WandData.levelContent.data.rooms[WandData.editorScene.roomID];

            // Verify that Tile is Valid:
            WandData.validTile = false;

            if (LevelContent.VerifyTiles(roomData.main, gridX, gridY))
            {
                WandData.layerData = roomData.main;
                WandData.isObject  = false;
            }

            else if (LevelContent.VerifyTiles(roomData.fg, gridX, gridY))
            {
                WandData.layerData = roomData.fg;
                WandData.isObject  = false;
            }

            else if (LevelContent.VerifyTiles(roomData.obj, gridX, gridY))
            {
                WandData.layerData = roomData.obj;
                WandData.isObject  = true;
            }

            else
            {
                return(false);
            }

            WandData.validTile = true;

            WandData.gridX = gridX;
            WandData.gridY = gridY;

            // Get Tile Content Data
            WandData.wandTileData = LevelContent.GetTileDataWithParams(WandData.layerData, WandData.gridX, WandData.gridY);

            // Get the Param Set Used
            Params moveParamSet = null;
            Params actParamSet  = null;

            if (WandData.isObject)
            {
                moveParamSet = Systems.mapper.ObjectMetaData[byte.Parse(WandData.wandTileData[0].ToString())].moveParamSet;
                actParamSet  = Systems.mapper.ObjectMetaData[byte.Parse(WandData.wandTileData[0].ToString())].actParamSet;
            }
            else
            {
                TileObject wandTile = Systems.mapper.TileDict[byte.Parse(WandData.wandTileData[0].ToString())];
                moveParamSet = wandTile.moveParamSet;
                actParamSet  = wandTile.actParamSet;
            }

            // If the tile has param sets, it can be used here. Otherwise, return.
            WandData.validTile = (moveParamSet != null || actParamSet != null);
            if (WandData.validTile == false)
            {
                return(false);
            }

            WandData.moveParamSet = moveParamSet;
            WandData.actParamSet  = actParamSet;

            return(true);
        }
Exemple #15
0
        public void TileToolTick(short gridX, short gridY)
        {
            // Prevent drawing when a component is selected.
            if (UIComponent.ComponentWithFocus != null)
            {
                return;
            }

            // Make sure placement is in valid location:
            if (gridY < 0 || gridY > this.yCount)
            {
                return;
            }
            if (gridX < 0 || gridX > this.xCount)
            {
                return;
            }

            TileTool tool = EditorTools.tileTool;

            // Make sure the tile tool is set, or placement cannot occur:
            if (tool == null)
            {
                return;
            }

            // Check if AutoTile Tool is intended. Requires Control to be held down.
            if (Systems.input.LocalKeyDown(Keys.LeftControl))
            {
                // If left mouse button was just clicked, AutoTile is being activated.
                if (Cursor.LeftMouseState == Cursor.MouseDownState.Clicked)
                {
                    EditorTools.StartAutoTool(gridX, gridY);
                }
            }

            // If AutoTile Tool is active, run it's behavior:
            if (EditorTools.autoTool.IsActive)
            {
                // If left mouse was just released and AutoTile is active, place AutoTiles.
                if (Cursor.LeftMouseState == Cursor.MouseDownState.Released)
                {
                    EditorTools.autoTool.PlaceAutoTiles(this);
                }

                // If Control key is not held down, auto-tiles must be deactivated.
                else if (!Systems.input.LocalKeyDown(Keys.LeftControl))
                {
                    EditorTools.autoTool.ClearAutoTiles();
                }

                return;
            }

            // Left Mouse Button (Overwrite Current Tile)
            if (Cursor.mouseState.LeftButton == ButtonState.Pressed)
            {
                // Prevent repeat-draws on the same tile (e.g. within the last 100ms).
                if (!DrawTracker.AttemptPlace(gridX, gridY))
                {
                    return;
                }

                EditorPlaceholder ph = tool.CurrentPlaceholder;

                // Place Tile
                if (ph.tileId > 0)
                {
                    RoomFormat roomData = this.levelContent.data.rooms[this.roomID];

                    if (ph.layerEnum == LayerEnum.main)
                    {
                        // Check the Tile Limiter before placing the tile.
                        if (this.scene.limiter.AddLimitTile(this.scene.curRoomID, ph.tileId, ph.subType))
                        {
                            this.PlaceTile(roomData.main, ph.layerEnum, gridX, gridY, ph.tileId, ph.subType, null);
                        }

                        // If the Object Limiter failed, display the error message.
                        else
                        {
                            UIHandler.AddNotification(UIAlertType.Error, "Limit Reached", ObjectLimiter.LastFailMessage, 240);
                        }
                    }
                    else if (ph.layerEnum == LayerEnum.bg)
                    {
                        this.PlaceTile(roomData.bg, ph.layerEnum, gridX, gridY, ph.tileId, ph.subType, null);
                    }
                    else if (ph.layerEnum == LayerEnum.fg)
                    {
                        this.PlaceTile(roomData.fg, ph.layerEnum, gridX, gridY, ph.tileId, ph.subType, null);
                    }
                }

                // Place Object
                else if (ph.objectId > 0)
                {
                    // Check the Object Limiter before placing the tile.
                    if (this.scene.limiter.AddLimitObject(this.scene.curRoomID, ph.objectId))
                    {
                        this.PlaceTile(this.levelContent.data.rooms[this.roomID].obj, LayerEnum.obj, gridX, gridY, ph.objectId, ph.subType, null);
                    }

                    // If the Object Limiter failed, display the error message.
                    else
                    {
                        UIHandler.AddNotification(UIAlertType.Error, "Limit Reached", ObjectLimiter.LastFailMessage, 240);
                    }
                }

                return;
            }
        }