Ejemplo n.º 1
0
    //Loads Asset Text at the beginning of the Game Start from a .csv file
    void AssetLoad()
    {
        var file = Resources.Load <TextAsset>("sdata");

        string[] data = file.text.Split(new char[] { '\n' });

        for (int i = 1; i < data.Length - 1; i++)
        {
            string[]      row            = data[i].Split(new char[] { ',' });
            Storylet      storylet       = new Storylet();
            PreConditions preConditions  = new PreConditions();
            PostCondition postConditions = new PostCondition();
            storylet.SetName(row[1]);

            row[2] = row[2].Replace(";", ",");
            row[2] = row[2].Replace("new-l", "\n");
            storylet.SetText(row[2]);
            storylet.AddTileDisplayText(row[3]);
            preConditions.position = row[4];

            int pre_mood;
            if (int.TryParse(row[5], out pre_mood))
            {
                preConditions.SetCharachterMood(pre_mood);
            }
            if (row[6].Contains(";") || row[6].Contains(":"))
            {
                string[] storyReq = row[6].Split(new char[] { ';' });
                foreach (string req in storyReq)
                {
                    string[] point = req.Split(new char[] { ':' });
                    int      value;
                    if (int.TryParse(point[1], out value))
                    {
                        KeyValuePair <string, int> pair = new KeyValuePair <string, int>(point[0], value);
                        preConditions.AddStoryletReq(pair);
                    }
                }
            }
            postConditions.position = row[7];

            int post_mood;
            if (int.TryParse(row[8], out post_mood))
            {
            }

            if (row[9].Contains(";") || row[9].Contains(":"))
            {
                string[] charAttib = row[9].Split(new char[] { ';' });
                foreach (string attrib in charAttib)
                {
                    string[] point = attrib.Split(new char[] { ':' });
                    int      value;
                    if (int.TryParse(point[1], out value))
                    {
                        postConditions.charachterAttributes.Add(point[0], value);
                    }
                }
            }

            if (row[10].Contains(";") || row[10].Contains(":"))
            {
                string[] inventory = row[10].Split(new char[] { ';' });
                foreach (string item in inventory)
                {
                    string[] point = item.Split(new char[] { ':' });

                    int value;
                    if (int.TryParse(point[1], out value))
                    {
                        charachter.UpdateInventory(point[0], value);
                    }
                }
            }

            string[] actors = row[11].Split(new char[] { ';' });
            foreach (string actor in actors)
            {
                string result = actor.Trim();
                if (!result.Equals("*"))
                {
                    postConditions.actors.Add(result);
                }
            }

            storylet.AddPreconditions(preConditions);
            storylet.AddPostcondition(postConditions);
            storylets.Add(storylet.GetName(), storylet);
        }

        Debug.Log(storylets.Count);
        foreach (KeyValuePair <string, Storylet> pair in storylets)
        {
            Debug.Log(pair.Key);
        }
    }
Ejemplo n.º 2
0
    public void AssetLoad()
    {
        var file = Resources.Load <TextAsset>(inputFile);

        string[] data = file.text.Split(new char[] { '\n' });


        for (int i = 3; i < data.Length - 1; i++)
        {
            string[]      row            = data[i].Split(new char[] { ',' });
            Storylet1     storylet       = new Storylet1();
            PreConditions preConditions  = new PreConditions();
            PostCondition postConditions = new PostCondition();
            //Display Text
            storylet.TileDisplayText = row[1];

            //Story Text
            row[2] = row[2].Replace(";", ",");
            row[2] = row[2].Replace("new-l", "\n");
            row[2] = row[2].Replace("DQ", "\"");
            row[2] = row[2].Replace("INSERT_NAME", scene.player_name);
            storylet.StoryletText = row[2];

            //Precondition Level
            if (int.TryParse(row[3], out int pre_level))
            {
                preConditions.level = pre_level;
            }

            //Morality Level
            if (int.TryParse(row[4], out int val))
            {
                storylet.MoralityScale = val;
            }

            //Affected Charachteristics
            if (row[5].Contains(";") || row[5].Contains(":"))
            {
                string[] attributes = row[5].Split(new char[] { ';' });
                foreach (string attribute in attributes)
                {
                    string[] value = attribute.Split(new char[] { ':' });
                    KeyValuePair <string, int> pair = new KeyValuePair <string, int>(value[0], int.Parse(value[1]));
                    storylet.AddCharachterUpdates(pair);
                }
            }

            //Precondition Actor
            string[] actors = row[6].Split(new char[] { ';' });
            foreach (string actor in actors)
            {
                if (!string.IsNullOrEmpty(actor) && !actor.Equals("*"))
                {
                    preConditions.AddActor(actor);
                }
            }


            // Pre Required Player Conditions
            if (row[7].Contains(";") || row[7].Contains(":"))
            {
                string[] reqd_qualities = row[7].Split(new char[] { ';' });
                foreach (string quality in reqd_qualities)
                {
                    string[] value = quality.Split(new char[] { ':' });
                    KeyValuePair <string, int> pair = new KeyValuePair <string, int>(value[0], int.Parse(value[1]));
                    preConditions.AddStoryletReq(pair);
                }
            }

            // Pre Required Position
            row[8] = row[8].Trim();
            preConditions.position = row[8];


            // Post Actors
            if ((row[9].Contains(";") || row[9].Contains(":")) && !row[9].Contains("*"))
            {
                string[] updateActors = row[9].Split(new char[] { ';' });
                foreach (string update in updateActors)
                {
                    if (!string.IsNullOrEmpty(update) && !update.Contains("*"))
                    {
                        postConditions.actors.Add(update);
                    }
                }
            }

            //Post Condition Position
            row[10] = row[10].Trim();
            postConditions.position = row[10];

            //Post Level
            if (int.TryParse(row[11], out int post_level))
            {
                postConditions.level_post = post_level;
            }

            //Dead People
            if ((row[12].Contains(";") || row[12].Contains(":")) && !row[12].Contains("*"))
            {
                string[] updateDeadActors = row[12].Split(new char[] { ';' });
                postConditions.deadActor = updateDeadActors[0];
            }

            //Interactable Obj
            if ((row[13].Contains(";") || row[13].Contains(":")) && !row[13].Contains("*"))
            {
                string[] obj = row[13].Split(new char[] { ';' });
                postConditions.interactableObj = obj[0];
            }

            storylet.Precondition  = preConditions;
            storylet.Postcondition = postConditions;
            storylets.Add(storylet.TileDisplayText, storylet);
        }

        //foreach (KeyValuePair<string, Storylet1> storylet in storylets)
        //{
        //    Debug.Log(storylet.Key);
        //}
    }