Ejemplo n.º 1
0
    private void initDefaultKeys(bool tryLoadUserSettings, string nameAddendum)
    {
        dynamicKeys = new Dictionary <string, KeySetting>();
        if (tryLoadUserSettings)
        {
            if (!SaveAndLoadJson.LoadDictionary(filePath(nameAddendum), out keySettings))
            {
                Debug.Log("could not load settings, using hard coded defaults");
            }
            else
            {
                return;
            }
        }

        //these keys must match up with other parts of the program using them
        //these settings will eventually be loaded from a users settings
        keySettings = new Dictionary <string, KeySetting> {
            { "mainAction", new KeySetting(new KeyCode[]   { KeyCode.E }, KeypressState.buttonDown) },

            { "moveUp", new KeySetting(new KeyCode[]   { KeyCode.W }, KeypressState.buttonHeld) },
            { "moveDown", new KeySetting(new KeyCode[]   { KeyCode.S }, KeypressState.buttonHeld) },
            { "moveLeft", new KeySetting(new KeyCode[]   { KeyCode.A }, KeypressState.buttonHeld) },
            { "moveRight", new KeySetting(new KeyCode[]   { KeyCode.D }, KeypressState.buttonHeld) },

            { "card1", new KeySetting(new KeyCode[]   { KeyCode.Alpha1 }, KeypressState.buttonDown) },
            { "card2", new KeySetting(new KeyCode[]   { KeyCode.Alpha2 }, KeypressState.buttonDown) },
            { "card3", new KeySetting(new KeyCode[]   { KeyCode.Alpha3 }, KeypressState.buttonDown) },
            { "card4", new KeySetting(new KeyCode[]   { KeyCode.Alpha4 }, KeypressState.buttonDown) },
        };
    }
Ejemplo n.º 2
0
	public void loadDeck(string deckName) {
		clearDeck();
		
		//TODO add confirmation screen when loading/exiting deck editor
		JsonDeck deckLoad;
		if(SaveAndLoadJson.loadStruct( getDeckPath() + "/" + deckName, out deckLoad) == false) {
			Debug.LogError("selected deck does not exist in " + getDeckPath());
			return;
		}

		Card c = null;
		object obj;
		for(int i = 0; i < deckLoad.cardTypeName.Length; i++) {
			obj = Activator.CreateInstance(Type.GetType(deckLoad.cardTypeName[i]));
			if(obj != null) {
				if(obj is Card) {
					c = (Card)obj;
					addCardToDeck(c);
					continue;
				}
			}
			Debug.LogError("card " + deckLoad.cardTypeName[i]+ " could not be loaded\n" +
				"check that the card class with that name exists");
		}

		this.deckName.text = deckName;
		
	}
Ejemplo n.º 3
0
	/// <summary>
	/// get the deck path
	/// enemy decks are stored in the resource folder so they are added to build
	/// </summary>
	/// <returns></returns>
	private string getDeckPath() {
		if(playerDeck) {
			return SaveAndLoadJson.getBaseFilePath(Deck.playerDecks);
		} else {
			return SaveAndLoadJson.getResourcePath(Deck.baddyDecks,"");
		}
	}
Ejemplo n.º 4
0
    private bool loadDeckFromMemory(string deckName)
    {
        JsonDeck deck;
        bool     loadSuccess = false;

        if (playerDeck)
        {
            loadSuccess = SaveAndLoadJson.loadStruct(SaveAndLoadJson.getBaseFilePath(playerDecks, deckName), out deck);
        }
        else
        {
            loadSuccess = SaveAndLoadJson.loadStruct(SaveAndLoadJson.getResourcePath(baddyDecks, deckName), out deck);
        }
        if (!loadSuccess)
        {
            if (!SaveAndLoadJson.loadStruct(SaveAndLoadJson.getResourcePath(baddyDecks, "errorDeck"), out deck))
            {
                return(false);
            }
        }
        //get card class types from names
        Type[] cardClasses = new Type[deck.cardTypeName.Length];
        for (int i = 0; i < deck.cardTypeName.Length; i++)
        {
            cardClasses[i] = Type.GetType(deck.cardTypeName[i]);
        }

        addCardsToDeck(cardClasses);


        return(loadSuccess);
    }
