示例#1
0
    public void initAll()
    {
        if (!Initialized)
        {
            Stopwatch sw = new Stopwatch(); //benchmarking terrible loading times
            sw.Start();
            ScriptRegistry.init();
            sw.Stop();
            UnityEngine.Debug.Log("Script registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            sw.Start();
            SpriteRegistry.init();
            sw.Stop();
            UnityEngine.Debug.Log("Sprite registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            sw.Start();
            AudioClipRegistry.init();
            sw.Stop();
            UnityEngine.Debug.Log("Audio clip registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            sw.Start();
            SpriteFontRegistry.init();
            sw.Stop();
            UnityEngine.Debug.Log("Sprite font registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();
        }
        LateUpdater.init(); // must be last; lateupdater's initialization is for classes that depend on the above registries
        MusicManager.src = Camera.main.GetComponent <AudioSource>();
    }
示例#2
0
    // Use this for initialization
    void Start()
    {
        FindObjectOfType <Fading>().BeginFade(-1);

        tmMain       = GameObject.Find("TextManager Main").GetComponent <TextManager>();
        tmChoice     = GameObject.Find("TextManager Choice").GetComponent <TextManager>();
        tmInfo       = GameObject.Find("TextManager Info").GetComponent <TextManager>();
        tmBigTalk    = GameObject.Find("TextManager BigTalk").GetComponent <TextManager>();
        tmGold       = GameObject.Find("TextManager Gold").GetComponent <TextManager>();
        tmItem       = GameObject.Find("TextManager Item").GetComponent <TextManager>();
        tmInfoParent = tmInfo.transform.parent.parent.gameObject;
        tmBigTalk.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) });
        utHeart = GameObject.Find("utHeart");
        EnableBigText(false);

        if (scriptName == null)
        {
            throw new CYFException("You must give a valid script name to the function General.EnterShop()");
        }

        script = new ScriptWrapper()
        {
            scriptname = scriptName
        };
        string scriptText = ScriptRegistry.Get(ScriptRegistry.SHOP_PREFIX + scriptName);

        if (scriptText == null)
        {
            throw new CYFException("You must give a valid script name to the function General.EnterShop()");
        }

        try {
            script.DoString(scriptText);
            script.SetVar("background", UserData.Create(new LuaSpriteController(GameObject.Find("Background").GetComponent <Image>())));
            script.script.Globals["Interrupt"]    = ((Action <DynValue, string>)Interrupt);
            script.script.Globals["CreateSprite"] = (Func <string, string, int, DynValue>)SpriteUtil.MakeIngameSprite;
            script.script.Globals["CreateLayer"]  = (Action <string, string, bool>)SpriteUtil.CreateLayer;
            script.script.Globals["CreateText"]   = (Func <Script, DynValue, DynValue, int, string, int, LuaTextManager>)LuaScriptBinder.CreateText;
            TryCall("Start");

            tmMain.SetCaller(script);
            tmChoice.SetCaller(script);
            tmInfo.SetCaller(script);
            tmBigTalk.SetCaller(script);

            tmMain.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][linespacing:11]" + script.GetVar("maintalk").String, true, false) });
            tmChoice.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice][font:uidialoglilspace][linespacing:9]    Buy\n    Sell\n    Talk\n    Exit", false, true) });
            tmGold.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + PlayerCharacter.instance.Gold + "G", false, true) });
            tmItem.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + Inventory.inventory.Count + "/8", false, true) });
            tmInfo.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) });

            Camera.main.GetComponent <AudioSource>().clip = AudioClipRegistry.GetMusic(script.GetVar("music").String);
            Camera.main.GetComponent <AudioSource>().time = 0;
            Camera.main.GetComponent <AudioSource>().Play();

            SetPlayerOnSelection();
        }
        catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(scriptName, ex.DecoratedMessage != null ? UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message : ex.Message); }
        catch (Exception ex)            { UnitaleUtil.DisplayLuaError(scriptName, "Unknown error. Usually means you're missing a sprite.\nSee documentation for details.\nStacktrace below in case you wanna notify a dev.\n\nError: " + ex.Message + "\n\n" + ex.StackTrace); }
    }
