Example #1
0
    /**
     * this method gets the custom stage data from database
     * @param id - id of the custom stage requested
     */
    private IEnumerator getCustomStageFromFirebase(string id)
    {
        var DBTask = DBreference.Child("customStage").Child(id).GetValueAsync();

        yield return(new WaitUntil(predicate: () => DBTask.IsCompleted));

        if (DBTask.Exception != null)
        {
            Debug.LogWarning(message: $"Failed to register task with {DBTask.Exception}");
        }
        else
        {
            DataSnapshot snapshot = DBTask.Result;
            if (snapshot.Value == null)
            {
                if (errorMessage != null)
                {
                    errorMessage.SetActive(true);
                }
            }
            else
            {
                if (errorMessage != null)
                {
                    errorMessage.SetActive(false);
                }
                string     json        = snapshot.GetRawJsonValue();
                GameObject dataManager = GameObject.FindGameObjectWithTag("DataManager");
                customStage      = CustomStage.CreateFromJSON(json);
                customStageCheck = true;
                Debug.Log(customStage.questions[0]);
                SceneManager.LoadScene("test");
            }
        }
    }
    public void AddContainer(CustomStage c)
    {
        GameObject stage = GetComponent <UIScrollList>().CreateItem(customLevelPrefabs[c.world]).gameObject;

        stage.GetComponent <CustomLevelButton>().world = c.world;
        stage.GetComponent <CustomLevelButton>().level = Flow.customStages.IndexOf(c);
    }
	public void SendToFriend(CustomStage level)
	{
		if(isRankingScreen)
		{
			scroll = Flow.config.GetComponent<ConfigManager>().challengeInviteScroll;
			scroll.transform.parent = transform;
			scroll.transform.localPosition = new Vector3(-0.1220818f, 0.1973438f, -7.011475f);
		}
		
		currentCustomStage = level;
		EnteredInvite();
	}
    public void SendToFriend(CustomStage level)
    {
        if (isRankingScreen)
        {
            scroll = Flow.config.GetComponent <ConfigManager>().challengeInviteScroll;
            scroll.transform.parent        = transform;
            scroll.transform.localPosition = new Vector3(-0.1220818f, 0.1973438f, -7.011475f);
        }

        currentCustomStage = level;
        EnteredInvite();
    }
Example #5
0
    /**
     * this method gets the custom stage data from database - this method is for testing only
     * @param id - id of the custom stage requested
     */
    private IEnumerator getCustomStageFromFirebase(string id)
    {
        var DBTask = DBreference.Child("customStage").Child(id).GetValueAsync();

        yield return(new WaitUntil(predicate: () => DBTask.IsCompleted));

        if (DBTask.Exception != null)
        {
            Debug.LogWarning(message: $"Failed to register task with {DBTask.Exception}");
        }
        else
        {
            DataSnapshot snapshot    = DBTask.Result;
            string       json        = snapshot.GetRawJsonValue();
            CustomStage  customStage = CustomStage.CreateFromJSON(json);
            Debug.Log(customStage.questions[0]);
        }
    }
Example #6
0
    /**
     * this method handles OnClick for finish button in select question UI
     */
    public void clickFinishButton()
    {
        List <string> chosenQuestionsList = GameObject.Find("QuestionsManager").GetComponent <CustomStageChooseQuestions>().getChosenQuestionsList();

        foreach (string chosenQuestion in chosenQuestionsList)
        {
            Debug.Log(chosenQuestion);
        }
        foreach (string pokemon in pokemonSelected)
        {
            Debug.Log(pokemon);
        }
        Debug.Log(background);
        CustomStage customStage = new CustomStage(pokemonSelected, chosenQuestionsList, background);
        string      json        = customStage.SaveToJSON();

        StartCoroutine(writeCustomStageToFirebase(json));
        //StartCoroutine(queryQuestion("1_hard_5_question"));
        //StartCoroutine(getCustomStageFromFirebase("12345"));
    }
Example #7
0
    public static void AddCustomStage(List <List <int> > customTileset, int customWorld, int numberOfMines, string name, int id, bool isNew = false, bool isChallenge = false,
                                      string creatorName = "")
    {
        if (customStages == null)
        {
            customStages = new List <CustomStage>();
        }
        CustomStage c = new CustomStage();

        c.tileset       = customTileset;
        c.world         = customWorld;
        c.numberOfMines = numberOfMines;
        c.name          = name;
        c.id            = id;
        c.isNew         = isNew;
        c.isChallenge   = isChallenge;
        c.creatorName   = creatorName;
        customStages.Add(c);

        UpdateXML();
    }
