예제 #1
0
 void LoadLevel()
 {
     // so simple
     level = JsonUtility.FromJson <LevelFormat>(levelJson.text);
     leftGrid.Init(level.leftGrid);
     rightGrid.Init(level.rightGrid);
 }
예제 #2
0
        public static async Task <bool> LevelRequest(string levelId)
        {
            levelId = levelId.ToUpper();

            // Make sure the level doesn't already exist locally. If it does, there's no need to call the online API.
            if (LevelContent.LevelExists(levelId))
            {
                Systems.handler.levelContent.LoadLevelData(levelId);
                return(true);
            }

            // All checks have passed. Request the Level.
            try {
                string json = await Systems.httpClient.GetStringAsync(GameValues.CreoAPI + "level/" + levelId);

                // If the retrieval fails:
                if (json.IndexOf("success:\"fail") > -1)
                {
                    return(false);
                }

                // Load Level Data
                LevelFormat levelData = JsonConvert.DeserializeObject <LevelFormat>(json);
                levelData.id = levelId;
                Systems.handler.levelContent.LoadLevelData(levelData);

                // Save Level
                Systems.handler.levelContent.SaveLevel();

                return(true);
            } catch (Exception ex) {
                return(false);
            }
        }
 public void setData(LevelFormat _levelData, int _levelNb)
 {
     levelData      = _levelData;
     levelName.text = levelData.name;
     if (ActualSave.actualSave.levels[_levelNb - 1].beaten)
     {
         if (ActualSave.actualSave.levels[_levelNb - 1].collectedSlime < _levelData.bonusCount)
         {
             collectedSlime.text        = ActualSave.actualSave.levels[_levelNb - 1].collectedSlime + "";
             slimeImageContainer.sprite = missingSlime;
         }
         else
         {
             collectedSlime.text        = _levelData.bonusCount + "";
             slimeImageContainer.sprite = completeSlime;
         }
         slimeNumber.text = "/" + levelData.bonusCount;
     }
     else
     {
         collectedSlime.text        = "?";
         slimeImageContainer.sprite = missingSlime;
         slimeNumber.text           = "??";
     }
     levelNb          = _levelNb;
     levelNbText.text = "" + _levelNb;
 }
예제 #4
0
        public void SaveLevel()
        {
            LevelFormat lvl = new LevelFormat();

            lvl.playerInfo       = player.Info;
            lvl.clickObjectsInfo = new List <ClickAbleInfo>();

            foreach (object o in GameObjects)
            {
                if (o is ClickableObject)
                {
                    lvl.clickObjectsInfo.Add((o as ClickableObject).Info);
                }
                else if (o is MovementTile)
                {
                    lvl.moveTiles.Add((o as MovementTile).Info);
                }
                else if (o is WinTile)
                {
                    lvl.moveTiles.Add((o as WinTile).Info);
                }
            }

            LevelManager.Instance.SaveLevel(lvl, levelID);
        }
예제 #5
0
        ushort z; // Length/Depth

        #endregion Fields

        #region Constructors

        // Constructor
        public LevelConverter()
        {
            mFileName = String.Empty;
            mInputFormat = LevelFormat.Null;
            lvlVisitPermission = 0;
            lvlBuildPermission = 0;
        }
예제 #6
0
        public async Task <bool> DisplayLevelInfo()
        {
            // Reset Status Text
            this.worldUI.statusText.SetText(null, null);

            // Verify the Node is ready.
            if (!await RunNodeReadiness())
            {
                return(false);
            }

            // Identify Level Data at this node:
            int    coordId = Coords.MapToInt(this.character.curX, this.character.curY);
            string levelId = this.currentZone.nodes.ContainsKey(coordId.ToString()) ? this.currentZone.nodes[coordId.ToString()] : "";

            // Make sure the level exists.
            LevelFormat levelData = LevelContent.GetLevelData(levelId);

            if (levelData == null)
            {
                return(false);
            }

            // Set Level Title and Description
            this.worldUI.statusText.SetText(levelData.title, levelData.description);

            return(true);
        }
예제 #7
0
 // Constructor
 public LevelConverter()
 {
     mFileName          = String.Empty;
     mInputFormat       = LevelFormat.Null;
     lvlVisitPermission = 0;
     lvlBuildPermission = 0;
 }