示例#3
0
    // Use this for initialization
    void Start()
    {
        FindObjectOfType <Fading>().BeginFade(-1);

        tmMain       = GameObject.Find("TextManager Main").GetComponent <TextManager>();
        tmChoice     = GameObject.Find("TextManager Choice").GetComponent <TextManager>();
        tmInfo       = GameObject.Find("TextManager Info").GetComponent <TextManager>();
        tmBigTalk    = GameObject.Find("TextManager BigTalk").GetComponent <TextManager>();
        tmGold       = GameObject.Find("TextManager Gold").GetComponent <TextManager>();
        tmItem       = GameObject.Find("TextManager Item").GetComponent <TextManager>();
        tmInfoParent = tmInfo.transform.parent.parent.gameObject;
        tmBigTalk.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) });
        utHeart = GameObject.Find("utHeart");
        EnableBigText(false);

        if (scriptName == null)
        {
            UnitaleUtil.DisplayLuaError("Creating the shop menu", "You must give a valid script name to the function General.EnterShop()");
            return;
        }

        script = new ScriptWrapper()
        {
            scriptname = scriptName
        };
        string scriptText = ScriptRegistry.Get(ScriptRegistry.SHOP_PREFIX + scriptName);

        if (scriptText == null)
        {
            UnitaleUtil.DisplayLuaError("Creating the shop menu", "You must give a valid script name to the function General.EnterShop()");
            return;
        }


        script.DoString(scriptText);
        script.SetVar("background", UserData.Create(new LuaSpriteController(GameObject.Find("Background").GetComponent <Image>())));
        script.script.Globals["Interrupt"]    = ((Action <DynValue, string>)Interrupt);
        script.script.Globals["CreateSprite"] = (Func <string, string, int, DynValue>)SpriteUtil.MakeIngameSprite;
        script.script.Globals["CreateLayer"]  = (Action <string, string, bool>)SpriteUtil.CreateLayer;
        script.script.Globals["CreateText"]   = (Func <Script, DynValue, DynValue, int, string, int, LuaTextManager>)LuaScriptBinder.CreateText;
        script.Call("Start");

        tmMain.SetCaller(script);
        tmChoice.SetCaller(script);
        tmInfo.SetCaller(script);
        tmBigTalk.SetCaller(script);

        tmMain.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][linespacing:11]" + script.GetVar("maintalk").String, true, false) });
        tmChoice.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice][font:uidialoglilspace][linespacing:9]    Buy\n    Sell\n    Talk\n    Exit", false, true) });
        tmGold.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + PlayerCharacter.instance.Gold + "G", false, true) });
        tmItem.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + Inventory.inventory.Count + "/8", false, true) });
        tmInfo.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) });

        Camera.main.GetComponent <AudioSource>().clip = AudioClipRegistry.GetMusic(script.GetVar("music").String);
        Camera.main.GetComponent <AudioSource>().Play();
    }
    private void PrepareWave()
    {
        DynValue nextWaves = script.GetVar("nextwaves");

        waves     = new ScriptWrapper[nextWaves.Table.Length];
        waveNames = new string[waves.Length];
        int currentWaveScript = 0;

        try {
            List <int> indexes = new List <int>();
            for (int i = 0; i < waves.Length; i++)
            {
                currentWaveScript = i;
                DynValue ArenaStatus = UserData.Create(ArenaManager.luaStatus);
                waves[i] = new ScriptWrapper()
                {
                    script = LuaScriptBinder.BoundScript()
                };
                waves[i].script.Globals.Set("Arena", ArenaStatus);
                waves[i].script.Globals["EndWave"]             = (Action)EndWaveTimer;
                waves[i].script.Globals["State"]               = (Action <Script, string>)UIController.SwitchStateOnString;
                waves[i].script.Globals["CreateProjectile"]    = (Func <Script, string, float, float, string, DynValue>)CreateProjectile;
                waves[i].script.Globals["CreateProjectileAbs"] = (Func <Script, string, float, float, string, DynValue>)CreateProjectileAbs;
                if (nextWaves.Table.Get(i + 1).Type != DataType.String)
                {
                    UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "Non-string value encountered in nextwaves table");
                    return;
                }
                else
                {
                    waveNames[i] = nextWaves.Table.Get(i + 1).String;
                }
                waves[i].script.Globals["wavename"] = nextWaves.Table.Get(i + 1).String;
                try {
                    waves[i].DoString(ScriptRegistry.Get(ScriptRegistry.WAVE_PREFIX + nextWaves.Table.Get(i + 1).String));
                    indexes.Add(i);
                } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(nextWaves.Table.Get(i + 1).String + ".lua", ex.DecoratedMessage); } catch (Exception ex) {
                    if (!GlobalControls.retroMode && !ScriptRegistry.dict.ContainsKey(ScriptRegistry.WAVE_PREFIX + nextWaves.Table.Get(i + 1).String))
                    {
                        UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "The wave " + nextWaves.Table.Get(i + 1).String + " doesn't exist.");
                    }
                    else
                    {
                        UnitaleUtil.DisplayLuaError("<UNKNOWN LOCATION>", ex.Message + "\n\n" + ex.StackTrace);
                    }
                }
            }
            Table luaWaveTable = new Table(null);
            for (int i = 0; i < indexes.Count; i++)
            {
                luaWaveTable.Set(i + 1, UserData.Create(waves[indexes[i]]));
            }
            script.SetVar("Wave", DynValue.NewTable(luaWaveTable));
        } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(nextWaves.Table.Get(currentWaveScript + 1).String + ".lua", ex.DecoratedMessage); }
    }
    private void Start()
    {
        try {
            string scriptText = ScriptRegistry.Get(ScriptRegistry.MONSTER_PREFIX + scriptName);
            if (scriptText == null)
            {
                UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "Tried to load monster script " + scriptName + ".lua but it didn't exist. Is it misspelled?");
                return;
            }
            script.scriptname = scriptName;
            script.Bind("SetSprite", (Action <string>)SetSprite);
            script.Bind("SetActive", (Action <bool>)SetActive);
            script.Bind("isActive", (Func <bool>)InFight);
            script.Bind("Kill", (Action)DoKill);
            script.Bind("Spare", (Action)DoSpare);
            script.Bind("Move", (Action <float, float, bool>)Move);
            script.Bind("MoveTo", (Action <float, float, bool>)MoveTo);
            script.Bind("BindToArena", (Action <bool, bool>)BindToArena);
            script.Bind("SetDamage", (Action <int>)SetDamage);
            script.Bind("SetBubbleOffset", (Action <int, int>)SetBubbleOffset);
            script.Bind("SetDamageUIOffset", (Action <int, int>)SetDamageUIOffset);
            script.Bind("SetSliceAnimOffset", (Action <int, int>)SetSliceAnimOffset);
            script.Bind("GetLetters", (Func <Letter[]>)GetLetters);
            script.Bind("State", (Action <Script, string>)UIController.SwitchStateOnString);
            script.SetVar("canmove", DynValue.NewBoolean(false));
            sprite = new LuaSpriteController(GetComponent <Image>());
            script.SetVar("monstersprite", UserData.Create(sprite, LuaSpriteController.data));
            script.DoString(scriptText);

            string spriteFile = script.GetVar("sprite").String;
            if (spriteFile != null)
            {
                SetSprite(spriteFile);
            }
            else
            {
                throw new CYFException("missing sprite");
            }

            ui = FindObjectOfType <UIController>();
            if (MaxHP == 0)
            {
                MaxHP = HP;
            }

            textBubbleSprite = Resources.Load <Sprite>("Sprites/UI/SpeechBubbles/right");

            /*if (script.GetVar("canspare") == null) CanSpare = false;
             * if (script.GetVar("cancheck") == null) CanCheck = true;*/
        }
        catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(scriptName, ex.DecoratedMessage); }
        catch (Exception ex)            { UnitaleUtil.DisplayLuaError(scriptName, "Unknown error. Usually means you're missing a sprite.\nSee documentation for details.\nStacktrace below in case you wanna notify a dev.\n\nError: " + ex.Message + "\n\n" + ex.StackTrace); }
    }
