Example #1
0
        public static ITimeable BuildTimeTernary(List <Token> tokens)
        {
            IBoolable condition = BoolableBuilder.Build(GetTernaryCondition(tokens));

            if (condition.IsNull())
            {
                return(null);
            }

            ITimeable confirmationCase = TimeableBuilder.Build(GetTernaryConfirmation(tokens));

            if (confirmationCase.IsNull())
            {
                return(null);
            }

            ITimeable negationCase = TimeableBuilder.Build(GetTernaryNegation(tokens));

            if (negationCase.IsNull())
            {
                return(null);
            }

            return(new TimeTernary(condition, confirmationCase, negationCase));
        }
Example #2
0
        public static IBoolable BuildTimTim(string name, List <Argument> args)
        {
            if (args.Count != 2)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 2 time arguments.");
            }

            ITimeable itim1 = TimeableBuilder.Build(args[0].tokens);
            ITimeable itim2 = TimeableBuilder.Build(args[1].tokens);

            if (itim1.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as time.");
            }
            if (itim2.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as time.");
            }

            if (name.Equals("samedate") || name.Equals("samedates") ||
                name.Equals("thesamedate") || name.Equals("thesamedates"))
            {
                return(new FuncSamedates(itim1, itim2));
            }
            else if (name.Equals("sameclock") || name.Equals("sameclocks") ||
                     name.Equals("thesameclock") || name.Equals("thesameclocks"))
            {
                return(new FuncSamedates(itim1, itim2));
            }

            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Example #3
0
        private static ITimeable BuildFromDateAndClock(List <Token> tokens)
        {
            List <Token> beforeComma = new List <Token>();
            List <Token> afterComma  = new List <Token>();
            int          level       = 0;
            bool         pastComma   = false;

            foreach (Token tok in tokens)
            {
                if (tok.GetTokenType().Equals(TokenType.BracketOn))
                {
                    level++;
                }
                if (tok.GetTokenType().Equals(TokenType.BracketOff))
                {
                    level--;
                }

                if (tok.GetTokenType().Equals(TokenType.Comma) && level == 0)
                {
                    pastComma = true;
                }
                else
                {
                    if (pastComma)
                    {
                        afterComma.Add(tok);
                    }
                    else
                    {
                        beforeComma.Add(tok);
                    }
                }
            }

            ITimeable itim = TimeableBuilder.Build(beforeComma);

            if (itim.IsNull())
            {
                return(null);
            }

            IClock clock = BuildClock(afterComma);

            if (clock.IsNull())
            {
                return(null);
            }

            if (itim is Time)
            {
                (itim as Time).SetNewClock(clock);
                return(itim);
            }
            else
            {
                return(new TimeableWithClock(itim, clock));
            }
        }
Example #4
0
 public void CmdIncreaseTime(float value)
 {
     // Tells the server to increase the time by value
     Debug.Log(" Server sending command to increase time");
     if (timer == null)
     {
         timer = GameObject.FindObjectOfType <UpdateTime> ();
     }
     timer.IncreaseTime(value);
 }
Example #5
0
    // Use this for initialization

    void Start()
    {
        if (isLocalPlayer)
        {
            GameObject.FindObjectOfType <StashButtonController> ().player = this.gameObject;
        }

        justDropped      = null;
        timer            = GameObject.FindObjectOfType <UpdateTime> ();
        spriteRenderer   = gameObject.GetComponent <SpriteRenderer> ();
        profileContainer = gameObject.GetComponent <PlayerProfileContainer> ();
        playerScore      = gameObject.GetComponent <PlayerScore> ();
    }
Example #6
0
        IEnumerator CoWaitForBeats(ITimeable timeable, int count)
        {
            int beats    = timing.beatCount;
            int endBeats = beats + count;

            while (beats < endBeats)
            {
                beats = timing.beatCount;
                yield return(null);
            }

            timeable.OnBeatsElapsed();
        }