예제 #8
0
 public void Load()
 {
     if (!LevelLoaded)
     {
         try
         {
             if (IOHelper.Instance.CreateDirectory(levelDir))
             {
                 if (IOHelper.Instance.DoesFileExist(levelDir + "level" + levelID + ".json"))
                 {
                     level       = JsonConvert.DeserializeObject <LevelFormat>(IOHelper.Instance.ReadFile(levelDir + "level" + levelID + ".json"));
                     LevelLoaded = true;
                 }
                 else
                 {
                     throw new FileNotFoundException(levelDir + "level" + levelID + ".json doesn't exsist");
                 }
             }
             else
             {
                 throw new Exception("Couldn't create dir");
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
         }
     }
 }
예제 #9
0
 public GameScreen(LevelFormat level, bool test = true)
 {
     loader        = new LevelLoader(level);
     GameObjects   = new List <object>();
     player        = new Player();
     objectives    = new List <Objective>();
     drawAbleItems = new List <IDrawAble>();
     levelID       = -1;
     testing       = test;
 }
예제 #10
0
 public void LoadFromLevelInfo(LevelFormat lvl)
 {
     if (lvl.Grid != null && lvl.Grid.Count > 0)
     {
         foreach (GridTileInfo info in lvl.Grid)
         {
             grid[info.column, info.row] = info.cliprect;
         }
     }
 }
예제 #11
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);
        }
예제 #12
0
        public override void LoadLevel(LevelFormat level)
        {
            foreach (ClickAbleInfo info in level.clickObjectsInfo)
            {
                ClickableObject clickObj = new ClickableObject();

                bool found = false;
                foreach (Tuple <string, Texture2D> tup in textures)
                {
                    if (tup.Item1 == info.texturePath)
                    {
                        found                = true;
                        clickObj.Image       = tup.Item2;
                        clickObj.TexturePath = tup.Item1;
                    }
                }

                // Texture not found just drop it
                if (!found)
                {
                    continue;
                }

                if (info.useCustomBounds)
                {
                    clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                }

                clickObj.StartPosition  = info.position;
                clickObj.Position       = info.position;
                clickObj.moveToPosition = info.moveToPosition;
                clickObj.TexturePath    = info.texturePath;

                // Check if the object has an animation
                if (IOHelper.Instance.DoesFileExist(Constants.CONTENT_DIR + info.texturePath + ".ani"))
                {
                    AnimationInfo aInfo = JsonConvert.DeserializeObject <AnimationInfo>(IOHelper.Instance.ReadFile(Constants.CONTENT_DIR + info.texturePath + ".ani"));
                    clickObj.Animation = new Animation(Game1.Instance.Content.Load <Texture2D>(info.texturePath), aInfo.width, aInfo.height, aInfo.cols, aInfo.rows, aInfo.totalFrames, aInfo.fps);
                }

                clickObj.ObjectiveID = info.objectiveID;

                if (info.useCustomBounds)
                {
                    clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                }
                clickables.Add(clickObj);
                clickablesCount++;
            }

            base.LoadLevel(level);
        }
예제 #13
0
        public override void LoadLevel(LevelFormat level)
        {
            player.StartPosition = level.playerInfo.position;
            player.StartMovement = level.playerInfo.startMovement;
            player.ChangePosition(level.playerInfo.position);
            player.ChangeMovement(level.playerInfo.startMovement);

            if (level.playerInfo.useCustomBoundingbox)
            {
                player.SetCustomBoundingbox(new Rectangle(level.playerInfo.x, level.playerInfo.y, level.playerInfo.width, level.playerInfo.height));
            }

            base.LoadLevel(level);
        }
예제 #14
0
    // Use this for initialization
    void Start()
    {
        string data = toLoad.text; // get the text

        Debug.Log("Raw json " + data);
        LevelFormat tl = JsonUtility.FromJson <LevelFormat>(data);

        Debug.Log("Looking good: len " + tl.leftGrid.Length);

        // testing obfuscation on data
        byte[] bytesToEncode = System.Text.Encoding.UTF8.GetBytes(data);
        string encodedText   = System.Convert.ToBase64String(bytesToEncode);

        Debug.Log("Encode: " + encodedText.Length + " " + encodedText);
    }