Ejemplo n.º 5
0
    //TODO change this to use assent bundles at some point
    /// <summary>
    /// load the text Assent CardAttr
    /// </summary>
    /// <param name="cardName"></param>
    /// <param name="cardAttr"></param>
    /// <returns></returns>
    public static bool LoadBasicCardAttributesFromJsonInResorceFolder(string cardName, out BasicCardAttributes cardAttr)
    {
        cardAttr = default(BasicCardAttributes);
        TextAsset cardAttrJson = PrefabResorceLoader.Instance.loadTextAsset(cardName + "/CardAttr");         //Note: resorce.load does not need file extension
        bool      loaded       = false;

        if (cardAttrJson != null)
        {
            loaded = SaveAndLoadJson.loadStructFromString(out cardAttr, cardAttrJson.text);
        }
        if (!loaded)
        {
            if (Application.isEditor)
            {
                //TODO create CardPramSetter
                Debug.Log("Card attributes not set" + cardName + "\n"
                          + "create using editor using CardPramSetter");
            }
            else
            {
                Debug.LogError("something has gone wrong, there are no card Attributes in " + cardName);
            }
        }
        return(loaded);
    }
Ejemplo n.º 6
0
    /// <summary>
    /// make tempSettings the current settings
    /// </summary>
    /// <param name="nameAddendum">many Settings can be saved
    /// with slightly differing names leave empty if there is only one setting</param>
    /// <returns>save to disk worked or not</returns>
    public bool setAndSaveKeySettings(string nameAddendum)
    {
        keySettings = tempSettings;
        bool worked = SaveAndLoadJson.saveDictionary(filePath(nameAddendum), keySettings);

        if (!worked)
        {
            Debug.LogError("keySettings not saved!");
        }
        return(worked);
    }
Ejemplo n.º 7
0
 //TODO abstract which type is loaded at start
 public void loadDeckType(Toggle deckType)
 {
     if (deckType.isOn)
     {
         loadDeckFolder(SaveAndLoadJson.getBaseFilePath(Deck.playerDecks));
     }
     else
     {
         loadDeckFolder(SaveAndLoadJson.getResourcePath(Deck.baddyDecks));
     }
 }
Ejemplo n.º 8
0
    private void loadSoundLevels()
    {
        SoundLevelsDiskSave loadedLevels;
        bool fileExists = SaveAndLoadJson.loadStruct(soundFilePath(), out loadedLevels);

        if (fileExists)
        {
            setMusicVolume(loadedLevels.musicLevel);
            setSfxVolume(loadedLevels.sfxLevel);
        }
    }
Ejemplo n.º 9
0
	public void saveDeck() {

		string[] cardClassNames = new string[listOfCards.Count];
		BasicCardAttributes[] cardsAttributes= new BasicCardAttributes[listOfCards.Count];
		Card c;
		int index = 0;
		foreach(CardDisplayController item in listOfCards) { 
			c = item.getCardRepresented();
			cardClassNames[index] = c.GetType().Name;
			//WARNING for now all enemy cards stay in decks when used
			if(!playerDeck) {
				c.basicAttrabutes.removeOnDraw = false;
			}
			cardsAttributes[index++] = c.basicAttrabutes;
		
		}
		
		JsonDeck deckSave = new JsonDeck(cardClassNames, cardsAttributes);
		SaveAndLoadJson.saveStruct(getDeckPath() + deckName.text, deckSave);
	}
Ejemplo n.º 10
0
 // Use this for initialization
 void Start()
 {
     loadDeckFolder(SaveAndLoadJson.getBaseFilePath(Deck.playerDecks));
 }
Ejemplo n.º 11
0
    private void saveSoundLevels()
    {
        SoundLevelsDiskSave savingFile = new SoundLevelsDiskSave(musicVolume, sfxVolume);

        SaveAndLoadJson.saveStruct(soundFilePath(), savingFile);
    }
Ejemplo n.º 12
0
 private string soundFilePath()
 {
     return(SaveAndLoadJson.getBaseFilePath() + folderName + "/" + fileName);
 }
