public static void SaveLevelStorage(LevelStorage levelStorage)
    {
        Serializer.Serialize(levelStorage, ConfigPath);
		#if UNITY_EDITOR
        UnityEditor.AssetDatabase.Refresh();
		#endif
    }
Example #2
0
        /* --- Save & Load -------------------------------------------------- */

        public static Level Load(LevelStorage store)
        {
            return(new Level(LEVELS.GetProperties(store.Type), store.Width, store.Height)
            {
                Id = store.Id,
                Name = store.Name,
            });
        }
Example #3
0
        private void deleteRequested(CarouselItem item)
        {
            var name = item.LevelName;

            LevelStorage.DeleteLevel(name);
            notifications.Push($"{name} level has been deleted!", NotificationState.Good);
            selectFirst();
            item.Expire();
        }
Example #4
0
        public void HandleLEVEL(Socket socket, byte[] data)
        {
            new BufferReader(data)
            .Ignore(sizeof(int))
            .ReadStringUTF8(out var levelJson);

            LevelStorage levelStorage = levelJson.FromJson <LevelStorage>();

            Logger.Log <GameState>($"Loading {levelStorage.Name}...");
            Level level = Level.Load(levelStorage);

            World.Levels.Add(level);
        }
Example #5
0
        private bool canBeCreated(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                notifications.Push("Level name can't be empty", NotificationState.Bad);
                return(false);
            }

            if (LevelStorage.LevelExists(name))
            {
                notifications.Push($"\"{name}\" level already exists", NotificationState.Bad);
                return(false);
            }

            return(true);
        }
Example #6
0
        public void UpdateItems()
        {
            flow.Clear();

            foreach (var l in LevelStorage.GetLevels())
            {
                flow.Add(new CarouselItem(l)
                {
                    Selected = onSelection,
                    OnEdit   = editRequested,
                    Deleted  = deleteRequested,
                });
            }

            selectFirst();
        }
Example #7
0
    public void ChangeScene(int sceneNumber, bool saveRoomData)
    {
        LevelStorage levelStorage = this.GetComponent <LevelStorage>();

        if (saveRoomData)
        {
            levelStorage.StoreCurrentLevelData();
            previousScene = Application.loadedLevel;
        }

        StateHandler stateHandler = this.GetComponent <StateHandler>();

        stateHandler.gameState = GameState.Normal;

        Application.LoadLevel(sceneNumber);
    }
Example #8
0
    void OnItemUnlockButton(PictruePage_Item item)
    {
        var data = item.data;
        var cost = data.picRow.Get <int>("cost");
        var gold = PlayerStatus.gold;

        if (gold >= cost)
        {
            Debug.Log("can unlock");
            gold -= cost;
            PlayerStatus.gold = gold;
            var pictureId = data.picRow.Get <string>("id");
            LevelStorage.SetPictureUnlocked(pictureId);
            PlayerStatus.Save();

            // 单独处理需要修改显示状态的 item
            data.status = PicturePage_ItemStatus.Unlocked;
            SetItem(item, data);
            item.Flash();
            AudioManager.PlaySe("button");
            AudioManager.PlaySe("unlock-pic");
        }
        else
        {
            var param = new DialogParam();
            param.des    = MsgList.Get("lack_of_gold");
            param.button = "商城";
            var popup  = new Admission_PopupNewPage();
            var dialog = UIEngine.Forward <DialogPage>(param, popup);
            dialog.Complete = result => {
                if (result == DialogResult.Conform)
                {
                    UIEngineHelper.WateAdmissionComplete(() => {
                        UIEngine.Forward <ShopPage>();
                    });
                }
            };
            AudioManager.PlaySe("lack-of-gold");
        }
    }
Example #9
0
    private void Start()
    {
        if (GameObject.FindWithTag(Tags.persistentEngine) && GameObject.FindWithTag(Tags.persistentEngine).GetComponent <SaveSystem>())
        {
            SaveSystem saveSystem = GameObject.FindWithTag(Tags.persistentEngine).GetComponent <SaveSystem>();

            LevelStorage levelStorage = saveSystem.GetComponent <LevelStorage>();
            if (levelStorage)
            {
                levelStorage.ReturnCurrentLevelData();
            }

            if (!saveSystem.isLoadingNewScene)
            {
                FindPlayerStart();
            }
            else
            {
                saveSystem.isLoadingNewScene = false;
            }
        }
    }