예제 #15
0
        public void DrawLevel(short levelNum, short posX, short posY)
        {
            // Display Slot Number
            Systems.fonts.console.Draw("#" + levelNum, posX + 6, posY + 98, Color.White);

            // If there is no level data, mark it as an open slot:
            if (!this.levels.ContainsKey(levelNum))
            {
                // Draw Level
                UIHandler.atlas.DrawAdvanced(MyLevelsScene.openImg, posX - 5, posY, Color.White, 0f, 2);

                //// Draw Character
                //Head.GetHeadBySubType(6).Draw(false, posX - 30, posY - 15, 0, 0);
                //Suit.GetSuitBySubType(51).Draw("StandLeft", posX - 30, posY - 15, 0, 0);

                // Display Empty Level Slot
                short emptySize = (short)Systems.fonts.baseText.font.MeasureString(MyLevelsScene.openSlot).X;
                Systems.fonts.baseText.Draw(MyLevelsScene.openSlot, posX + 16 - (byte)Math.Floor(emptySize * 0.5f), posY + 73, Color.White);

                return;
            }

            LevelFormat levelData = this.levels[levelNum];

            // Draw Level
            Systems.mapper.atlas[(byte)AtlasGroup.Tiles].DrawAdvanced(MyLevelsScene.activeImg, posX - 5, posY, Color.White, 0f, 2);

            // Display Name
            short titleSize = (short)Systems.fonts.baseText.font.MeasureString(levelData.title).X;

            Systems.fonts.baseText.Draw(levelData.title, posX + 16 - (byte)Math.Floor(titleSize * 0.5f), posY + 73, Color.White);

            //// Display Character
            //if(levelData.icon[0] > 0 && levelData.icon[1] > 0) {
            //	Head.GetHeadBySubType(levelData.icon[0]).Draw(false, posX - 30, posY - 15, 0, 0);
            //	Suit.GetSuitBySubType(levelData.icon[1]).Draw("StandLeft", posX - 30, posY - 15, 0, 0);

            //	if(levelData.icon[2] > 0) {
            //		Hat.GetHatBySubType(levelData.icon[2]).Draw(false, posX - 30, posY - 15, 0, 0);
            //	} else if(levelData.icon[0] == (byte)HeadSubType.PooHead) {
            //		Hat.GetHatBySubType((byte)HatSubType.PooHat).Draw(false, posX - 30, posY - 15, 0, 0);
            //	}
            //}
        }
예제 #16
0
        public bool LoadDAT()
        {
            bool success = false;

            com.mojang.minecraft.level.Level dat;
            try
            {
                // Load file
                dat = com.mojang.minecraft.level.Level.Load(mFileName);

                // Read in levelname
                mapName = dat.name;

                // Read in dimensions
                x = (ushort)dat.width;
                y = (ushort)dat.height;
                z = (ushort)dat.depth;

                // Read in spawn
                spawnx    = (ushort)dat.xSpawn;
                spawny    = (ushort)dat.ySpawn;
                spawnz    = (ushort)dat.zSpawn;
                spawnrotx = 0;
                spawnroty = 0;

                // Read in blocks
                blocks = new byte[dat.blocks.Length];
                blocks = dat.blocks;


                success      = true;
                mInputFormat = LevelFormat.MinecraftDAT;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error loading dat");
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }

            return(success);
        }
예제 #17
0
        public override void LoadLevel(LevelFormat level)
        {
            foreach (DecorationInfo d in level.decoration)
            {
                Decoration decoration = new Decoration(d.ImagePath);
                decoration.Position = d.position;

                for (int i = 0; i < decorationImages.Count; i++)
                {
                    if (decorationImages[i].Item1 == d.ImagePath)
                    {
                        decoration.Image = decorationImages[i].Item2;
                        break;
                    }
                }

                tiles.Add(decoration);
            }

            base.LoadLevel(level);
        }
