예제 #1
0
        public static void ComputeItems(ILi <IStickHitItem> target,
                                        IList <Ops.Hit> hit, IList <Ops.EndHit> endHit,
                                        IStickHitItemFactory itemFactory)
        {
            if (hit.Count <= 0 && endHit.Count <= 0)
            {
                return;
            }

            var items = target.AsWrite();

            for (int i = 0, n = hit.Count; i < n; ++i)
            {
                items.Add(itemFactory.Create(hit[i]));
            }

            if (endHit.Count > 0)
            {
                for (int i = items.Count - 1; i >= 0; --i)
                {
                    for (int j = 0, m = endHit.Count; j < m; ++j)
                    {
                        var start = items[i].Hit;
                        var end   = endHit[j];
                        if (start.From == end.From && start.To == end.To)
                        {
                            itemFactory.Dispose(items[i]);
                            items.RemoveAt(i);
                        }
                    }
                }
            }
        }
예제 #2
0
        public static Wa Wa <T>(this IEngine engine, CompositeDisposable cd, ILi <T> li, Func <T, object> extractor)
        {
            var liwa = new Wa(engine);

            liwa.Setup(cd, engine, li, extractor);
            return(liwa);
        }
예제 #3
0
        public static void Items(
            ILi <ITodoItem> target,
            IEl <int> nextId,
            IMultiOp <string> newItem_,
            IOp <Empty> deleteCompletedItems_,
            IMultiOp <string> deleteItem_,
            ITodoItemFactory factory)
        {
            var   newItem = newItem_.Read();
            Empty tmp;
            bool  deleteCompletedItems = deleteCompletedItems_.TryRead(out tmp);
            var   deleteItem           = deleteItem_.Read();

            if (newItem.Count <= 0 &&
                !deleteCompletedItems &&
                deleteItem.Count <= 0)
            {
                return;
            }

            var items = target.AsWrite();

            if (newItem.Count > 0)
            {
                for (int i = 0, n = newItem.Count; i < n; ++i)
                {
                    items.Add(factory.Create((nextId.Read() + i).ToString(), newItem[i]));
                }
                nextId.Write(nextId.Read() + newItem.Count);
            }

            if (deleteCompletedItems)
            {
                items.RemoveAll(it =>
                {
                    if (it.IsCompleted.Read())
                    {
                        factory.Dispose(it);
                        return(true);
                    }
                    return(false);
                });
            }

            if (deleteItem.Count > 0)
            {
                items.RemoveAll(it =>
                {
                    if (deleteItem.Contains(it.Id))
                    {
                        factory.Dispose(it);
                        return(true);
                    }
                    return(false);
                });
            }
        }
예제 #4
0
        public State(CompositeDisposable cd, IEngine engine)
        {
            NextId               = engine.El(1);
            CreateNewItem        = engine.MultiOp <string>();
            Items                = engine.Li(new List <ITodoItem>());
            ToggleItemComplete   = engine.MultiOp <string>();
            UncompletedCount     = engine.El(0);
            DeleteCompletedItems = engine.Op <Empty>();
            DeleteItem           = engine.MultiOp <string>();
            EditItem             = engine.Op <string>();
            EditingItemId        = engine.El <string>(null);
            FinishEditItem       = engine.Op <string>();
            ItemFactory          = new TodoItem.Factory(cd, engine,
                                                        ToggleItemComplete, EditingItemId, FinishEditItem);

            engine.Computer(cd,
                            new object[] {
                Items,
                ToggleItemComplete,
            },
                            () => Computers.UncompletedCount(
                                UncompletedCount,
                                Items
                                )
                            );

            engine.Computer(cd,
                            new object[]
            {
                CreateNewItem,
                DeleteCompletedItems,
                DeleteItem
            },
                            () => Computers.Items(
                                Items,
                                NextId,
                                CreateNewItem,
                                DeleteCompletedItems,
                                DeleteItem,
                                ItemFactory
                                )
                            );

            engine.Computer(cd,
                            new object[]
            {
                EditItem,
                FinishEditItem
            },
                            () => Computers.EditingItemId(
                                EditingItemId,
                                EditItem,
                                FinishEditItem
                                )
                            );
        }
