Exemplo n.º 1
0
        /// <inheritdoc />
        public void SetName(Entity entity, string value)
        {
            try
            {
                if (!entity.HasComponent <Nameable>())
                {
                    return;
                }
                if (value == null)
                {
                    value = string.Empty;
                }
                int maxLength = _engineService.MaxNameLength;

                if (value.Length > maxLength)
                {
                    value = value.Substring(0, maxLength);
                }

                Nameable component = entity.GetComponent <Nameable>();
                component.Value = value;
            }
            catch (Exception)
            {
                // Do nothing.
            }
        }
Exemplo n.º 2
0
        public void BuildEntity(Entity entity, params object[] args)
        {
            string    dataFile  = "./Levels/" + args[0] + ".json";
            LevelData levelData = _dataManager.Load <LevelData>(dataFile);

            Nameable nameable = _componentFactory.Create <Nameable>();

            nameable.Name = levelData.Name;

            Map map = _componentFactory.Create <Map>();

            map.Width       = levelData.Width;
            map.Height      = levelData.Height;
            map.Spritesheet = _contentManager.Load <Texture2D>("./Graphics/Tilesets/" + levelData.Spritesheet);
            map.Tiles       = levelData.Tiles;
            map.BGM         = _contentManager.Load <Song>("./Audio/BGM/" + levelData.BGMFile);

            Script script = _componentFactory.Create <Script>();

            script.FilePath = "Levels/" + levelData.Script;

            Heartbeat hb = _componentFactory.Create <Heartbeat>();

            hb.Interval = 1.0f;

            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(map.BGM);

            entity.AddComponent(nameable);
            entity.AddComponent(map);
            entity.AddComponent(script);
            entity.AddComponent(hb);
        }
Exemplo n.º 3
0
        public void BuildEntity(Entity entity, params object[] args)
        {
            string       enemyResourceFile = args[0] as string;
            string       dataFile          = "\\Enemies\\" + enemyResourceFile + ".json";
            CreatureData data = _dataManager.Load <CreatureData>(dataFile);

            Sprite sprite = _componentFactory.Create <Sprite>();

            sprite.Texture = _contentManager.Load <Texture2D>(".\\Graphics\\" + _fileSystem.Path.ChangeExtension(data.TextureFile, null));
            foreach (Animation animation in data.Animations)
            {
                sprite.Animations.Add(animation.Name, animation);
                if (animation.IsDefaultAnimation)
                {
                    sprite.SetCurrentAnimation(animation.Name);
                }
            }

            entity.AddComponent(sprite);
            entity.AddComponent(_componentFactory.Create <Health>());
            Position position = _componentFactory.Create <Position>();

            position.X = (int?)args[1] ?? 0;
            position.Y = (int?)args[2] ?? 0;
            entity.AddComponent(position);
            entity.AddComponent(_componentFactory.Create <Renderable>());
            entity.AddComponent(_componentFactory.Create <Velocity>());
            entity.AddComponent(_componentFactory.Create <Hostile>());
            entity.AddComponent(_componentFactory.Create <LocalData>());

            Nameable nameable = _componentFactory.Create <Nameable>();

            nameable.Name = data.Name;
            entity.AddComponent(nameable);

            Script script = _componentFactory.Create <Script>();

            script.FilePath = data.Script;
            entity.AddComponent(script);

            CollisionBox box = _componentFactory.Create <CollisionBox>();

            box.Width   = data.CollisionWidth;
            box.Height  = data.CollisionHeight;
            box.OffsetX = data.CollisionOffsetX;
            box.OffsetY = data.CollisionOffsetY;
            entity.AddComponent(box);

            Heartbeat hb = _componentFactory.Create <Heartbeat>();

            hb.Interval = data.HeartbeatInterval;
            entity.AddComponent(hb);

            Gravity gravity = _componentFactory.Create <Gravity>();

            gravity.Speed = 4.0f;
            entity.AddComponent(gravity);
        }
Exemplo n.º 4
0
            public void Sets_Name_of_TestNameable()
            {
                var      nameToSet = this.fixture.Create <string>();
                Nameable tn        = this.nf.Create <TestNameable>(
                    nameToSet);

                Assert.NotNull(
                    nameToSet);
                Assert.Equal(
                    nameToSet,
                    tn.Name);
            }