Example #7
0
        private static IBoolable BuildBetweenTimes(ITimeable tim, List <Token> left, List <Token> right)
        {
            ITimeable timLeft  = TimeableBuilder.Build(left);
            ITimeable timRight = TimeableBuilder.Build(right);

            if (timLeft.IsNull() || timRight.IsNull())
            {
                return(null);
            }
            else
            {
                return(new BetweenTimes(tim, timLeft, timRight));
            }
        }
        private static ICommand BuildComplex(TokenType type, IListable list, ITimeable time)
        {
            switch (type)
            {
            case TokenType.Recreate:
                return(new RecreateTo(list, time));

            case TokenType.Remodify:
                return(new RemodifyTo(list, time));

            case TokenType.Reaccess:
                return(new ReaccessTo(list, time));
            }
            throw new SyntaxErrorException("ERROR! Command not indentified."); // this is never thrown
        }
        private static ICommand BuildSimple(TokenType type, ITimeable time)
        {
            switch (type)
            {
            case TokenType.Recreate:
                return(new RecreateTo(new StringVariableRefer("this"), time));

            case TokenType.Remodify:
                return(new RemodifyTo(new StringVariableRefer("this"), time));

            case TokenType.Reaccess:
                return(new ReaccessTo(new StringVariableRefer("this"), time));
            }
            throw new SyntaxErrorException("ERROR! Command not indentified."); // this is never thrown
        }
Example #10
0
    private IEnumerator DecrementTimer(int seconds, ITimeable callback)
    {
        this.seconds = seconds;

        callback.OnStartTimer();

        while (this.seconds > 0)
        {
            yield return(new WaitForSeconds(1f));

            this.seconds--;
            callback.OnIncrementTimer();
        }

        callback.OnFinishTimer();
    }
