Exemple #1
0
        /// <summary>
        /// Evaluates a math expression of 2 time spans.
        /// </summary>
        /// <param name="node">The AST node the evaluation is a part of.</param>
        /// <param name="lhs">The time on the left hand side</param>
        /// <param name="rhs">The time on the right hand side</param>
        /// <param name="op">The math operator.</param>
        /// <returns></returns>
        public static LBool CompareTimes(AstNode node, LTime lhs, LTime rhs, Operator op)
        {
            var left   = lhs.Value;
            var right  = rhs.Value;
            var result = false;

            if (op == Operator.LessThan)
            {
                result = left < right;
            }
            else if (op == Operator.LessThanEqual)
            {
                result = left <= right;
            }
            else if (op == Operator.MoreThan)
            {
                result = left > right;
            }
            else if (op == Operator.MoreThanEqual)
            {
                result = left >= right;
            }
            else if (op == Operator.EqualEqual)
            {
                result = left == right;
            }
            else if (op == Operator.NotEqual)
            {
                result = left != right;
            }
            return(new LBool(result));
        }
Exemple #2
0
        private static void SetDateTime(LTime target, DateTimeKind kind, int year = -1, int month = -1, int day = -1,
                                        int hour = -1, int minute = -1, int second = -1, int millisecond = -1)
        {
            var t = target.Value;

            hour        = hour == -1 ? t.Hours : hour;
            minute      = minute == -1 ? t.Minutes : minute;
            second      = second == -1 ? t.Seconds : second;
            millisecond = millisecond == -1 ? t.Milliseconds : millisecond;

            var finaLTimeTime = new TimeSpan(hour, minute, second, millisecond);

            target.Value = finaLTimeTime;
        }
Exemple #3
0
    protected override void FetchReferences()
    {
        base.FetchReferences();
        LTime time = story.CurrentTime;

        SetDay(time.GetDayString());
        changeTime(time.GetTimeString());
        if (firstTimeBootup)
        {
            EventController.Event(LEvent.BootUp);
            firstTimeBootup = false;
        }
        setBackgroundWallpaper();
        setPushNotifications();
    }
Exemple #4
0
        /// <summary>
        /// Evaluates a math expression of 2 time spans.
        /// </summary>
        /// <param name="node">The AST node the evaluation is a part of.</param>
        /// <param name="lhs">The time on the left hand side</param>
        /// <param name="rhs">The time on the right hand side</param>
        /// <param name="op">The math operator.</param>
        /// <returns></returns>
        public static LTime CalcTimes(AstNode node, LTime lhs, LTime rhs, Operator op)
        {
            if (op != Operator.Add && op != Operator.Subtract)
            {
                throw ExceptionHelper.BuildRunTimeException(node, "Can only add/subtract times");
            }

            var left   = lhs.Value;
            var right  = rhs.Value;
            var result = TimeSpan.MinValue;

            if (op == Operator.Add)
            {
                result = left + right;
            }
            else if (op == Operator.Subtract)
            {
                result = left - right;
            }
            return(new LTime(result));
        }
Exemple #5
0
 public static void StartServices()
 {
     LTime.DoStart();
     CoroutineHelper.DoStart();
 }
Exemple #6
0
 /// <summary>
 /// Sets the milliseconds on the date
 /// </summary>
 /// <param name="time">The LTimeType to set</param>
 /// <param name="milliseconds">The milliseconds to set</param>
 public void SetMilliseconds(LTime time, int milliseconds)
 {
     SetDateTime(time, DateTimeKind.Local, -1, -1, -1, -1, -1, -1, milliseconds);
 }