Example #8
0
    void readFromXML()
    {
        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(rawXML);

        foreach (XmlNode masterNode in xmlDoc.SelectNodes("Document/Worlds/World"))
        {
            World tempWorld = new World();
            tempWorld.levelDict = new Dictionary <int, Level>();
            tempWorld.id        = masterNode.Attributes["ID"].InnerText.ToInt32();

            foreach (XmlNode subNode in masterNode.SelectNodes("Levels/Level"))
            {
                Level tempLevel = new Level();
                tempLevel.tileset    = new List <int>();
                tempLevel.id         = subNode.Attributes["ID"].InnerText.ToInt32();
                tempLevel.lastUpdate = DateTime.Parse(subNode.SelectSingleNode("Update").InnerText);

                string s = subNode.SelectSingleNode("Tileset").InnerText;
                for (int i = 0; i < s.Length; i++)
                {
                    tempLevel.tileset.Add(int.Parse(s[i].ToString()));
                }
                tempWorld.levelDict.Add(tempLevel.id, tempLevel);
            }

            Flow.worldDict.Add(tempWorld.id, tempWorld);
        }

        foreach (XmlNode customStage in xmlDoc.SelectNodes("Document/CustomStages/CustomStage"))
        {
            List <List <int> > customTileset = new List <List <int> >();
            string             all64         = customStage.SelectSingleNode("Tileset").InnerText;
            int customMines = 0;
            for (int i = 0; i < 8; i++)
            {
                List <int> singleRow = new List <int>();
                for (int j = 0; j < 8; j++)
                {
                    if (int.Parse(all64[i * 8 + j].ToString()) == 1)
                    {
                        customMines++;
                    }
                    singleRow.Add(int.Parse(all64[i * 8 + j].ToString()));
                }
                customTileset.Add(singleRow);
            }

            if (Flow.customStages == null)
            {
                Flow.customStages = new List <CustomStage>();
            }
            CustomStage c = new CustomStage();
            c.tileset       = customTileset;
            c.world         = int.Parse(customStage.SelectSingleNode("World").InnerText);
            c.numberOfMines = customMines;
            c.name          = customStage.Attributes["Name"].InnerText;
            c.id            = int.Parse(customStage.SelectSingleNode("ID").InnerText);
            Flow.customStages.Add(c);

            //Debug.Log("adicionei o level " + customStage.Attributes["Name"].InnerText);
            //Debug.Log("o tileset dele era " + all64);
        }

        /*foreach(CustomStage c in Flow.customStages)
         * {
         *      string testTileset = "";
         *      foreach(List<int> listInt in c.tileset)
         *      {
         *              foreach(int i in listInt) testTileset += i;
         *      }
         *      Debug.Log(testTileset);
         * }*/

        logoPanel.StartTransition(UIPanelManager.SHOW_MODE.BringInForward);
    }
