Exemple #1
0
    void process_json_game_event(string path, bool from_previous = false)
    {
        //get rid of old bubbles if they exist
        hide_bubble(speech_A);
        hide_bubble(speech_B);

        if (!from_previous)
        {
            previous_events.Add(current_event_name);
        }
        current_event_name = path;
        try
        {
            GameEventJSON json = JsonUtility.FromJson <GameEventJSON>(read_json_file(path));
            Debug.Log("event: " + json.dialogue);
            current_event = new GameEvent(json);
            handle_event(new GameEvent(json));
        }
        catch (System.Exception e)
        {
            Text debugInfo = DebugInfo.GetComponent <Text>();
            debugInfo.text = "Invalid JSON script: " + path;
            Canvas.ForceUpdateCanvases();
            Debug.Log("Invalid JSON script: " + e.ToString());
            return;
        }
    }
Exemple #2
0
 public GameEvent(GameEventJSON js)
 {
     wait_time  = js.wait_time;
     next_event = js.next_event;
     choices    = js.choices;
     text_speed = js.text_speed;
     if (text_speed == null || text_speed == 0)
     {
         text_speed = 1;
     }
     wobble = js.wobble;  //deprecated DO NOT USE!
     if (wobble == null || wobble == 0)
     {
         wobble = 1f; //multiplier
     }
     dialogue = js.dialogue;
     if (js.tutorial != null)
     {
         tutorial = js.tutorial;
     }
     display_state = new DisplayState(js.display_state);
     is_interrupt  = js.is_interrupt;
     if (is_interrupt == null)
     {
         is_interrupt = false;
     }
     effects = js.effects;
 }
Exemple #3
0
    // recursive checks that all script paths are valid; returns success
    bool validate_scripts(string script, string calling_script, Hashtable seen, List <string> traversal)
    {
        traversal.Add(script);
        if (script == "endgame" || script == "" /*dummy*/)
        {
            return(true); //good!
        }

        if (seen.Contains(script))
        {
            int count = (int)seen[script];
            seen[script] = count + 1;
            return(true); //FIXME remove this and fix the test below
            //if (traversal.Count > 100)
            //{
            //    Debug.LogWarning("Warning: Potentially infinite loop from scripts: " + string.Join(" -> ", traversal));
            //    return false;
            //}
        }
        else
        {
            seen.Add(script, 1);
        }

        GameEvent gameEvent;

        string jsonData;

        try
        {
            jsonData = read_json_file(script);
        }
        catch (System.Exception e)
        {
            Debug.LogError("Error: MISSING script: " + script + " referenced in " + calling_script);
            Debug.Log(e);
            return(false);
        }
        try
        {
            GameEventJSON gameEventJSON = JsonUtility.FromJson <GameEventJSON>(jsonData);
            gameEvent = new GameEvent(gameEventJSON);
        }
        catch (System.Exception e)
        {
            Debug.LogError("Error: INVALID script: " + script);
            Debug.Log(e);
            return(false);
        }


        bool success = true;

        foreach (string s in gameEvent.next_event)
        {
            List <string> trav = new List <string>();
            foreach (string st in traversal)
            {
                trav.Add(st);
            }
            success = success && validate_scripts(s, script, seen, trav);
        }
        return(success);
    }