Exemple #7
0
 /// <summary>
 /// Sets the hours of the date
 /// </summary>
 /// <param name="time">The LTimeType to set</param>
 /// <param name="hours">The hours to set</param>
 /// <param name="minutes">The minutes to set</param>
 /// <param name="seconds">The seconds to set</param>
 /// <param name="milliseconds">The milliseconds to set</param>
 public void SetHours(LTime time, int hours, int minutes, int seconds, int milliseconds)
 {
     SetDateTime(time, DateTimeKind.Local, -1, -1, -1, hours, minutes, seconds, milliseconds);
 }
        private MatchResult CheckExpressionMatches(CompilerPlugin plugin, List <TokenMatch> matches, Dictionary <string, object> args, int peekCount, int matchCount)
        {
            var isMatch      = true;
            var token        = peekCount == 0 ? this.TokenIt.NextToken : this.TokenIt.Peek(peekCount);
            var totalMatched = matchCount;

            foreach (var match in matches)
            {
                var continueCheck  = false;
                var trackNamedArgs = true;
                var valueMatched   = false;

                // Termninators
                if (match.TokenType == "@exprTerminators" &&
                    (Terminators.ExpFlexibleEnd.ContainsKey(token.Token) || Terminators.ExpThenEnd.ContainsKey(token.Token))
                    )
                {
                    // Don't increment the peekcount
                    isMatch = totalMatched >= plugin.TotalRequiredMatches;
                    break;
                }
                // Check for ";" and EOF ( end of file/text )
                if (token.Token == Tokens.Semicolon || token.Token == Tokens.EndToken)
                {
                    isMatch = totalMatched >= plugin.TotalRequiredMatches;
                    break;
                }

                // Check 1: Group tokens ?
                if (match.IsGroup)
                {
                    var submatches = ((TokenGroup)match).Matches;
                    var result     = CheckExpressionMatches(plugin, submatches, args, peekCount, totalMatched);
                    if (match.IsRequired && !result.Success)
                    {
                        isMatch = false;
                        break;
                    }
                    if (result.Success)
                    {
                        peekCount = result.TokenCount;
                        if (match.IsRequired)
                        {
                            totalMatched += result.TotalMatched;
                        }
                    }
                }
                // Check 2: starttoken?
                else if (match.TokenType == "@starttoken")
                {
                    continueCheck = true;
                    totalMatched++;
                }
                // Check 2a: tokenmap1
                else if (match.TokenType == "@tokenmap1")
                {
                    if (plugin.TokenMap1 == null || !plugin.TokenMap1.ContainsKey(token.Token.Text))
                    {
                        isMatch = false;
                        break;
                    }
                    continueCheck = true;
                    totalMatched++;
                }
                else if (match.TokenType == "@tokenmap2")
                {
                    if (plugin.TokenMap2 == null || !plugin.TokenMap2.ContainsKey(token.Token.Text))
                    {
                        isMatch = false;
                        break;
                    }
                    continueCheck = true;
                    totalMatched++;
                }
                // Check 2c: "identSymbol" must exist
                else if (match.TokenType == "@identsymbol")
                {
                    var symbolExists = this.Symbols.Contains(token.Token.Text);
                    continueCheck = symbolExists;
                    if (!continueCheck)
                    {
                        isMatch = false;
                        break;
                    }
                    totalMatched++;
                }
                // Check 2c: "identSymbol" must exist
                else if (match.TokenType == "@singularsymbol")
                {
                    var plural       = token.Token.Text + "s";
                    var symbolExists = this.Symbols.Contains(plural);
                    continueCheck = symbolExists;
                    if (!continueCheck)
                    {
                        isMatch = false;
                        break;
                    }
                    totalMatched++;
                }
                // Check 2d: paramlist = @word ( , @word )* parameter names
                else if (match.TokenType == "@paramnames")
                {
                    var isvalidParamList = true;
                    var maxParams        = 10;
                    var totalParams      = 0;
                    var paramList        = new List <object>();

                    while (totalParams <= maxParams)
                    {
                        var token2 = this.TokenIt.Peek(peekCount, false);
                        if (token2.Token == Tokens.Comma)
                        {
                            peekCount++;
                        }
                        else if (token2.Token.Kind == TokenKind.Ident)
                        {
                            paramList.Add(token2.Token.Text);
                            peekCount++;
                        }
                        else
                        {
                            peekCount--;
                            break;
                        }
                        totalParams++;
                    }
                    isMatch       = isvalidParamList;
                    continueCheck = isMatch;
                    if (continueCheck)
                    {
                        trackNamedArgs = false;
                        if (!string.IsNullOrEmpty(match.Name))
                        {
                            args[match.Name]           = token;
                            args[match.Name + "Value"] = new LArray(paramList);
                        }
                        totalMatched++;
                    }
                    else
                    {
                        break;
                    }
                }
                // Check 3a: Optional words with text
                else if (!match.IsRequired && match.Text != null && match.Text != token.Token.Text)
                {
                    continueCheck = false;
                }
                // Check 3b: Optional words matched
                else if (!match.IsRequired && match.IsMatchingValue(token.Token))
                {
                    continueCheck = true;
                }
                // Check 4: Optional word not matched
                else if (!match.IsRequired && !match.IsMatchingValue(token.Token))
                {
                    continueCheck = false;
                }
                // Check 5a: Expected word
                else if (match.IsRequired && match.TokenType == null && match.Text == token.Token.Text)
                {
                    continueCheck = true;
                    totalMatched++;
                }
                // Check 5b: Expected word in list
                else if (match.IsRequired && match.TokenType == null && match.Values != null)
                {
                    if (!match.IsMatchingValue(token.Token))
                    {
                        isMatch = false;
                        break;
                    }
                    continueCheck = true;
                    valueMatched  = true;
                    totalMatched++;
                }
                // Check 6: check the type of n1
                else if (match.IsMatchingType(token.Token))
                {
                    continueCheck = true;
                    totalMatched++;
                }
                else
                {
                    isMatch = false;
                    break;
                }
                if (continueCheck)
                {
                    if (!string.IsNullOrEmpty(match.Name) && trackNamedArgs)
                    {
                        args[match.Name] = token;
                        if (match.TokenPropEnabled)
                        {
                            // 1. figure out which token map to use.
                            var lookupmap = plugin.StartTokenMap;

                            if (match.TokenType == "@tokenmap1")
                            {
                                lookupmap = plugin.TokenMap1;
                            }
                            else if (match.TokenType == "@tokenmap2")
                            {
                                lookupmap = plugin.TokenMap2;
                            }

                            // Case 1: Start token replacement value
                            if (match.TokenPropValue == "value")
                            {
                                var startToken = token.Token.Text;
                                args[match.Name + "Value"] = lookupmap[startToken];
                            }
                            // Case 2: Token value
                            else if (match.TokenPropValue == "tvalue")
                            {
                                LObject val = LObjects.Null;
                                if (match.TokenType == "@number")
                                {
                                    val = new LNumber((double)token.Token.Value);
                                }
                                else if (match.TokenType == "@time")
                                {
                                    val = new LTime((TimeSpan)token.Token.Value);
                                }
                                else if (match.TokenType == "@word")
                                {
                                    val = new LString((string)token.Token.Value);
                                }
                                else if (match.TokenType == "@starttoken")
                                {
                                    val = new LString(token.Token.Text);
                                }
                                args[match.Name + "Value"] = val;
                            }
                            // Case 2: Token value
                            else if (match.TokenPropValue == "tvaluestring")
                            {
                                LObject val = LObjects.Null;
                                if (match.TokenType == "@number")
                                {
                                    val = new LString(((double)token.Token.Value).ToString(CultureInfo.InvariantCulture));
                                }
                                else if (match.TokenType == "@time")
                                {
                                    val = new LString(((TimeSpan)token.Token.Value).ToString());
                                }
                                else if (match.TokenType == "@starttoken")
                                {
                                    val = new LString(token.Token.Text);
                                }
                                else if (match.TokenType == "@word")
                                {
                                    val = new LString(token.Token.Text);
                                }
                                else if (match.TokenType == "@singularsymbol")
                                {
                                    val = new LString(token.Token.Text);
                                }
                                args[match.Name + "Value"] = val;
                            }
                        }
                        // matching values
                        else if (valueMatched)
                        {
                            args[match.Name + "Value"] = token.Token.Text;
                        }
                    }
                    // Matched: increment.
                    peekCount++;
                    token = this.TokenIt.Peek(peekCount, false);
                }
            }
            var res = new MatchResult(isMatch, null, args);

            res.TotalMatched = totalMatched;
            res.TokenCount   = peekCount;
            return(res);
        }