Example #10
0
        private void save()
        {
            for (int i = 0; i < rooms.Count; i++)
            {
                if (!RoomHelper.SpawnDefined(rooms[i]))
                {
                    notifications.Push($"Player spawn is not defined in room-{i}", NotificationState.Bad);
                    return;
                }

                if (rooms[i].RoomCompletionType == RoomCompletionType.Warp && !RoomHelper.EndDefined(rooms[i]))
                {
                    notifications.Push($"Room end is not defined in room-{i}", NotificationState.Bad);
                    return;
                }
            }

            LevelStorage.CreateLevel(name, new Level
            {
                Rooms = rooms.ToList()
            });
            notifications.Push("Level has been saved!", NotificationState.Good);
        }
Example #11
0
    public override void OnPush()
    {
        // 如果要显示的是某个图片分类
        if (p.pageType == PicturePageType.Pictype)
        {
            // 从 pic 表中找出所有 type 是 param 的数据行
            // 并且包装成 PicturePage_ItemData
            var sheet    = StaticDataLite.GetSheet("pic");
            var pictype  = this.p.picTypeId;
            var dataList = new List <PictruePage_ItemData>();
            foreach (string key in sheet.Keys)
            {
                var row = sheet[key];
                if (row.Get <string>("type") == pictype)
                {
                    var data = new PictruePage_ItemData
                    {
                        picRow = row,
                    };
                    // check unlock info
                    var unlocked = LevelStorage.IsPictureUnlocked(key);
                    var complete = PlayerStatus.IsPictureComplete(int.Parse(key));
                    var status   = PicturePage_ItemStatus.Locked;
                    if (complete)
                    {
                        status = PicturePage_ItemStatus.Complete;
                    }
                    else if (unlocked)
                    {
                        status = PicturePage_ItemStatus.Unlocked;
                    }
                    data.status = status;
                    dataList.Add(data);
                }
            }
            this.setDataList(dataList);

            // set picture count
            var completePictureCount = 0;
            var pictureCount         = dataList.Count;
            foreach (var data in dataList)
            {
                if (data.status == PicturePage_ItemStatus.Complete)
                {
                    completePictureCount++;
                }
            }
            text_pictureCount.text = completePictureCount + "/" + pictureCount;
        }

        // 如果要显示的是未完成的拼图
        if (p.pageType == PicturePageType.Uncomplete)
        {
            var dataList = new List <PictruePage_ItemData>();
            foreach (var kv in PlayerStatus.uncompletePuzzle)
            {
                var info   = kv.Value;
                var picRow = StaticDataLite.GetRow("pic", info.picId.ToString());

                var data = new PictruePage_ItemData
                {
                    picRow = picRow,
                };
                data.status = PicturePage_ItemStatus.Unlocked;
                dataList.Add(data);
            }
            this.setDataList(dataList);

            text_pictureCount.text = PlayerStatus.uncompletePuzzle.Count.ToString();
        }

        // 如果要显示已完成的图片
        if (p.pageType == PicturePageType.Complete)
        {
            var dataList = new List <PictruePage_ItemData>();
            foreach (var kv in PlayerStatus.completeDic)
            {
                var info   = kv.Value;
                var picId  = info.pid;
                var picRow = StaticDataLite.GetRow("pic", picId.ToString());

                var data = new PictruePage_ItemData
                {
                    picRow = picRow,
                };
                data.status = PicturePage_ItemStatus.Complete;
                dataList.Add(data);
            }
            text_pictureCount.text = dataList.Count.ToString();
            this.setDataList(dataList);
        }
    }
    void OnGUI()
    {
		if (levelStorage == null)
		{
			levelStorage = GameObject.FindObjectOfType<LevelsManager> ().levelStorage;
		}

		EditorGUILayout.Space();

		GUILayout.Label("Level Edit and Creation:", EditorStyles.boldLabel);

		if (levelStorage != null && levelStorage.LevelsCount > 0)
		{
			GUILayout.Label(string.Format("Selected Level: {0} / {1}", selectedLevelId + 1, levelStorage.LevelsCount));
		}

		GUILayout.BeginHorizontal();

		if (GUILayout.Button("Prev", GUILayout.Height(32)))
		{
			if (selectedLevelId > 0)
			{
				if (levelStorage.levelsList.Count > 1)
				{
					selectedLevelId--;
					newLevel = levelStorage.levelsList[selectedLevelId];
				}
			}
		}

		if (GUILayout.Button("Next", GUILayout.Height(32)))
		{
			if (selectedLevelId < levelStorage.levelsList.Count - 1)
			{
				if (levelStorage.levelsList.Count > 1)
				{
					selectedLevelId++;
					newLevel = levelStorage.levelsList[selectedLevelId];
				}
			}

		}

		GUILayout.EndHorizontal();

		DrawLevelInfo();

        EditorGUILayout.Space();

		if (GUILayout.Button("Create New Level", GUILayout.ExpandWidth(true), GUILayout.Height(32)))
		{
			if (levelStorage.LevelsCount == 0)
			{
				selectedLevelId = 0;
			}
			else
			{
				selectedLevelId = levelStorage.LevelsCount;
			}

			newLevel = new Level(selectedLevelId, 10, 1, 1, 3, 100, 200, false, 0, 1f);
			levelStorage.AddNewLevel (newLevel);
		}

		if (GUILayout.Button("Recalculate Eneies Waves in Level", GUILayout.ExpandWidth(true), GUILayout.Height(32)))
		{
			for (int i = 0; i < levelStorage.LevelsCount; i++) {
				levelStorage.levelsList [i].CreateEnemiesWaves (
					levelStorage.levelsList [i].WavesCount,
					levelStorage.levelsList [i].MinEnemyCount,
					levelStorage.levelsList [i].MaxEnemyCount,
					levelStorage.levelsList [i].timeBetwenEnemySpawnMin,
					levelStorage.levelsList [i].timeBetwenEnemySpawnMax
				);
			}

			GameObject.FindObjectOfType<LevelsManager> ().levelStorage = levelStorage;
		}

		if (GUILayout.Button("Delete Selected Level", GUILayout.ExpandWidth(true), GUILayout.Height(32)))
		{
			levelStorage.DeleteLevelById (selectedLevelId);

			if (selectedLevelId > 0) 
			{
				selectedLevelId--;
			}
		}

		EditorGUILayout.Space();

        if (levelStorage != null)
        {
			GUILayout.Label("Get Data From JSON Config to Level Storage:", EditorStyles.boldLabel);

			if (GUILayout.Button("Update Level Storage", GUILayout.ExpandWidth(true), GUILayout.Height(32)))
			{
				levelStorage = ConfigManager.GetLevelStorage();
				GameObject.FindObjectOfType<LevelsManager> ().levelStorage = levelStorage;
			}

			GUILayout.Label("Set Data From Level Storage to JSON Config:", EditorStyles.boldLabel);

			if (GUILayout.Button("Update JSON Config", GUILayout.ExpandWidth(true), GUILayout.Height(32)))
            {
				ConfigManager.SaveLevelStorage(levelStorage);
            }

			GUILayout.Label(string.Format("JSON Config stored in:\n{0}\n", ConfigManager.ConfigPath));
        }

		EditorGUILayout.Space();

		if (GUILayout.Button("Open Config Folder", GUILayout.ExpandWidth(true), GUILayout.Height(32)))
		{
			EditorUtility.RevealInFinder (Path.GetDirectoryName(ConfigManager.ConfigPath));
		}

    }
Example #13
0
 private void Awake()
 {
             #if !UNITY_WEBPLAYER
     levelStorage = this.GetComponent <LevelStorage>();
             #endif
 }
Example #14
0
 private void InitLevelStorage()
 {
     LevelStorage = new LevelStorage();
 }
Example #15
0
 void Awake()
 {
     Instance = this;
     levels = Resources.LoadAll<Level>("Levels");
     Debug.Log(levels.Length);
 }