示例#6
0
    private void Start()
    {
        try
        {
            string scriptText = ScriptRegistry.Get(ScriptRegistry.MONSTER_PREFIX + scriptName);
            if (scriptText == null)
            {
                UnitaleUtil.displayLuaError(StaticInits.ENCOUNTER, "Tried to load monster script " + scriptName + ".lua but it didn't exist. Is it misspelled?");
                return;
            }

            script.scriptname = scriptName;
            script.Bind("SetSprite", (Action <string>)SetSprite);
            script.Bind("SetActive", (Action <bool>)SetActive);
            script.Bind("Kill", (Action)DoKill);
            script.Bind("Spare", (Action)DoSpare);
            script.DoString(scriptText);

            string spriteFile = script.GetVar("sprite").String;
            if (spriteFile != null)
            {
                SetSprite(spriteFile);
            }
            else
            {
                throw new InvalidOperationException("missing sprite");
            }

            ui               = FindObjectOfType <UIController>();
            maxHP            = HP;
            currentHP        = HP;
            textBubbleSprite = Resources.Load <Sprite>("Sprites/UI/SpeechBubbles/right");

            /*if (script.GetVar("canspare") == null)
             * {
             *  CanSpare = false;
             * }
             * if (script.GetVar("cancheck") == null)
             * {
             *  CanCheck = true;
             * }*/
        }
        catch (InterpreterException ex)
        {
            UnitaleUtil.displayLuaError(scriptName, ex.DecoratedMessage);
        }
        catch (Exception ex)
        {
            UnitaleUtil.displayLuaError(scriptName, "Unknown error. Usually means you're missing a sprite.\nSee documentation for details.\nStacktrace below in case you wanna notify a dev.\n" + ex.StackTrace);
        }
    }
