private void categoriseComponents(UnitEntity e) { foreach (BaseUnitComponent buc in e.Components) { switch (buc.Category) { case ComponentCategory.Graphic: BaseDrawableUnitComponent comp = buc as BaseDrawableUnitComponent; if (comp == null) { throw new Exception("GraphicCategory Component is not a DrawableUnitComponent!"); } this.graphicComponents.Add(comp); break; case ComponentCategory.Movement: this.movementComponents.Add(buc); break; case ComponentCategory.Misc: this.miscComponents.Add(buc); break; default: throw new Exception("Unknown category!"); } } // just to make sure, clear all components in unitentity e.Components.Clear(); }
public UnitEntity CreateUnitEntity(UnitEntityType type) { UnitEntity e = null; switch (type) { case UnitEntityType.Cube: e = buildCube(); break; default: throw new ArgumentException("Unknown unit entity."); } return(e); }
public override void Initialize() { // testing UnitEntity e = unitBuilder.CreateUnitEntity(UnitEntityType.Cube); categoriseComponents(e); vpService = (IViewportService)this.Game.Services.GetService(typeof(IViewportService)); vpService.MainViewChanged += new ViewportService.ViewportChangedHandler(vpService_MainViewChanged); this.mapViewport = vpService.MainView; base.Initialize(); }
protected UnitEntity buildCube() { UnitEntity e = new UnitEntity(); UnitServices unitservices = new UnitServices(); unitservices.AddService(typeof(IUnitEntityType), e); GraphicComponent graphic = new GraphicComponent(); // get provided services // init each component initializeComponent(graphic, unitservices); graphic.LoadContent(); e.Components.Add(graphic); return e; }
protected UnitEntity buildCube() { UnitEntity e = new UnitEntity(); UnitServices unitservices = new UnitServices(); unitservices.AddService(typeof(IUnitEntityType), e); GraphicComponent graphic = new GraphicComponent(); // get provided services // init each component initializeComponent(graphic, unitservices); graphic.LoadContent(); e.Components.Add(graphic); return(e); }