예제 #18
0
        public bool ApplyLevelDataByNumber(short levelNum)
        {
            string levelId = "__" + levelNum.ToString();

            // Check if the level has already been attached into the dictionary. If so, return TRUE.
            if (this.levels.ContainsKey(levelNum))
            {
                return(true);
            }

            // Make sure the level exists.
            LevelFormat levelData = LevelContent.GetLevelData(levelId);

            if (levelData == null)
            {
                return(false);
            }

            // Attach the level data to the levels dictionary.
            this.levels.Add(levelNum, levelData);

            return(true);
        }
    public void HandlePreview()
    {
        if (actualPreview)
        {
            LeanTween.pause(activeAnimation);
            actualPreview.LeanScale(Vector3.zero, 0.1f);
            Destroy(actualPreview, 0.2f);
        }
        if (stateMachine.ID >= 0)
        {
            hasBeenInvoked = false;
            GameObject selected = stateMachine.firstSelected.gameObject.transform.parent.gameObject;
            actualLevelData = selected.GetComponent <levelBubbleHandlerScript>().getLevelData();
            Object prefab = Resources.Load("Levels/" + actualLevelData.objName); // Assets/Resources/Prefabs/prefab1.FBX
            actualPreview = (GameObject)Instantiate(prefab, levelPreviewContainer.transform);
            actualPreview.transform.localPosition = Vector3.zero;
            actualPreview.transform.localScale    = Vector3.zero;
            Quaternion rotation = new Quaternion();
            rotation.eulerAngles             = new Vector3(actualLevelData.previewRotation[0], actualLevelData.previewRotation[1], actualLevelData.previewRotation[2]);
            actualPreview.transform.rotation = rotation;

            Invoke("animatePreview", 0.3f);
        }
    }
예제 #20
0
        private LevelFormat GetLevelFormat()
        {
            LevelFormat lvl = new LevelFormat();

            List <object> allLayerObjects = AllLayerObjects();

            foreach (object o in allLayerObjects)
            {
                if (o is Player)
                {
                    lvl.playerInfo = (o as Player).Info;
                }
                else if (o is ClickableObject)
                {
                    lvl.clickObjectsInfo.Add((o as ClickableObject).Info);
                }
                else if (o is MovementTile)
                {
                    lvl.moveTiles.Add((o as MovementTile).Info);
                }
                else if (o is WinTile)
                {
                    lvl.moveTiles.Add((o as WinTile).Info);
                }
                else if (o is Decoration)
                {
                    lvl.decoration.Add((o as Decoration).Info);
                }
                else if (o is GridTileInfo)
                {
                    lvl.Grid.Add((o as GridTileInfo));
                }
            }

            return(lvl);
        }
예제 #21
0
 public virtual void LoadLevel(LevelFormat level)
 {
 }
예제 #22
0
        public bool LoadMCSharp()
        {
            bool success = false;
            FileStream fs = File.OpenRead(mFileName);
            try
            {
                // Open a GZIP Stream
                GZipStream gs = new GZipStream(fs, CompressionMode.Decompress);
                byte[] ver = new byte[2];
                gs.Read(ver, 0, ver.Length);
                ushort version = BitConverter.ToUInt16(ver, 0);

                if (version == 1900)
                {

                }
                else if (version == 1874)
                {
                    // Read in the header
                    byte[] header = new byte[16];
                    gs.Read(header, 0, header.Length);

                    // Map Dimensions
                    x = BitConverter.ToUInt16(header, 0);
                    y = BitConverter.ToUInt16(header, 2);
                    z = BitConverter.ToUInt16(header, 4);
                    //
                    spawnx = BitConverter.ToUInt16(header, 6);
                    spawnz = BitConverter.ToUInt16(header, 8);
                    spawny = BitConverter.ToUInt16(header, 10);
                    spawnrotx = header[12];
                    spawnroty = header[13];
                    lvlVisitPermission = header[14];
                    lvlBuildPermission = header[15];

                    // Read in block data
                    blocks = new byte[x * y * z];
                    gs.Read(blocks, 0, blocks.Length);
                }
                else
                {
                    // Read in the header
                    byte[] header = new byte[12];
                    gs.Read(header, 0, header.Length);

                    // Map Dimensions
                    x = version;
                    y = BitConverter.ToUInt16(header, 0);
                    z = BitConverter.ToUInt16(header, 2);

                    // Spawn
                    spawnx = BitConverter.ToUInt16(header, 4);
                    spawnz = BitConverter.ToUInt16(header, 6);
                    spawny = BitConverter.ToUInt16(header, 8);
                    spawnrotx = header[10];
                    spawnroty = header[11];

                    // Read in block data
                    blocks = new byte[x * y * z];
                    gs.Read(blocks, 0, blocks.Length);
                }

                // Close the GZIP stream
                gs.Close();
                success = true;
                mInputFormat = LevelFormat.MCSharp;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error while loading the old MCSharp level.");
                Console.WriteLine(e.Message);
            }
            return success;
        }