示例#7
0
    public static void InitAll(bool shaders = false)
    {
        if (!Initialized && (!GlobalControls.isInFight || GlobalControls.modDev))
        {
            //UnitaleUtil.createFile();
            Stopwatch sw = new Stopwatch(); //benchmarking terrible loading times
            sw.Start();
            ScriptRegistry.Init();
            sw.Stop();
            UnityEngine.Debug.Log("Script registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            sw.Start();
            SpriteRegistry.Init();
            sw.Stop();
            UnityEngine.Debug.Log("Sprite registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            sw.Start();
            AudioClipRegistry.Init();
            sw.Stop();
            UnityEngine.Debug.Log("Audio clip registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            sw.Start();
            SpriteFontRegistry.Init();
            sw.Stop();
            UnityEngine.Debug.Log("Sprite font registry loading time: " + sw.ElapsedMilliseconds + "ms");
            sw.Reset();

            if (shaders)
            {
                sw.Start();
                ShaderRegistry.Init();
                sw.Stop();
                UnityEngine.Debug.Log("Shader registry loading time: " + sw.ElapsedMilliseconds + "ms");
                sw.Reset();
            }
        }
        else
        {
            Initialized = true;
        }
        LateUpdater.Init(); // must be last; lateupdater's initialization is for classes that depend on the above registries
        MusicManager.src = Camera.main.GetComponent <AudioSource>();
        SendLoaded();
        //CurrENCOUNTER = ENCOUNTER;
        //CurrMODFOLDER = MODFOLDER;
    }
示例#8
0
        public void Setup()
        {
            ScriptsLifetimeManager scriptsLifetimeManager = new ScriptsLifetimeManager();

            scripts = new List <Script>();

            Mock <EventInfo>      mockEventInfo      = new Mock <EventInfo>();
            Mock <Self>           mockSelf           = new Mock <Self>();
            Mock <ScriptRegistry> mockScriptRegistry = new Mock <ScriptRegistry>();

            eventInfo = mockEventInfo.Object;
            Self           self           = mockSelf.Object;
            ScriptRegistry scriptRegistry = mockScriptRegistry.Object;

            mockScriptRegistry.Setup(mock => mock.Scripts).Returns(scripts);

            Singleton <ISelf> .Instance           = self;
            Singleton <IScriptRegistry> .Instance = scriptRegistry;
        }
    /// <summary>
    /// Attempts to initialize the encounter's script file and bind encounter-specific functions to it.
    /// </summary>
    /// <returns>True if initialization succeeded, false if there was an error.</returns>
    private bool initScript()
    {
        script            = new ScriptWrapper();
        script.scriptname = StaticInits.ENCOUNTER;
        string scriptText = ScriptRegistry.Get(ScriptRegistry.ENCOUNTER_PREFIX + StaticInits.ENCOUNTER);

        try
        {
            script.DoString(scriptText);
        }
        catch (InterpreterException ex)
        {
            UnitaleUtil.displayLuaError(StaticInits.ENCOUNTER, ex.DecoratedMessage);
            return(false);
        }
        script.Bind("RandomEncounterText", (Func <string>)RandomEncounterText);
        script.Bind("CreateProjectile", (Func <Script, string, float, float, DynValue>)CreateProjectile);
        script.Bind("CreateProjectileAbs", (Func <Script, string, float, float, DynValue>)CreateProjectileAbs);
        script_ref = script;
        return(true);
    }
示例#10
0
        public Form2HtmlMELOVisitor(FormModel formModel, bool verbose)
        {
            html = null;

            scripts = new List <HtmlContainer>();

            if (formModel == null)
            {
                return;
            }

            initialize = formModel.Submitted;

            this.verbose = verbose;

            scriptRegistry = new ScriptRegistry();

            Visit(formModel.FormGroup, null);

            AddScripts();
        }
示例#11
0
    private void prepareWave()
    {
        DynValue nextWaves = script.GetVar("nextwaves");

        waves     = new Script[nextWaves.Table.Length];
        waveNames = new string[waves.Length];
        int currentWaveScript = 0;

        try
        {
            for (int i = 0; i < waves.Length; i++)
            {
                currentWaveScript = i;
                waves[i]          = LuaScriptBinder.boundScript();
                DynValue ArenaStatus = UserData.Create(ArenaSizer.luaStatus);
                waves[i].Globals.Set("Arena", ArenaStatus);
                waves[i].Globals["State"]               = (Action <string>)UIController.instance.SwitchStateOnString;
                waves[i].Globals["CreateProjectile"]    = (Func <Script, string, float, float, DynValue>)CreateProjectile;
                waves[i].Globals["CreateProjectileAbs"] = (Func <Script, string, float, float, DynValue>)CreateProjectileAbs;
                waves[i].Globals["EndWave"]             = (Action)endWaveTimer;
                if (nextWaves.Table.Get(i + 1).Type != DataType.String)
                {
                    UnitaleUtil.displayLuaError(StaticInits.ENCOUNTER, "Non-string value encountered in nextwaves table");
                    return;
                }
                else
                {
                    waveNames[i] = nextWaves.Table.Get(i + 1).String;
                }
                waves[i].DoString(ScriptRegistry.Get(ScriptRegistry.WAVE_PREFIX + nextWaves.Table.Get(i + 1).String));
            }
        }
        catch (InterpreterException ex)
        {
            UnitaleUtil.displayLuaError(nextWaves.Table.Get(currentWaveScript + 1).String + ".lua", ex.DecoratedMessage);
        }
    }