예제 #5
0
        public ModifierList(IEngine engine, IList <Info.IModifier> info)
        {
            var items = new List <IModifierItem>();

            for (int i = 0, n = info != null ? info.Count : 0; i < n; ++i)
            {
                items.Add(new ModifierItem(engine, info[i]));
            }
            Items = engine.Li(items);
        }
예제 #6
0
        internal void Setup <T>(CompositeDisposable cd, IEngine engine, ILi <T> li, Func <T, object> extractor)
        {
            var lastCd      = new CompositeDisposable();
            var lastTargets = new List <object>();

            cd.Add(lastCd);
            engine.Computer(cd,
                            new object[] { li },
                            () =>
            {
                var l       = li.Read();
                var targets = new List <object>();
                for (int i = 0, n = l.Count; i < n; ++i)
                {
                    targets.Add(extractor(l[i]));
                }

                if (targets.Count == lastTargets.Count)
                {
                    bool isSame = true;
                    for (int i = 0, n = targets.Count; i < n; ++i)
                    {
                        if (!ReferenceEquals(targets[i], lastTargets[i]))
                        {
                            isSame = false;
                            break;
                        }
                    }
                    if (isSame)
                    {
                        return;
                    }
                }
                lastTargets.Clear();
                lastTargets.AddRange(targets);

                lastCd.Dispose();
                if (targets.Count > 0)
                {
                    engine.Computer(lastCd,
                                    targets.ToArray(),
                                    () =>
                    {
                        // Work around to ensure different instance of action is registerd
                        l.GetHashCode();
                        inner.Fire(Empty.Instance);
                        engine.MarkDirty(this);
                    }
                                    );
                }
            }
                            );
        }
예제 #7
0
        public static void UncompletedCount(IEl <int> target, ILi <ITodoItem> items_)
        {
            var items            = items_.Read();
            int uncompletedCount = 0;

            for (int i = 0, n = items.Count; i < n; ++i)
            {
                if (!items[i].IsCompleted.Read())
                {
                    ++uncompletedCount;
                }
            }
            if (uncompletedCount != target.Read())
            {
                target.Write(uncompletedCount);
            }
        }
예제 #8
0
        public static void ComputeList(ILi <IModifierItem> target,
                                       IEntity entity, IOp <Ops.Tick> tick, IList <Ops.Hit> hit,
                                       IModifierItemFactory itemFactory)
        {
            Ops.Tick t;
            if (!tick.TryRead(out t) && hit.Count <= 0)
            {
                return;
            }

            var items = target.AsWrite();

            for (int i = 0, n = hit.Count; i < n; ++i)
            {
                var h = hit[i];
                if (h.To != entity)
                {
                    continue;
                }

                var a = h.From.Hitters.AddModifier;
                if (a == null)
                {
                    continue;
                }

                for (int j = 0, m = a.Modifiers.Count; j < m; ++j)
                {
                    items.Add(itemFactory.Create(a.Modifiers[j]));
                }
            }

            if (tick.TryRead(out t))
            {
                items.RemoveAll(it =>
                {
                    if (it.Remain.Read() == 0)
                    {
                        itemFactory.Dispose(it);
                        return(true);
                    }
                    return(false);
                });
            }
        }