예제 #23
0
 // Use this for initialization
 void Start()
 {
     level = JsonUtility.FromJson <LevelFormat>(inputText.text);
     MakeTiles();
 }
예제 #24
0
        public bool LoadDAT()
        {
            bool success = false;
            com.mojang.minecraft.level.Level dat;
            try
            {
                // Load file
                dat = com.mojang.minecraft.level.Level.Load(mFileName);

                // Read in levelname
                mapName = dat.name;

                // Read in dimensions
                x = (ushort)dat.width;
                y = (ushort)dat.height;
                z = (ushort)dat.depth;

                // Read in spawn
                spawnx = (ushort)dat.xSpawn;
                spawny = (ushort)dat.ySpawn;
                spawnz = (ushort)dat.zSpawn;
                spawnrotx = 0;
                spawnroty = 0;

                // Read in blocks
                blocks = new byte[dat.blocks.Length];
                blocks = dat.blocks;

                success = true;
                mInputFormat = LevelFormat.MinecraftDAT;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error loading dat");
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }

            return success;
        }
예제 #25
0
 public override void LoadLevel(LevelFormat level)
 {
     base.LoadLevel(level);
 }
예제 #26
0
 /// <summary>
 /// Save an level
 /// </summary>
 /// <param name="lvl">The level file</param>
 /// <param name="levelID">The ID of the level</param>
 public void SaveLevel(LevelFormat lvl, int levelID)
 {
     IOHelper.Instance.WriteFile(@"\levels\" + "level" + levelID + ".json", JsonConvert.SerializeObject(lvl, Formatting.Indented));
 }
예제 #27
0
        public bool LoadMCSharp()
        {
            bool       success = false;
            FileStream fs      = File.OpenRead(mFileName);

            try
            {
                // Open a GZIP Stream
                GZipStream gs  = new GZipStream(fs, CompressionMode.Decompress);
                byte[]     ver = new byte[2];
                gs.Read(ver, 0, ver.Length);
                ushort version = BitConverter.ToUInt16(ver, 0);

                if (version == 1900)
                {
                }
                else if (version == 1874)
                {
                    // Read in the header
                    byte[] header = new byte[16];
                    gs.Read(header, 0, header.Length);

                    // Map Dimensions
                    x = BitConverter.ToUInt16(header, 0);
                    y = BitConverter.ToUInt16(header, 2);
                    z = BitConverter.ToUInt16(header, 4);
                    //
                    spawnx             = BitConverter.ToUInt16(header, 6);
                    spawnz             = BitConverter.ToUInt16(header, 8);
                    spawny             = BitConverter.ToUInt16(header, 10);
                    spawnrotx          = header[12];
                    spawnroty          = header[13];
                    lvlVisitPermission = header[14];
                    lvlBuildPermission = header[15];

                    // Read in block data
                    blocks = new byte[x * y * z];
                    gs.Read(blocks, 0, blocks.Length);
                }
                else
                {
                    // Read in the header
                    byte[] header = new byte[12];
                    gs.Read(header, 0, header.Length);

                    // Map Dimensions
                    x = version;
                    y = BitConverter.ToUInt16(header, 0);
                    z = BitConverter.ToUInt16(header, 2);

                    // Spawn
                    spawnx    = BitConverter.ToUInt16(header, 4);
                    spawnz    = BitConverter.ToUInt16(header, 6);
                    spawny    = BitConverter.ToUInt16(header, 8);
                    spawnrotx = header[10];
                    spawnroty = header[11];

                    // Read in block data
                    blocks = new byte[x * y * z];
                    gs.Read(blocks, 0, blocks.Length);
                }

                // Close the GZIP stream
                gs.Close();
                success      = true;
                mInputFormat = LevelFormat.MCSharp;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error while loading the old MCSharp level.");
                Console.WriteLine(e.Message);
            }
            return(success);
        }
예제 #28
0
 public LevelLoader(LevelFormat level)
 {
     this.level  = level;
     LevelLoaded = true;
 }