예제 #1
0
        public override void Bind(Entity entity, Main main, bool creating = false)
        {
            entity.CannotSuspendByDistance = true;

            PointLight light     = entity.GetOrCreate <PointLight>("PointLight");
            Transform  transform = entity.GetOrCreate <Transform>("Transform");

            VoxelAttachable attachable = VoxelAttachable.MakeAttachable(entity, main);

            attachable.Enabled.Value = true;

            light.Add(new Binding <Vector3>(light.Position, () => Vector3.Transform(new Vector3(0, 0, attachable.Offset), transform.Matrix), attachable.Offset, transform.Matrix));

            Switch sw = entity.GetOrCreate <Switch>("Switch");

            if (main.EditorEnabled)
            {
                light.Enabled.Value = true;
            }
            else
            {
                light.Add(new Binding <bool>(light.Enabled, sw.On));
                CommandBinding <IEnumerable <Voxel.Coord>, Voxel> cellFilledBinding = null;

                entity.Add(new NotifyBinding(delegate()
                {
                    Voxel m = attachable.AttachedVoxel.Value.Target.Get <Voxel>();
                    if (cellFilledBinding != null)
                    {
                        entity.Remove(cellFilledBinding);
                    }

                    cellFilledBinding = new CommandBinding <IEnumerable <Voxel.Coord>, Voxel>(m.CellsFilled, delegate(IEnumerable <Voxel.Coord> coords, Voxel newMap)
                    {
                        foreach (Voxel.Coord c in coords)
                        {
                            if (c.Equivalent(attachable.Coord))
                            {
                                sw.On.Value = c.Data == Voxel.States.PoweredSwitch;
                                break;
                            }
                        }
                    });
                    entity.Add(cellFilledBinding);

                    sw.On.Value = m[attachable.Coord] == Voxel.States.PoweredSwitch;
                }, attachable.AttachedVoxel));
            }

            sw.Add(new Binding <Entity.Handle>(sw.AttachedVoxel, attachable.AttachedVoxel));
            sw.Add(new Binding <Voxel.Coord>(sw.Coord, attachable.Coord));

            this.SetMain(entity, main);

            entity.Add("AttachOffset", attachable.Offset);
            entity.Add("OnPowerOn", sw.OnPowerOn);
            entity.Add("OnPowerOff", sw.OnPowerOff);
            entity.Add("On", sw.On, null, true);
        }
예제 #2
0
        public Node StmtSwitch()
        {
            var statementSwitch = new Switch()
            {
                AnchorToken = Expect(TokenCategory.SWITCH)
            };

            Expect(TokenCategory.PARENTHESIS_OPEN);
            statementSwitch.Add(Expr());
            Expect(TokenCategory.PARENTHESIS_CLOSE);

            Expect(TokenCategory.BRACKETS_OPEN);
            while (CurrentToken == TokenCategory.CASE)
            {
                statementSwitch.Add(Case());
            }
            if (CurrentToken == TokenCategory.DEFAULT)
            {
                statementSwitch.Add(DefaultCase());
            }
            Expect(TokenCategory.BRACKETS_CLOSE);

            return(statementSwitch);
        }