Exemplo n.º 5
0
        public void GetName_ShouldReturnValue()
        {
            Entity   entity            = _world.CreateEntity();
            Nameable nameableComponent = new Nameable
            {
                Name = "MyName"
            };

            entity.AddComponent(nameableComponent);
            string name = _methods.GetName(entity);

            Assert.AreEqual(name, "MyName");
        }
Exemplo n.º 6
0
        public void EntityMethods_SetName_ShouldMatch()
        {
            EntityWorld world     = TestHelpers.CreateEntityWorld();
            Entity      entity    = world.CreateEntity();
            Nameable    component = new Nameable
            {
                Value = "InitialName"
            };

            entity.AddComponent(component);
            Assert.AreEqual("InitialName", _entityMethods.GetName(entity));
            _entityMethods.SetName(entity, "NewName");
            Assert.AreEqual("NewName", _entityMethods.GetName(entity));
        }
Exemplo n.º 7
0
        public void EntityMethods_GetName_ShouldReturnValue()
        {
            EntityWorld world     = TestHelpers.CreateEntityWorld();
            Entity      entity    = world.CreateEntity();
            Nameable    component = new Nameable
            {
                Value = "MyName"
            };

            entity.AddComponent(component);
            string name = _entityMethods.GetName(entity);

            Assert.AreEqual(name, "MyName");
        }
Exemplo n.º 8
0
        public void NameableAssignments()
        {
            // Act
            var value1 = new Nameable <int>(1);
            var value2 = new Nameable <int>(2, "Name");
            var value3 = (Nameable <int>) 3;
            var value4 = (Nameable <int>) 4;
            var value5 = value4.AsName("Name");

            // Assert
            Assert.Equal(1, actual: value1.Value); Assert.Null(value1.Name);
            Assert.Equal(2, actual: value2.Value); Assert.NotNull(value2.Name);
            Assert.Equal(3, actual: value3.Value); Assert.Null(value3.Name);
            Assert.Equal(4, actual: (int)value4); Assert.Null(value4.Name);
            Assert.Equal(4, actual: (int)value5); Assert.NotNull(value5.Name);
        }
Exemplo n.º 9
0
        public void NameableStatics()
        {
            // Arrange
            var value1 = new Nameable <int>(1);
            var value2 = new Nameable <int>(2, "Name");

            // Act
            var compare1 = Nameable.Compare(value1, value1);
            var compare2 = Nameable.Compare(value1, value2);
            var equals1  = Nameable.Equals(value1, value1);
            var equals2  = Nameable.Equals(value1, value2);
            var type1    = Nameable.GetUnderlyingType(value1.GetType());

            // Assert
            Assert.Equal(0, actual: compare1); Assert.Equal(-1, actual: compare2);
            Assert.True(equals1); Assert.False(equals2);
            Assert.Equal(typeof(int), type1);
        }
Exemplo n.º 10
0
        public void EntityMethods_SetName_ShouldTrimTo256Characters()
        {
            EntityWorld world     = TestHelpers.CreateEntityWorld();
            Entity      entity    = world.CreateEntity();
            Nameable    component = new Nameable
            {
                Value = "InitialName"
            };

            entity.AddComponent(component);

            string longName = string.Empty;

            for (int x = 0; x < 1000; x++)
            {
                longName += "A";
            }
            _entityMethods.SetName(entity, longName);
            var name = _entityMethods.GetName(entity);

            Assert.AreEqual(_engineService.MaxNameLength, name.Length);
        }
Exemplo n.º 11
0
        public void BuildEntity(Entity entity, params object[] args)
        {
            int    width       = (int)args[0];
            int    height      = (int)args[1];
            string name        = (string)args[2];
            string texturePath = (string)args[3];

            TileData[,] tiles = (TileData[, ])args[4];

            Map map = _componentFactory.Create <Map>();

            map.Width       = width;
            map.Height      = height;
            map.Spritesheet = _content.Load <Texture2D>(".\\Graphics\\Tilesets\\" + texturePath);
            map.Tiles       = tiles;
            entity.AddComponent(map);

            Nameable nameable = _componentFactory.Create <Nameable>();

            nameable.Name = name;
            entity.AddComponent(nameable);
        }