예제 #9
0
            public State(IEngine engine)
            {
                Ids  = engine.Li(new List <string>());
                Xs   = engine.Li(new List <int>());
                Ys   = engine.Li(new List <int>());
                Vxs  = engine.Li(new List <int>());
                Vys  = engine.Li(new List <int>());
                Tick = engine.MultiOp <int>();
                Add  = engine.MultiOp <Rigidbody>();

                engine.Computer(cd,
                                new object[] { Tick, Add },
                                () =>
                {
                    var tick = Tick.Read();
                    var add  = Add.Read();

                    if (tick.Count <= 0 && add.Count <= 0)
                    {
                        return;
                    }

                    var xs = Xs.AsWrite();
                    var ys = Ys.AsWrite();

                    {
                        var vxs = Vxs.Read();
                        var vys = Vys.Read();

                        for (int t = 0, c = tick.Count; t < c; ++t)
                        {
                            var dt = tick[t];

                            for (int i = 0, n = Ids.Read().Count; i < n; ++i)
                            {
                                xs[i] += vxs[i] * dt;
                                ys[i] += vys[i] * dt;
                            }
                        }
                    }

                    if (add.Count > 0)
                    {
                        for (int i = 0, n = add.Count; i < n; ++i)
                        {
                            var r = add[i];
                            xs.Add(r.X);
                            ys.Add(r.Y);
                        }
                    }
                }
                                );

                engine.Computer(cd,
                                new object[] { Add },
                                () =>
                {
                    var add = Add.Read();

                    if (add.Count <= 0)
                    {
                        return;
                    }

                    var ids = Ids.AsWrite();
                    var vxs = Vxs.AsWrite();
                    var vys = Vys.AsWrite();

                    for (int i = 0, n = add.Count; i < n; ++i)
                    {
                        var r = add[i];
                        ids.Add(r.Id);
                        vxs.Add(r.Vx);
                        vys.Add(r.Vy);
                    }
                }
                                );
            }
예제 #10
0
            public State(IEngine engine)
            {
                Ids    = engine.Li(new List <string>());
                Sheets = engine.Li(new List <object>());
                CurrentFrameIndexes = engine.Li(new List <int>());
                TotalFrames         = engine.Li(new List <int>());
                Speeds = engine.Li(new List <int>());
                Tick   = engine.MultiOp <int>();
                Add    = engine.MultiOp <Sprite>();

                engine.Computer(cd,
                                new object[] { Tick, Add },
                                () =>
                {
                    var tick = Tick.Read();
                    var add  = Add.Read();

                    if (tick.Count <= 0 && add.Count <= 0)
                    {
                        return;
                    }

                    var currentFrameIndexes = CurrentFrameIndexes.AsWrite();

                    {
                        var totalFrames = TotalFrames.Read();
                        var speeds      = Speeds.Read();

                        for (int t = 0, c = tick.Count; t < c; ++t)
                        {
                            var dt = tick[t];

                            for (int i = 0, n = Ids.Read().Count; i < n; ++i)
                            {
                                var current            = currentFrameIndexes[i];
                                current                = (current + dt * speeds[i]) % totalFrames[i];
                                currentFrameIndexes[i] = current;
                            }
                        }
                    }

                    if (add.Count > 0)
                    {
                        for (int i = 0, n = add.Count; i < n; ++i)
                        {
                            var s = add[i];
                            currentFrameIndexes.Add(s.CurrentFrameIndex);
                        }
                    }
                }
                                );

                engine.Computer(cd,
                                new object[] { Add },
                                () =>
                {
                    var add = Add.Read();

                    if (add.Count <= 0)
                    {
                        return;
                    }

                    var ids         = Ids.AsWrite();
                    var sheets      = Sheets.AsWrite();
                    var totalFrames = TotalFrames.AsWrite();
                    var speeds      = Speeds.AsWrite();

                    for (int i = 0, n = add.Count; i < n; ++i)
                    {
                        var s = add[i];
                        ids.Add(s.Id);
                        sheets.Add(s.Sheet);
                        totalFrames.Add(s.TotalFrame);
                        speeds.Add(s.Speed);
                    }
                }
                                );
            }
예제 #11
0
 public StickHitList(IEngine engine)
 {
     Items = engine.Li(new List <IStickHitItem>());
 }