Esempio n. 1
0
        ////////////////

        public static void AddValidatedPromise <T>(PromiseValidator validator, Func <T, bool> func) where T : PromiseArguments
        {
            var  mymod = ModHelpersMod.Instance;
            bool conditionsMet;
            T    args;

            lock ( validator ) {
                conditionsMet = mymod.Promises.ValidatedPromiseConditionsMet.Contains(validator);
            }

            if (conditionsMet)
            {
                lock ( validator ) {
                    args = (T)mymod.Promises.ValidatedPromiseArgs[validator];
                }

                if (!func(args))
                {
                    return;
                }
            }

            lock ( validator ) {
                if (!mymod.Promises.ValidatedPromise.ContainsKey(validator))
                {
                    mymod.Promises.ValidatedPromise[validator] = new List <Func <PromiseArguments, bool> >();
                }
                mymod.Promises.ValidatedPromise[validator].Add(U => func((T)U));
            }
        }
Esempio n. 2
0
        public static int CountValidatedPromises(PromiseValidator validator)
        {
            var mymod = ModHelpersMod.Instance;

            lock ( validator ) {
                if (!mymod.Promises.ValidatedPromise.ContainsKey(validator))
                {
                    return(0);
                }
                return(mymod.Promises.ValidatedPromise.Count);
            }
        }
Esempio n. 3
0
        public static void UntriggerValidatedPromise(PromiseValidator validator, object validatorKey)
        {
            var mymod = ModHelpersMod.Instance;

            if (validator.ValidatorKey != validatorKey)
            {
                throw new HamstarException("Validation failed.");
            }

            lock ( validator ) {
                mymod.Promises.ValidatedPromiseConditionsMet.Remove(validator);
                mymod.Promises.ValidatedPromiseArgs.Remove(validator);
            }
        }
Esempio n. 4
0
        ////////////////

        public static void TriggerValidatedPromise(PromiseValidator validator, object validatorKey, PromiseArguments args)
        {
            var  mymod = ModHelpersMod.Instance;
            bool isValidated, isEach;

            if (mymod.Promises == null)
            {
                throw new HamstarException("Promises not loaded.");
            }
            if (validatorKey == null)
            {
                throw new HamstarException("No validation key specified.");
            }
            if (validator.ValidatorKey != validatorKey)
            {
                throw new HamstarException("Validation failed.");
            }

            lock (validator.MyLock) {
                mymod.Promises.ValidatedPromiseConditionsMet.Add(validator);
                mymod.Promises.ValidatedPromiseArgs[validator] = args;
                isValidated = mymod.Promises.ValidatedPromise.ContainsKey(validator);
            }

            if (isValidated)
            {
                IList <Func <PromiseArguments, bool> > funcList;
                int count;

                lock (validator.MyLock) {
                    funcList = mymod.Promises.ValidatedPromise[validator];
                    count    = funcList.Count;
                }

                for (int i = 0; i < funcList.Count; i++)
                {
                    lock (validator.MyLock) {
                        isEach = funcList[i](args);
                    }

                    if (!isEach)
                    {
                        funcList.RemoveAt(i);
                        i--;
                    }
                }
            }
        }
Esempio n. 5
0
 public static void AddValidatedPromise(PromiseValidator validator, Func <bool> action)
 {
     Promises.AddValidatedPromise <PromiseArguments>(validator, _ => action());
 }
Esempio n. 6
0
        ////////////////

        public static bool IsPromiseValidated(PromiseValidator validator)
        {
            lock ( validator ) {
                return(ModHelpersMod.Instance.Promises.ValidatedPromiseConditionsMet.Contains(validator));
            }
        }
Esempio n. 7
0
 public static void TriggerValidatedPromise(PromiseValidator validator, object validatorKey)
 {
     Promises.TriggerValidatedPromise(validator, validatorKey, null);
 }