Ejemplo n.º 13
0
    void OnGUI()
    {
        card         = (MonoScript)EditorGUILayout.ObjectField("card script", card, typeof(MonoScript), false);
        cardFilePath = GUILayout.TextField(cardFilePath);
        if (!cardFilePath.EndsWith("/"))
        {
            cardFilePath += "/";
        }

        if (GUILayout.Button("set prefab location based on cardClass"))
        {
            cardFilePath = card.GetClass().Name + "/";
            //default names
            cardAttrabutes.cardIconPath        = cardFilePath + "icon";
            cardAttrabutes.cardArtPath         = cardFilePath + "card art";
            cardAttrabutes.cardDescriptionPath = cardFilePath + "description";
            cardAttrabutes.cardName            = card.GetClass().Name;
        }

        //load existing card attributes

        TextAsset tempChangeCheck = existingCardAttr;

        existingCardAttr = (TextAsset)EditorGUILayout.ObjectField("CardAttr", existingCardAttr, typeof(TextAsset), false);
        if (GUILayout.Button("update Existing CardAttr") || tempChangeCheck != existingCardAttr)
        {
            if (existingCardAttr != null)
            {
                SaveAndLoadJson.loadStructFromString(out cardAttrabutes, existingCardAttr.text);
                string[] filePath = AssetDatabase.GetAssetPath(existingCardAttr).Split(new char[] { '/' });
                int      index    = 0;
                while (index < filePath.Length)
                {
                    if (filePath[index++] == "Resources")
                    {
                        break;
                    }
                }
                cardFilePath = "";
                for (int i = index; i < filePath.Length - 1; i++)
                {
                    cardFilePath += filePath[i] + "/";
                }
            }

            //default names
            cardAttrabutes.cardIconPath        = cardFilePath + "icon";
            cardAttrabutes.cardArtPath         = cardFilePath + "card art";
            cardAttrabutes.cardDescriptionPath = cardFilePath + "description";
        }

        cardAttrabutes.cardName                  = EditorGUILayout.TextField("card displayed name", cardAttrabutes.cardName);
        cardAttrabutes.cardResorceCost           = EditorGUILayout.FloatField("cost", cardAttrabutes.cardResorceCost);
        cardAttrabutes.cardReloadTime_seconds    = EditorGUILayout.FloatField("slot reload time", cardAttrabutes.cardReloadTime_seconds);
        cardAttrabutes.removeOnDraw              = EditorGUILayout.Toggle("removedOnDraw", cardAttrabutes.removeOnDraw);
        cardAttrabutes.probabilityOfDraw         = EditorGUILayout.FloatField("draw probability", cardAttrabutes.probabilityOfDraw);
        cardAttrabutes.numberOfCardAllowedInDeck = EditorGUILayout.IntField("Numb Allowed In Deck", cardAttrabutes.numberOfCardAllowedInDeck);
        cardAttrabutes.cardElements              = (DamageTypes)EditorGUILayout.EnumMaskPopup("setCardElements", cardAttrabutes.cardElements);
        cardAttrabutes.cardType                  = (CardLocation)EditorGUILayout.EnumMaskPopup("setCardType(s)", cardAttrabutes.cardType);


        GUILayout.Label("icon,card art, and card description (.txt)\nmust be added to the created folder");

        GUIStyle colorset = new GUIStyle(GUI.skin.button);

        if (timeLeftOnScreen_sec > 0)
        {
            colorset.normal.textColor = new Color(0f, 0.4f, 0f);
            timeLeftOnScreen_sec     -= Time.deltaTime;
        }
        else
        {
            colorset.normal.textColor = Color.black;
        }

        if (GUILayout.Button("create card information", colorset) && cardFilePath != "/")
        {
            if (!Directory.Exists(SaveAndLoadJson.getResourcePath(cardFilePath)))
            {
                Directory.CreateDirectory(SaveAndLoadJson.getResourcePath(cardFilePath));
            }

            //string printer = "";
            //SaveAndLoadJson.saveStructToString(cardAttrabutes,out printer);
            if (SaveAndLoadJson.saveStruct(SaveAndLoadJson.getResourcePath(cardFilePath + "CardAttr"), cardAttrabutes))
            {
                timeLeftOnScreen_sec = timeOnScreenMax_sec;
            }
            AssetDatabase.Refresh();
        }
    }