Example #1
0
    /// <summary>
    /// [COROUTINE] loads card typeson web builds.
    /// </summary>
    private IEnumerator loadCardTypesWeb()
    {
        //form the web request
        string filePath = Application.streamingAssetsPath + '/' + path;
        //while (filePath.StartsWith("/")) filePath = filePath.Substring(1); //remove any leading /'s
        WWW request = new WWW(filePath);

        //wait for the request to load
        yield return(request);

        //show error if there was one
        if (request.error != null)
        {
            Debug.LogError("Error loading card types:\n" + request.error);
            yield break;
        }

        //or, if we were successful, create a new stream and fill it with the contents of the web request:
        using (MemoryStream cardTypesStream = new MemoryStream())    //create the stream
        {
            StreamWriter writer = new StreamWriter(cardTypesStream); //used to write to it
            writer.Write(request.text);                              //write contents of the request
            writer.Flush();                                          //make sure it gets processed
            cardTypesStream.Position = 0;                            //send the stream back to the start

            //now we can finally load the decks
            types = CardTypeCollection.Load(cardTypesStream, filePath);
        }

        Debug.Log(types.cardTypes.Count + " card types loaded.");
    }
Example #2
0
    /// <summary>
    /// [COROUTINE] loads the card types.  This version is for PC builds
    /// </summary>
    private IEnumerator loadCardTypesPC()
    {
        //wait for the dependency manager to exist before we do this
        while (DependencyManagerScript.instance == null)
        {
            yield return(null);
        }

        //also wait for enemies to be loaded
        while (DependencyManagerScript.instance.enemyDepenciesHandled == false)
        {
            yield return(null);
        }

        //load base game cards
        string filePath = Path.Combine(Application.streamingAssetsPath, path);

        using (FileStream stream = new FileStream(filePath, FileMode.Open))
            types = CardTypeCollection.Load(stream, filePath);

        foreach (PlayerCardData baseCard in types.cardTypes)
        {
            baseCard.isModded = false; //flag base game cards as being from the base game
        }
        //find mod files
        DirectoryInfo modDir = new DirectoryInfo(Path.Combine(Application.streamingAssetsPath, modPath)); //mod folder

        FileInfo[] modFiles = modDir.GetFiles("*.xml");                                                   //file list

        //load the files
        List <CardTypeCollection> modCardCollections = new List <CardTypeCollection>();

        foreach (FileInfo f in modFiles)
        {
            Debug.Log("found card mod file: " + f.Name);
            using (FileStream stream = new FileStream(f.FullName, FileMode.Open))
                modCardCollections.Add(CardTypeCollection.Load(stream, f.FullName));
        }

        //get the dependency manager to sort/cull the list
        modCardCollections = DependencyManagerScript.instance.handleCardFileDependencies(modCardCollections);

        foreach (CardTypeCollection modTypes in modCardCollections)
        {
            foreach (PlayerCardData moddedCard in modTypes.cardTypes)
            {
                //mark the definition as modded
                moddedCard.isModded = true;

                //find the existing version of this enemy
                PlayerCardData existingCard = null;
                foreach (PlayerCardData baseCard in types.cardTypes)
                {
                    if (baseCard.cardName == moddedCard.cardName)
                    {
                        existingCard = baseCard;
                        break;
                    }
                }

                //replace the enemy if it exists already, and add it if it doesnt
                if (existingCard != null)
                {
                    types.cardTypes.Remove(existingCard);
                    types.cardTypes.Add(moddedCard);
                    Debug.Log("Overwriting card: " + existingCard.cardName);
                }
                else
                {
                    types.cardTypes.Add(moddedCard);
                }
            }
        }

        yield break;
    }