Esempio n. 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.");
    }
Esempio n. 2
0
    /// <summary>
    /// returns a new CardTypeCollection loaded from the provided stream, and stores the given path into it
    /// </summary>
    public static CardTypeCollection Load(Stream stream, string filePath)
    {
        XmlSerializer      serializer = new XmlSerializer(typeof(CardTypeCollection));
        CardTypeCollection result     = serializer.Deserialize(stream) as CardTypeCollection;

        result.filePath = filePath;
        return(result);
    }
    /// <summary>
    /// event handler for card types being reloaded.  Updates display
    /// </summary>
    private void cardTypesReloaded(CardTypeCollection newTypes)
    {
        //bail if we arent showing anything
        if (data == null)
        {
            return;
        }

        //if we are, then find it in the list and reload it
        StartCoroutine(PreviewCard(newTypes.cardTypes.Find(c => c.cardName == data.cardName)));

        //if data is now null, throw a warning
        if (data == null)
        {
            Debug.LogWarning("The card types were reloaded, but the card type being previewed was not found and could not be updated!");
        }
    }
Esempio n. 4
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;
    }
 //called when card types are reloaded for some reason (probably from the inspector)
 private void cardTypesReloaded(CardTypeCollection newTypes)
 {
     destroyTypeEntries();
     setupTypeEntries(GetComponentInParent <DeckEditorMainScript>().openDeck);
 }