Example #11
0
        public static INumerable BuildTimTim(string name, List <Argument> args)
        {
            if (args.Count != 2)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 2 time arguments.");
            }

            ITimeable itim1 = TimeableBuilder.Build(args[0].tokens);
            ITimeable itim2 = TimeableBuilder.Build(args[1].tokens);

            if (itim1.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as time.");
            }
            if (itim2.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as time.");
            }

            if (name.Equals("yearsbetween"))
            {
                return(new Func__TimeBetween(itim1, itim2, TimeVariableType.Year));
            }
            else if (name.Equals("monthsbetween"))
            {
                return(new Func__TimeBetween(itim1, itim2, TimeVariableType.Month));
            }
            else if (name.Equals("daysbetween"))
            {
                return(new Func__TimeBetween(itim1, itim2, TimeVariableType.Day));
            }
            else if (name.Equals("hoursbetween"))
            {
                return(new Func__TimeBetween(itim1, itim2, TimeVariableType.Hour));
            }
            else if (name.Equals("minutesbetween"))
            {
                return(new Func__TimeBetween(itim1, itim2, TimeVariableType.Minute));
            }
            else if (name.Equals("secondsbetween"))
            {
                return(new Func__TimeBetween(itim1, itim2, TimeVariableType.Second));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Example #12
0
        private static IBoolable BuildBetween(List <Token> tokens)
        {
            int betweenIndex = TokenGroups.IndexOfTokenOutsideBrackets(tokens, TokenType.Between);
            int andIndex     = TokenGroups.IndexOfTokenOutsideBrackets(tokens, TokenType.And);

            if (andIndex < betweenIndex)
            {
                return(null);
            }

            if (betweenIndex == andIndex - 1)
            {
                throw new SyntaxErrorException("ERROR! Expression 'between' do not contain definition of value of left boundary.");
            }

            if (betweenIndex == 0)
            {
                throw new SyntaxErrorException("ERROR! Expression 'between' starts with keyword 'between' and thus do not contain comparing value.");
            }

            if (andIndex == tokens.Count - 1)
            {
                throw new SyntaxErrorException("ERROR! Expression 'between' ends with keyword 'and' and thus do not contain definition of value of right boundary.");
            }

            List <Token> valueTokens = tokens.Take(betweenIndex).ToList();
            List <Token> leftTokens  = tokens.GetRange(betweenIndex + 1, andIndex - betweenIndex - 1);
            List <Token> rightTokens = tokens.Skip(andIndex + 1).ToList();

            INumerable inum = NumerableBuilder.Build(valueTokens);

            if (!inum.IsNull())
            {
                return(BuildBetweenNumbers(inum, leftTokens, rightTokens));
            }

            ITimeable itim = TimeableBuilder.Build(valueTokens);

            if (!itim.IsNull())
            {
                return(BuildBetweenTimes(itim, leftTokens, rightTokens));
            }

            return(null);
        }
Example #13
0
        public static INumerable BuildTim(string name, List <Argument> args)
        {
            if (args.Count != 1)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 1 time argument.");
            }

            ITimeable itim = TimeableBuilder.Build(args[0].tokens);

            if (itim.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Argument of function " + name + " cannot be read as time.");
            }

            if (name.Equals("yearday") || name.Equals("dayofyear"))
            {
                return(new FuncYearday(itim));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Example #14
0
        private static IBoolable BuildTimeComparison(List <Token> tokens)
        {
            int index = tokens.TakeWhile(x => !TokenGroups.IsTimeComparingSign(x.GetTokenType())).Count();

            if (index == 0 || index == tokens.Count - 1)
            {
                return(null);
            }

            ComparisonType type        = tokens[index].GetTokenType().Equals(TokenType.IsAfter) ? ComparisonType.Bigger : ComparisonType.Smaller;
            List <Token>   leftTokens  = tokens.GetRange(0, index);
            List <Token>   rightTokens = tokens.GetRange(index + 1, tokens.Count - index - 1);
            ITimeable      leftL       = TimeableBuilder.Build(leftTokens);
            ITimeable      rightL      = TimeableBuilder.Build(rightTokens);

            if (leftL.IsNull() || rightL.IsNull())
            {
                return(null);
            }

            return(new TimeComparison(leftL, rightL, type));
        }
Example #15
0
        public static ITimeable BuildRelativeTime(List <Token> tokens)
        {
            List <RelativeTimeStruct> relativeTimes = new List <RelativeTimeStruct>();
            List <Token> currentTokens = new List <Token>();

            foreach (Token tok in tokens)
            {
                currentTokens.Add(tok);

                if (IsTimeDirection(tok))
                {
                    List <RelativeTimeStruct> rtss = BuildRelativeTimeStructs(currentTokens.Take(currentTokens.Count - 1).ToList(), currentTokens.Last());
                    if (rtss.IsNull())
                    {
                        return(null);
                    }
                    else
                    {
                        relativeTimes.AddRange(rtss);
                    }
                    currentTokens.Clear();
                }
            }

            if (currentTokens.Count == 0)
            {
                throw new SyntaxErrorException("ERROR! Relative time expression do not have definition for reference time.");
            }

            ITimeable itim = TimeableBuilder.Build(currentTokens);

            if (itim.IsNull())
            {
                return(null);
            }

            return(new RelativeTimeExpression(relativeTimes, itim));
        }
Example #16
0
 public FuncSamedates(ITimeable arg0, ITimeable arg1)
 {
     this.arg0 = arg0;
     this.arg1 = arg1;
 }
        public static ICommand Build(List <Token> tokens)
        {
            TokenType type = tokens[0].GetTokenType();
            string    name = type.Equals(TokenType.Recreate) ? "recreate" : (type.Equals(TokenType.Remodify) ? "remodify" : "reaccess");

            tokens.RemoveAt(0);

            if (tokens.Where(t => t.GetTokenType().Equals(TokenType.To)).Count() > 1)
            {
                throw new SyntaxErrorException("ERROR! In " + name + " command keyword 'to' occurs too many times.");
            }

            List <Token> part1  = new List <Token>();
            List <Token> part2  = new List <Token>();
            bool         pastTo = false;

            foreach (Token tok in tokens)
            {
                if (tok.GetTokenType().Equals(TokenType.To))
                {
                    pastTo = true;
                }
                else
                {
                    if (pastTo)
                    {
                        part2.Add(tok);
                    }
                    else
                    {
                        part1.Add(tok);
                    }
                }
            }

            if (part2.Count == 0)
            {
                throw new SyntaxErrorException("ERROR! Command " + name + " is too short and do not contain all necessary information.");
            }

            ITimeable expression2 = TimeableBuilder.Build(part2);

            if (expression2.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second part of command " + name + " cannot be read as time.");
            }

            if (part1.Count == 0)
            {
                return(BuildSimple(type, expression2));
            }
            else
            {
                IListable expression1 = ListableBuilder.Build(part1);
                if (expression1.IsNull())
                {
                    throw new SyntaxErrorException("ERROR! First part of command " + name + " cannot be read as list.");
                }
                return(BuildComplex(type, expression1, expression2));
            }
        }
Example #18
0
 public void Attach(ITimeable timeable)
 {
     this.timeables.Add(timeable);
 }
Example #19
0
    public IEnumerator StartTimerCouroutine(int seconds, ITimeable callback)
    {
        couroutine = DecrementTimer(seconds, callback);

        return(couroutine);
    }
        public static ICommand Build(List <Token> tokens)
        {
            string name = tokens[0].GetContent();

            tokens.RemoveAt(0);
            tokens.RemoveAt(0);

            if (tokens.Count == 0)
            {
                throw new SyntaxErrorException("ERROR! Variable " + name + " has no assigned value.");
            }

            if (name.Contains('.'))
            {
                return(BuildWithPoint(tokens, name));
            }

            if (!InterVariables.GetInstance().Contains(name))
            {
                IListable value = ListableBuilder.Build(tokens);
                if (value.IsNull())
                {
                    throw new SyntaxErrorException("ERROR! There are is something wrong with assigning value to variable " + name + ".");
                }

                if (value is IBoolable)
                {
                    InterVariables.GetInstance().Add(name, InterVarType.Bool);
                    return(new BoolDeclaration(name, (IBoolable)value));
                }
                else if (value is INumerable)
                {
                    InterVariables.GetInstance().Add(name, InterVarType.Number);
                    return(new NumericDeclaration(name, (INumerable)value));
                }
                else if (value is ITimeable)
                {
                    InterVariables.GetInstance().Add(name, InterVarType.Time);
                    return(new TimeDeclaration(name, (ITimeable)value));
                }
                else if (value is IStringable)
                {
                    InterVariables.GetInstance().Add(name, InterVarType.String);
                    return(new StringDeclaration(name, (IStringable)value));
                }
                else
                {
                    InterVariables.GetInstance().Add(name, InterVarType.List);
                    return(new ListDeclaration(name, value));
                }
            }
            else
            {
                InterVar ivar = InterVariables.GetInstance().GetVar(name);

                if (ivar.IsBool())
                {
                    IBoolable value = BoolableBuilder.Build(tokens);
                    if (value.IsNull())
                    {
                        throw new SyntaxErrorException("ERROR! Value assigned to variable " + name + " must be logical.");
                    }
                    return(new BoolDeclaration(name, value));
                }
                else
                {
                    if (ivar.IsNumber())
                    {
                        INumerable value = NumerableBuilder.Build(tokens);
                        if (value.IsNull())
                        {
                            throw new SyntaxErrorException("ERROR! Value assigned to variable " + name + " must be numeric.");
                        }
                        return(new NumericDeclaration(name, value));
                    }
                    else if (ivar.IsTime())
                    {
                        ITimeable value = TimeableBuilder.Build(tokens);
                        if (value.IsNull())
                        {
                            throw new SyntaxErrorException("ERROR! Value assigned to variable " + name + " must be time.");
                        }
                        return(new TimeDeclaration(name, value));
                    }
                    else if (ivar.IsString())
                    {
                        IStringable value = StringableBuilder.Build(tokens);
                        if (value.IsNull())
                        {
                            throw new SyntaxErrorException("ERROR! Value assigned to variable " + name + " must be text.");
                        }
                        return(new StringDeclaration(name, value));
                    }
                    else
                    {
                        IListable value = ListableBuilder.Build(tokens);
                        if (value.IsNull())
                        {
                            throw new SyntaxErrorException("ERROR! Value assigned to variable " + name + " must be list.");
                        }
                        return(new ListDeclaration(name, value));
                    }
                }
            }
        }
Example #21
0
 public RecreateTo(IListable list, ITimeable newTime)
 {
     this.list    = list;
     this.newTime = newTime;
 }
Example #22
0
 public RemodifyTo(IListable list, ITimeable newTime)
 {
     this.list    = list;
     this.newTime = newTime;
 }
Example #23
0
 public void Detach(ITimeable timeable)
 {
     this.timeables.Remove(timeable);
 }
Example #24
0
        public static ITimeable Build(List <Token> tokens)
        {
            // remove first and last bracket if it is there
            while (tokens[0].GetTokenType().Equals(TokenType.BracketOn) && tokens[tokens.Count - 1].GetTokenType().Equals(TokenType.BracketOff) &&
                   !Brackets.ContainsIndependentBracketsPairs(tokens, BracketsType.Normal))
            {
                List <Token> tokensCopy = tokens.Select(t => t.Clone()).ToList();
                tokensCopy.RemoveAt(tokens.Count - 1);
                tokensCopy.RemoveAt(0);
                tokens = tokensCopy;
            }

            // try to build simple one-token Timeable
            if (tokens.Count == 1)
            {
                if (tokens[0].GetTokenType().Equals(TokenType.Variable))
                {
                    string str = tokens[0].GetContent();
                    if (InterVariables.GetInstance().Contains(str, InterVarType.Time))
                    {
                        return(new TimeVariableRefer(str));
                    }
                }
            }

            //try to build time function
            if (Functions.IsPossibleFunction(tokens))
            {
                ITimeable itim = TimeFunction.Build(tokens);
                if (!itim.IsNull())
                {
                    return(itim);
                }
            }

            // try to build time ternary
            if (TernaryBuilder.IsPossibleTernary(tokens))
            {
                ITimeable itim = TernaryBuilder.BuildTimeTernary(tokens);
                if (!itim.IsNull())
                {
                    return(itim);
                }
            }

            // try to build relative time expression
            if (tokens.Where(t => IsTimeDirection(t)).Count() > 0)
            {
                ITimeable itim = BuildRelativeTime(tokens);
                if (!itim.IsNull())
                {
                    return(itim);
                }
            }

            if (HasOneComma(tokens))
            {
                // try to build Timeable from date and clock
                ITimeable itim = BuildFromDateAndClock(tokens);
                if (!itim.IsNull())
                {
                    return(itim);
                }
            }
            else
            {
                // try to build Timeable from date only
                if (ContainMonth(tokens))
                {
                    ITimeable itim = BuildFromDate(tokens);
                    if (!itim.IsNull())
                    {
                        return(itim);
                    }
                }

                // try to build Timeable from clock only
                if (ContainSemicolons(tokens))
                {
                    ITimeable itim = BuildFromClock(tokens);
                    if (!itim.IsNull())
                    {
                        return(itim);
                    }
                }
            }

            return(null);
        }
Example #25
0
 public TimeDeclaration(string name, ITimeable value)
 {
     this.name  = name;
     this.value = value;
 }
Example #26
0
 public static bool IsReady(ITimeable c) => c.CT >= ActionAmount;
Example #27
0
 public ReaccessTo(IListable list, ITimeable newTime)
 {
     this.list    = list;
     this.newTime = newTime;
 }
Example #28
0
 public BetweenTimes(ITimeable value, ITimeable leftBound, ITimeable rightBound)
 {
     this.value      = value;
     this.leftBound  = leftBound;
     this.rightBound = rightBound;
 }
Example #29
0
 public TimeComparison(ITimeable leftSide, ITimeable rightSide, ComparisonType type)
 {
     this.leftSide  = leftSide;
     this.rightSide = rightSide;
     this.type      = type;
 }
Example #30
0
 public TimeTernary(IBoolable condition, ITimeable leftValue, ITimeable rightValue)
 {
     this.condition  = condition;
     this.leftValue  = leftValue;
     this.rightValue = rightValue;
 }