Example #9
0
	void readFromXML()
	{
		XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(rawXML);
		
		foreach(XmlNode masterNode in xmlDoc.SelectNodes("Document/Worlds/World"))
		{
			World tempWorld = new World();
			tempWorld.levelDict = new Dictionary<int, Level>();
			tempWorld.id = masterNode.Attributes["ID"].InnerText.ToInt32();
			
			foreach(XmlNode subNode in masterNode.SelectNodes("Levels/Level"))
			{
				Level tempLevel = new Level();
				tempLevel.tileset = new List<int>();
				tempLevel.id = subNode.Attributes["ID"].InnerText.ToInt32();
				tempLevel.lastUpdate = DateTime.Parse(subNode.SelectSingleNode("Update").InnerText);
				
				string s = subNode.SelectSingleNode("Tileset").InnerText;
				for(int i = 0; i< s.Length; i++)
				{
					tempLevel.tileset.Add(int.Parse(s[i].ToString()));
				}
				tempWorld.levelDict.Add(tempLevel.id, tempLevel);
			}
			
			Flow.worldDict.Add(tempWorld.id, tempWorld);
		}
		
		foreach(XmlNode customStage in xmlDoc.SelectNodes("Document/CustomStages/CustomStage"))
		{
			List<List<int>> customTileset = new List<List<int>>();
			string all64 = customStage.SelectSingleNode("Tileset").InnerText;
			int customMines = 0;
			for(int i = 0; i< 8; i++)
			{
				List<int> singleRow = new List<int>();
				for(int j = 0; j < 8; j++)
				{
					if(int.Parse(all64[i*8+j].ToString()) == 1) customMines++;
					singleRow.Add(int.Parse(all64[i*8+j].ToString()));
				}
				customTileset.Add(singleRow);
			}
			
			if(Flow.customStages == null)
			{
				Flow.customStages = new List<CustomStage>();
			}
			CustomStage c = new CustomStage();
			c.tileset = customTileset;
			c.world = int.Parse(customStage.SelectSingleNode("World").InnerText);
			c.numberOfMines = customMines;
			c.name = customStage.Attributes["Name"].InnerText;
			c.id = int.Parse(customStage.SelectSingleNode("ID").InnerText);
			Flow.customStages.Add(c);
			
			//Debug.Log("adicionei o level " + customStage.Attributes["Name"].InnerText);
			//Debug.Log("o tileset dele era " + all64);
		}
		
		/*foreach(CustomStage c in Flow.customStages)
		{
			string testTileset = "";
			foreach(List<int> listInt in c.tileset)
			{
				foreach(int i in listInt) testTileset += i;
			}
			Debug.Log(testTileset);
		}*/
		
		logoPanel.StartTransition(UIPanelManager.SHOW_MODE.BringInForward);
	}
Example #10
0
	void CreateChallengeContainerImproved(IJSonObject item, IJSonObject data)
	{
		CustomStage cs = new CustomStage();
		cs.creatorName = item["username"].ToString();
		cs.id = item["customLevelID"].Int32Value;
		cs.isChallenge = true;
		if(item["time"].IsNull && item["isMe"].BooleanValue)
		{
			cs.isNew = true;
		}
		else
		{
			cs.isNew = false;
		}
		cs.name = item["name"].ToString();
		cs.world = item["worldID"].Int32Value - 3;
		cs.hostID = item["creatorID"].StringValue;
		cs.isMe = item["isMe"].BooleanValue;
		
		int numberOfMines = 0;
		string testTileset = "";
		List<List<int>> tileset = new List<List<int>>();
		for(int i = 0; i < 8; i++)
		{
			List<int> row = new List<int>();
			for(int j = 0; j < 8; j++)
			{
				testTileset += item["tileset"].StringValue[i*8+j].ToString();
				row.Add(int.Parse(item["tileset"].StringValue[i*8+j].ToString()));
				if(int.Parse(item["tileset"].StringValue[i*8+j].ToString())==1) numberOfMines++;
			}
			tileset.Add(row);
		}
		cs.numberOfMines = numberOfMines;
		cs.tileset = tileset;
		//falta definir as estrelas, se for ter mesmo
		
		//Debug.Log("chegou um challenge de tileset " + testTileset);
		
		Flow.customGames.Add(cs);
		
		if(item["creatorID"].StringValue != Save.GetString(PlayerPrefsKeys.ID) && !item["isMe"].BooleanValue)
		{
			//Debug.Log("non me interessa pq n tem nada a ver comigo");
			return;
		}
		
		if(!cs.isNew)
		{
			foreach(CustomStage c in Flow.customGames)
			{
				if(c.id == cs.id && Flow.customGames.IndexOf(c)!=Flow.customGames.Count-1 && (c.isMe || item["creatorID"].StringValue == Save.GetString(PlayerPrefsKeys.ID)))
				{
					//Debug.Log("impedindo que crie um container novo para um ranking que ja existe");
					return;
				}
			}
			foreach(IJSonObject subItem in data.ArrayItems)
			{
				//Debug.Log(subItem);
				if(subItem["customLevelID"].Int32Value == cs.id && subItem["time"].IsNull && subItem["isMe"].BooleanValue)
				{
					//Debug.Log("impedindo que crie um container novo para um uma challenge nova que vai existir");
					return;
				}
			}
		}
		
		IUIListObject g = null;
		if(cs.isNew)
		{
			g = newPanel.transform.FindChild("NewScroll").GetComponent<UIScrollList>().CreateItem(newContainerPrefab);
			g.transform.FindChild("Name").GetComponent<SpriteText>().Text = cs.creatorName;
			g.transform.FindChild("Mines").GetComponent<SpriteText>().Text = "Mines: " + cs.numberOfMines;
			g.transform.FindChild("StageName").GetComponent<SpriteText>().Text = cs.name;
			g.transform.FindChild("World"+(1+cs.world).ToString()).gameObject.SetActive(true);
			
			//Debug.Log("adicionei no novo");
		}
		else if(!cs.isNew)
		{
			g = oldPanel.transform.FindChild("OldScroll").GetComponent<UIScrollList>().CreateItem(oldContainerPrefab);
			g.transform.FindChild("Name").GetComponent<SpriteText>().Text = cs.name;
			g.transform.FindChild("Mines").GetComponent<SpriteText>().Text = "Mines: " + cs.numberOfMines;
			g.transform.FindChild("Host").GetComponent<SpriteText>().Text = "Hosted by " + cs.creatorName;
			g.transform.FindChild("World"+(1+cs.world).ToString()).gameObject.SetActive(true);
			
			//Debug.Log("adicionei no velho");
		}
		
		g.transform.GetComponent<ChallengesButton>().challengeIndex = Flow.customGames.IndexOf(cs);
		g.transform.GetComponent<ChallengesButton>().gameIndex = item["customGameID"].Int32Value;
		//Debug.Log("custom game id (challenge): " + g.transform.GetComponent<ChallengesButton>().gameIndex);
		QuickSwapToNew();
		
		foreach(CustomStage c in Flow.customStages)
		{
			if(c.id == cs.id || (Flow.DecodeList(c.tileset) == Flow.DecodeList(cs.tileset) && c.world == cs.world) && c.name == cs.name)
			{
				g.transform.GetComponent<ChallengesButton>().customLevelsIndex = Flow.customStages.IndexOf(c);
				return;
			}
		}
		
		Flow.AddCustomStage(cs.tileset, cs.world, cs.numberOfMines, cs.name, cs.id, cs.isNew, cs.isChallenge, cs.creatorName);
		g.transform.GetComponent<ChallengesButton>().customLevelsIndex = Flow.customStages.Count-1;
		customLevelScroll.AddContainer(cs);
		Debug.Log("adicionei o level " + cs.name);
	}