Exemplo n.º 12
0
 public ByteArrayField(Nameable nameProvider, ResourceType type)
 {
     this.nameProvider = nameProvider;
     this.type         = type;
 }
Exemplo n.º 13
0
 public ByteArrayField(Nameable nameProvider, ResourceType type, string rootProcessInstanceId, DateTime removalTime) : this(nameProvider, type)
 {
     this.removalTime           = removalTime;
     this.rootProcessInstanceId = rootProcessInstanceId;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NameableConverter"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <exception cref="System.ArgumentException">NameableConverterBadCtorArg - type</exception>
 public NameableConverter(Type type)
 {
     NameableType            = type;
     UnderlyingType          = Nameable.GetUnderlyingType(type) ?? throw new ArgumentException(nameof(type), "type");
     UnderlyingTypeConverter = TypeDescriptor.GetConverter(UnderlyingType);
 }
Exemplo n.º 15
0
 public DefaultCharSequence(Nameable named)
 {
     this.named = named;
 }
Exemplo n.º 16
0
        public void BuildEntity(Entity entity, params object[] args)
        {
            _characterType = args.Length > 0 ? (CharacterType)args[0] : CharacterType.X;
            LoadPlayerDataFile();

            entity.AddComponent(BuildSprite());
            PlayerCharacter character = _componentFactory.Create <PlayerCharacter>();

            character.MaxDashLength    = _playerData.MaxDashLength;
            character.MaxJumpLength    = _playerData.MaxJumpLength;
            character.MoveSpeed        = _playerData.MoveSpeed;
            character.DashSpeed        = _playerData.DashSpeed;
            character.JumpSpeed        = _playerData.JumpSpeed;
            character.CharacterType    = _characterType;
            character.MaxNumberOfJumps = _playerData.MaxNumberOfJumps;

            entity.AddComponent(character);

            Health health = _componentFactory.Create <Health>();

            health.MaxHitPoints     = 16;
            health.CurrentHitPoints = 8;
            entity.AddComponent(health);

            Position position = _componentFactory.Create <Position>();

            position.Facing = Direction.Right;
            position.X      = (int?)args[1] ?? 0;
            position.Y      = (int?)args[2] ?? 0;
            entity.AddComponent(position);

            entity.AddComponent(_componentFactory.Create <LocalData>());
            entity.AddComponent(_componentFactory.Create <Velocity>());
            entity.AddComponent(_componentFactory.Create <Renderable>());
            entity.AddComponent(BuildCollisionBox());

            Nameable nameable = _componentFactory.Create <Nameable>();

            nameable.Name = _playerData.Name;
            entity.AddComponent(nameable);

            Heartbeat heartbeat = _componentFactory.Create <Heartbeat>();

            heartbeat.Interval = _playerData.HeartbeatInterval;
            entity.AddComponent(heartbeat);

            Script script = _componentFactory.Create <Script>();

            script.FilePath = _playerData.Script;
            entity.AddComponent(script);

            PlayerStateMap stateMap = _componentFactory.Create <PlayerStateMap>();

            stateMap.States.Add(PlayerState.Idle, _playerStateFactory.Create <IdleState>());
            stateMap.States.Add(PlayerState.Move, _playerStateFactory.Create <MoveState>());
            stateMap.States.Add(PlayerState.Dash, _playerStateFactory.Create <DashState>());
            stateMap.States.Add(PlayerState.Jump, _playerStateFactory.Create <JumpState>());
            stateMap.States.Add(PlayerState.Fall, _playerStateFactory.Create <FallState>());
            stateMap.States.Add(PlayerState.Land, _playerStateFactory.Create <LandState>());
            stateMap.CurrentState = PlayerState.Idle;
            entity.AddComponent(stateMap);

            Gravity gravity = _componentFactory.Create <Gravity>();

            gravity.Speed = _playerData.GravitySpeed;
            entity.AddComponent(gravity);

            PlayerStats stats = _componentFactory.Create <PlayerStats>();

            stats.Lives = 2;
            entity.AddComponent(stats);

            EntitySystem.BlackBoard.SetEntry("Player", entity);
        }