Beispiel #1
0
        static void RunTheShip()
        {
            string            folder            = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Substring(6).Replace("/", @"\");
            WorldModel        worldModel        = new WorldModel(System.IO.Path.Combine(folder, @"..\..\TheShip.aslx"), null);
            DefaultController defaultController = new DefaultController();

            defaultController.m_worldModel = worldModel;
            worldModel.Initialise(defaultController);
            worldModel.Begin();
            while (defaultController.m_continue)
            {
                string stdin = System.Console.ReadLine();
                if (stdin == "quit")
                {
                    defaultController.Quit();
                }
                else
                {
                    worldModel.SendCommand(stdin);
                }
            }
            worldModel.Finish();
        }
Beispiel #2
0
        public override void Execute(Context c)
        {
            string data = m_data.Execute(c);

            // TO DO: Replace with dictionary mapping the enum to lambda functions
            switch (m_request)
            {
            case Request.UpdateLocation:
                m_worldModel.PlayerUI.LocationUpdated(data);
                break;

            case Request.GameName:
                m_worldModel.PlayerUI.UpdateGameName(data);
                break;

            case Request.ClearScreen:
                m_worldModel.PlayerUI.ClearScreen();
                m_worldModel.OutputLogger.Clear();
                break;

            case Request.ShowPicture:
                m_worldModel.PlayerUI.ShowPicture(data);
                // TO DO: Picture should be added to the OutputLogger, but the data we
                // get here includes the full path/URL - we want the original filename
                // only, so this would be a breaking change.
                break;

            case Request.PanesVisible:
                m_worldModel.PlayerUI.SetPanesVisible(data);
                break;

            case Request.Background:
                m_worldModel.PlayerUI.SetBackground(data);
                break;

            case Request.Foreground:
                m_worldModel.PlayerUI.SetForeground(data);
                break;

            case Request.RunScript:
                if (m_worldModel.Version == WorldModelVersion.v500)
                {
                    // v500 games used Frame.js functions for static panel feature. This is now implemented natively
                    // in Player and WebPlayer.
                    if (data == "beginUsingTextFrame")
                    {
                        return;
                    }
                    if (data.StartsWith("setFramePicture;"))
                    {
                        string[] frameArgs = data.Split(';');
                        m_worldModel.PlayerUI.SetPanelContents("<img src=\"" + frameArgs[1].Trim() + "\" onload=\"setPanelHeight()\"/>");
                        return;
                    }
                    if (data == "clearFramePicture")
                    {
                        m_worldModel.PlayerUI.SetPanelContents("");
                    }
                }

                string[] jsArgs       = data.Split(';').Select(a => a.Trim()).ToArray();
                string   functionName = jsArgs[0];
                if (jsArgs.Length == 0)
                {
                    m_worldModel.PlayerUI.RunScript(functionName, null);
                }
                else
                {
                    m_worldModel.PlayerUI.RunScript(functionName, jsArgs.Skip(1).ToArray());
                }

                break;

            case Request.Quit:
                m_worldModel.PlayerUI.Quit();
                m_worldModel.Finish();
                break;

            case Request.FontName:
                if (m_worldModel.Version >= WorldModelVersion.v540)
                {
                    throw new InvalidOperationException("FontName request is not supported for games written for Quest 5.4 or later.");
                }
                m_worldModel.PlayerUI.SetFont(data);
                ((LegacyOutputLogger)(m_worldModel.OutputLogger)).SetFontName(data);
                break;

            case Request.FontSize:
                if (m_worldModel.Version >= WorldModelVersion.v540)
                {
                    throw new InvalidOperationException("FontSize request is not supported for games written for Quest 5.4 or later.");
                }
                m_worldModel.PlayerUI.SetFontSize(data);
                ((LegacyOutputLogger)(m_worldModel.OutputLogger)).SetFontSize(data);
                break;

            case Request.LinkForeground:
                m_worldModel.PlayerUI.SetLinkForeground(data);
                break;

            case Request.Show:
                m_worldModel.PlayerUI.Show(data);
                break;

            case Request.Hide:
                m_worldModel.PlayerUI.Hide(data);
                break;

            case Request.SetCompassDirections:
                m_worldModel.PlayerUI.SetCompassDirections(data.Split(';'));
                break;

            case Request.SetStatus:
                m_worldModel.PlayerUI.SetStatusText(data.Replace("\n", Environment.NewLine));
                break;

            case Request.Pause:
                if (m_worldModel.Version >= WorldModelVersion.v550)
                {
                    throw new Exception("The 'Pause' request is not supported for games written for Quest 5.5 or later. Use the 'SetTimeout' function instead.");
                }
                int ms;
                if (int.TryParse(data, out ms))
                {
                    m_worldModel.StartPause(ms);
                }
                break;

            case Request.Wait:
                if (m_worldModel.Version >= WorldModelVersion.v540)
                {
                    throw new Exception("The 'Wait' request is not supported for games written for Quest 5.4 or later. Use the 'wait' script command instead.");
                }
                m_worldModel.StartWait();
                break;

            case Request.SetInterfaceString:
                string[] args = data.Split('=');
                m_worldModel.PlayerUI.SetInterfaceString(args[0], args[1]);
                break;

            case Request.RequestSave:
                m_worldModel.PlayerUI.RequestSave(null);
                break;

            case Request.SetPanelContents:
                m_worldModel.PlayerUI.SetPanelContents(data);
                break;

            case Request.Log:
                m_worldModel.PlayerUI.Log(data);
                break;

            case Request.Speak:
                m_worldModel.PlayerUI.Speak(data);
                break;

            default:
                throw new ArgumentOutOfRangeException("request", "Unhandled request type");
            }
        }
Beispiel #3
0
 static public void ClassCleanup()
 {
     s_worldModel.Finish();
 }