Example #11
0
    void CreateChallengeContainerImproved(IJSonObject item, IJSonObject data)
    {
        CustomStage cs = new CustomStage();

        cs.creatorName = item["username"].ToString();
        cs.id          = item["customLevelID"].Int32Value;
        cs.isChallenge = true;
        if (item["time"].IsNull && item["isMe"].BooleanValue)
        {
            cs.isNew = true;
        }
        else
        {
            cs.isNew = false;
        }
        cs.name   = item["name"].ToString();
        cs.world  = item["worldID"].Int32Value - 3;
        cs.hostID = item["creatorID"].StringValue;
        cs.isMe   = item["isMe"].BooleanValue;

        int                numberOfMines = 0;
        string             testTileset   = "";
        List <List <int> > tileset       = new List <List <int> >();

        for (int i = 0; i < 8; i++)
        {
            List <int> row = new List <int>();
            for (int j = 0; j < 8; j++)
            {
                testTileset += item["tileset"].StringValue[i * 8 + j].ToString();
                row.Add(int.Parse(item["tileset"].StringValue[i * 8 + j].ToString()));
                if (int.Parse(item["tileset"].StringValue[i * 8 + j].ToString()) == 1)
                {
                    numberOfMines++;
                }
            }
            tileset.Add(row);
        }
        cs.numberOfMines = numberOfMines;
        cs.tileset       = tileset;
        //falta definir as estrelas, se for ter mesmo

        //Debug.Log("chegou um challenge de tileset " + testTileset);

        Flow.customGames.Add(cs);

        if (item["creatorID"].StringValue != Save.GetString(PlayerPrefsKeys.ID) && !item["isMe"].BooleanValue)
        {
            //Debug.Log("non me interessa pq n tem nada a ver comigo");
            return;
        }

        if (!cs.isNew)
        {
            foreach (CustomStage c in Flow.customGames)
            {
                if (c.id == cs.id && Flow.customGames.IndexOf(c) != Flow.customGames.Count - 1 && (c.isMe || item["creatorID"].StringValue == Save.GetString(PlayerPrefsKeys.ID)))
                {
                    //Debug.Log("impedindo que crie um container novo para um ranking que ja existe");
                    return;
                }
            }
            foreach (IJSonObject subItem in data.ArrayItems)
            {
                //Debug.Log(subItem);
                if (subItem["customLevelID"].Int32Value == cs.id && subItem["time"].IsNull && subItem["isMe"].BooleanValue)
                {
                    //Debug.Log("impedindo que crie um container novo para um uma challenge nova que vai existir");
                    return;
                }
            }
        }

        IUIListObject g = null;

        if (cs.isNew)
        {
            g = newPanel.transform.FindChild("NewScroll").GetComponent <UIScrollList>().CreateItem(newContainerPrefab);
            g.transform.FindChild("Name").GetComponent <SpriteText>().Text      = cs.creatorName;
            g.transform.FindChild("Mines").GetComponent <SpriteText>().Text     = "Mines: " + cs.numberOfMines;
            g.transform.FindChild("StageName").GetComponent <SpriteText>().Text = cs.name;
            g.transform.FindChild("World" + (1 + cs.world).ToString()).gameObject.SetActive(true);

            //Debug.Log("adicionei no novo");
        }
        else if (!cs.isNew)
        {
            g = oldPanel.transform.FindChild("OldScroll").GetComponent <UIScrollList>().CreateItem(oldContainerPrefab);
            g.transform.FindChild("Name").GetComponent <SpriteText>().Text  = cs.name;
            g.transform.FindChild("Mines").GetComponent <SpriteText>().Text = "Mines: " + cs.numberOfMines;
            g.transform.FindChild("Host").GetComponent <SpriteText>().Text  = "Hosted by " + cs.creatorName;
            g.transform.FindChild("World" + (1 + cs.world).ToString()).gameObject.SetActive(true);

            //Debug.Log("adicionei no velho");
        }

        g.transform.GetComponent <ChallengesButton>().challengeIndex = Flow.customGames.IndexOf(cs);
        g.transform.GetComponent <ChallengesButton>().gameIndex      = item["customGameID"].Int32Value;
        //Debug.Log("custom game id (challenge): " + g.transform.GetComponent<ChallengesButton>().gameIndex);
        QuickSwapToNew();

        foreach (CustomStage c in Flow.customStages)
        {
            if (c.id == cs.id || (Flow.DecodeList(c.tileset) == Flow.DecodeList(cs.tileset) && c.world == cs.world) && c.name == cs.name)
            {
                g.transform.GetComponent <ChallengesButton>().customLevelsIndex = Flow.customStages.IndexOf(c);
                return;
            }
        }

        Flow.AddCustomStage(cs.tileset, cs.world, cs.numberOfMines, cs.name, cs.id, cs.isNew, cs.isChallenge, cs.creatorName);
        g.transform.GetComponent <ChallengesButton>().customLevelsIndex = Flow.customStages.Count - 1;
        customLevelScroll.AddContainer(cs);
        Debug.Log("adicionei o level " + cs.name);
    }
	public void AddContainer(CustomStage c)
	{
		GameObject stage = GetComponent<UIScrollList>().CreateItem(customLevelPrefabs[c.world]).gameObject;
		stage.GetComponent<CustomLevelButton>().world = c.world;
		stage.GetComponent<CustomLevelButton>().level = Flow.customStages.IndexOf(c);
	}
Example #13
0
	public static void AddCustomStage(List<List<int>> customTileset, int customWorld, int numberOfMines, string name, int id, bool isNew = false, bool isChallenge = false,
		string creatorName = "")
	{
		if(customStages == null)
		{
			customStages = new List<CustomStage>();
		}
		CustomStage c = new CustomStage();
		c.tileset = customTileset;
		c.world = customWorld;
		c.numberOfMines = numberOfMines;
		c.name = name;
		c.id = id;
		c.isNew = isNew;
		c.isChallenge = isChallenge;
		c.creatorName = creatorName;
		customStages.Add(c);
		
		UpdateXML();
	}