Ejemplo n.º 1
0
        public CommandData FromGameObject(Command c)
        {
            this.command = c.TypeName().ToUpper();

            LineContext lc = c.lineContext;

            this.actor = lc.actor;
            this.text  = lc.text;
            this.label = lc.label;
            this.meta  = lc.meta;

            if (c is Ask)
            {
                var opts = ((Ask)c).Options();
                options = new string[opts.Count];
                var i = 0;
                opts.ForEach(o =>
                {
                    //Console.WriteLine("ADD: "+o.text + "\\n" + o.action);
                    options[i++] = o.text + OPT_DELIM + o.action.text;
                });
            }

            return(this);
        }
Ejemplo n.º 2
0
        internal Command ToGameObject(ChatRuntime rt)
        {
            ChatParser  parser = rt.Parser();
            LineContext lc     = new LineContext(parser, actor, command, text, label, meta);
            var         cmd    = parser.CreateCommand(lc);

            if (cmd is Ask)
            {
                Ask ask = (Dialogic.Ask)cmd;
                for (int i = 0; i < options.Length; i++)
                {
                    var parts = options[i].Split(OPT_DELIM);
                    if (parts.Length != 2)
                    {
                        throw new DialogicException
                                  ("Bad option:" + options[i]);
                    }
                    Opt opt = new Opt();
                    parts[1] = parts[1].TrimFirst(Ch.LABEL);
                    opt.Init(parts[0], Ch.LABEL + parts[1], null);
                    ask.AddOption(opt);
                }
            }
            return(cmd);
        }
Ejemplo n.º 3
0
        internal Command CreateCommand(LineContext lc)
        {
            Type type = lc.command.Length > 0 ? runtime.typeMap[lc.command]
                : Chat.DefaultCommandType(activeChat);

            Command c = Command.Create(type, lc.text, lc.label, SplitMeta(lc.meta));
            c.lineContext = lc;

            HandleActor(c, lc.actor);
            HandleCommand(c);
            RunValidators(c);

            return c;
        }
Ejemplo n.º 4
0
        internal Command ParseLine(string line, int lineNo)
        {
            Command c = null;

            try
            {
                var lc = new LineContext(this, line, lineNo);
                c = CreateCommand(lc);
            }
            catch (Exception ex)
            //catch (ParseException ex)
            {
                throw new ParseException(line, lineNo, ex.Message);
            }

            return(c);
        }
Ejemplo n.º 5
0
        internal Chat ToGameObject(ChatRuntime rt)
        {
            ChatParser  parser = rt.Parser();
            LineContext lc     = new LineContext(parser, null, "CHAT", text, null, meta);
            Chat        chat   = (Dialogic.Chat)parser.CreateCommand(lc);

            chat.Staleness(this.staleness);
            chat.Resumable(this.resumable);
            chat.Interruptable(this.interruptable);
            chat.ResumeAfterInterrupting(this.resumeAfterInt);
            chat.StalenessIncr(this.stalenessIncr);

            chat.cursor    = this.cursor;
            chat.lastRunAt = this.lastRunAt;
            chat.allowSmoothingOnResume = this.allowSmoothingOnResume;

            chat.commands = new List <Command>(this.commands.Count);
            this.commands.ForEach(cmd => cmd.ToGameObject(rt));

            return(chat);
        }
Ejemplo n.º 6
0
        public LineContext line()
        {
            LineContext _localctx = new LineContext(_ctx, State);

            EnterRule(_localctx, 2, RULE_line);
            int _la;

            try {
                int _alt;
                EnterOuterAlt(_localctx, 1);
                {
                    State = 30;
                    _errHandler.Sync(this);
                    switch (Interpreter.AdaptivePredict(_input, 3, _ctx))
                    {
                    case 1:
                    {
                        State = 15; command();
                        State = 19;
                        _errHandler.Sync(this);
                        _alt = Interpreter.AdaptivePredict(_input, 1, _ctx);
                        while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber)
                        {
                            if (_alt == 1)
                            {
                                {
                                    {
                                        State = 16; Match(SPACE);
                                    }
                                }
                            }
                            State = 21;
                            _errHandler.Sync(this);
                            _alt = Interpreter.AdaptivePredict(_input, 1, _ctx);
                        }
                    }
                    break;

                    case 2:
                    {
                        State = 22; command();
                        State = 24;
                        _errHandler.Sync(this);
                        _la = _input.La(1);
                        do
                        {
                            {
                                {
                                    State = 23; Match(SPACE);
                                }
                            }
                            State = 26;
                            _errHandler.Sync(this);
                            _la = _input.La(1);
                        } while (_la == SPACE);
                        State = 28; args();
                    }
                    break;
                    }
                    State = 35;
                    _errHandler.Sync(this);
                    _la = _input.La(1);
                    while (_la == SPACE)
                    {
                        {
                            {
                                State = 32; Match(SPACE);
                            }
                        }
                        State = 37;
                        _errHandler.Sync(this);
                        _la = _input.La(1);
                    }
                    State = 38;
                    _la   = _input.La(1);
                    if (!(_la == Eof || _la == NEWLINE))
                    {
                        _errHandler.RecoverInline(this);
                    }
                    else
                    {
                        if (_input.La(1) == TokenConstants.Eof)
                        {
                            matchedEOF = true;
                        }

                        _errHandler.ReportMatch(this);
                        Consume();
                    }
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                _errHandler.ReportError(this, re);
                _errHandler.Recover(this, re);
            }
            finally {
                ExitRule();
            }
            return(_localctx);
        }