Exemple #9
0
 public int      GetDays              (LTime target) { var date = target.Value; return date.Days;                                                     }
Exemple #10
0
 public int      GetSeconds(LTime target)
 {
     var date = target.Value; return(date.Seconds);
 }
Exemple #11
0
 /// <summary>
 /// Sets the milliseconds on the date
 /// </summary>
 /// <param name="time">The LTimeType to set</param>
 /// <param name="milliseconds">The milliseconds to set</param>
 public void SetMilliseconds(LTime time, int milliseconds)
 {
     SetDateTime(time, DateTimeKind.Local, -1, -1, -1, -1, -1, -1, milliseconds);
 }
Exemple #12
0
 public int      GetDays(LTime target)
 {
     var date = target.Value; return(date.Days);
 }
Exemple #13
0
 public int      GetSeconds           (LTime target) { var date = target.Value; return date.Seconds;                                                   }
Exemple #14
0
 public string   ToString             (LTime target) { var date = target.Value; return date.ToString("hh mm ss");                     }
Exemple #15
0
 public int      GetMinutes           (LTime target) { var date = target.Value; return date.Minutes;		                                           }
Exemple #16
0
 public int      GetMilliseconds      (LTime target) { var date = target.Value; return date.Milliseconds;                                              }
Exemple #17
0
 public int      GetHours             (LTime target) { var date = target.Value; return date.Hours;                                                     }
Exemple #18
0
 public static void UpdateServices()
 {
     LTime.DoUpdate();
     CoroutineHelper.DoUpdate();
 }
Exemple #19
0
 public int      GetMilliseconds(LTime target)
 {
     var date = target.Value; return(date.Milliseconds);
 }
Exemple #20
0
 /// <summary>
 /// Sets the hours of the date
 /// </summary>
 /// <param name="time">The LTimeType to set</param>
 /// <param name="hours">The hours to set</param>
 /// <param name="minutes">The minutes to set</param>
 /// <param name="seconds">The seconds to set</param>
 /// <param name="milliseconds">The milliseconds to set</param>
 public void SetHours(LTime time, int hours, int minutes, int seconds, int milliseconds)
 {
     SetDateTime(time, DateTimeKind.Local, -1, -1, -1, hours, minutes, seconds, milliseconds);
 }
Exemple #21
0
        private static void SetDateTime(LTime target, DateTimeKind kind, int year = -1, int month = -1, int day = -1,
            int hour = -1, int minute = -1, int second = -1, int millisecond = -1)
        {
            var t = target.Value;
            hour = hour == -1 ? t.Hours : hour;
            minute = minute == -1 ? t.Minutes : minute;
            second = second == -1 ? t.Seconds : second;
            millisecond = millisecond == -1 ? t.Milliseconds : millisecond;

            var finaLTimeTime = new TimeSpan(hour, minute, second, millisecond);
            target.Value = finaLTimeTime;
        }
Exemple #22
0
 public void Set(LTime time, LConversation[] conversations)
 {
     this.CurrentTime         = time;
     this.activeConversations = new List <LConversation>(conversations);
 }
Exemple #23
0
 public void SetDay(int day, LDayPhase dayPhase, int hour, int minute = 0)
 {
     CurrentTime = new LTime(day, hour, minute, dayPhase);
     sendDayPhaseTransitionEvent(dayPhase);
     data.Save();
 }
Exemple #24
0
 public int      GetHours(LTime target)
 {
     var date = target.Value; return(date.Hours);
 }
Exemple #25
0
 public LGameSave(LTime time, LConversation[] conversations)
 {
     this.Time          = time;
     this.Conversations = conversations;
 }
Exemple #26
0
 public int      GetMinutes(LTime target)
 {
     var date = target.Value; return(date.Minutes);
 }
Exemple #27
0
 public void ParseTime()
 {
     Time = new LTime(GroupID);
 }
Exemple #28
0
 public string   ToString(LTime target)
 {
     var date = target.Value; return(date.ToString("hh mm ss"));
 }
Exemple #29
0
    string getConversationName(LContact contact)
    {
        LTime time = story.CurrentTime;

        return(string.Format("{0}{4}{1}{2}{4}{3}", contact.ContactName, LTime.DAY, time.Day, time.Phase, JOIN_CHAR));
    }