private void AddEntityType( IDictionary <Type, IDictionary <Type, EntityTypeWrapper> > destinationSystemEntityTypes, HashSet <Type> allEntityTypes, Type entityType, EntityTypeWrapper entityTypeWrapper) { if (allEntityTypes.Add(entityType)) { if (destinationSystemEntityTypes.ContainsKey( entityTypeWrapper.Attribute.DestinationSystem)) { destinationSystemEntityTypes[ entityTypeWrapper.Attribute.DestinationSystem] .Add(entityType, entityTypeWrapper); } else { throw new InvalidOperationException(string.Format( Resources.EntityTypeDestinationSystemDoesNotExist, entityTypeWrapper.Attribute.DestinationSystem.FullName, entityType.FullName)); } } else { throw new InvalidOperationException(string.Format( Resources.EntityTypeDefinedMultipleTimes, entityType.FullName)); } }
public void SpawnEntityFromMapData(EntityTypeWrapper setype, Color col, double x, double y) { double px = x * Block.BLOCK_WIDTH; double py = y * Block.BLOCK_HEIGHT; DynamicEntity d; AddEntity(d = setype.Get(), px, py); d.InitAfterMapParse(col); }
public void LoadMapFromResources(AbstractMarioPower p) { ImageMapParser parser = new ImageMapParser(new OpenRasterImage(ResourceAccessor.GetMap(mapWorld, mapLevel))); setSize(parser.GetWidth(), parser.GetHeight()); for (int x = 0; x < parser.GetWidth(); x++) { for (int y = 0; y < parser.GetHeight(); y++) { int imgX = x; int imgY = parser.GetHeight() - (1 + y); Color col_b = parser.map.GetColor(ImageMapParser.LAYER_BLOCKS, imgX, imgY); Color col_e = parser.map.GetColor(ImageMapParser.LAYER_ENTITIES, imgX, imgY); Color col_t = parser.map.GetColor(ImageMapParser.LAYER_TRIGGER, imgX, imgY); Color col_p = parser.map.GetColor(ImageMapParser.LAYER_PIPEZONES, imgX, imgY); Color col_v = parser.map.GetColor(ImageMapParser.LAYER_PLAYERVISION, imgX, imgY); Block block = parser.GetBlock(imgX, imgY); EntityTypeWrapper set = parser.GetEntity(imgX, imgY); AddTriggerType att = parser.GetTrigger(imgX, imgY); PipeZoneTypeWrapper pzt = parser.GetPipeZone(imgX, imgY); if (block == null) { throw new NotSupportedException(String.Format("Could not parse Block-Color in Map: {0} ({1}|{2})", col_b, x, y)); } else { AddBlock(block, x, y); } if (set == null) { } // No Entity else if (!set.IsSet()) { throw new NotSupportedException(String.Format("Could not parse SpawnEntity-Color in Map: {0} ({1}|{2})", col_e, x, y)); } else { SpawnEntityFromMapData(set, col_e, x, y); } if (att == AddTriggerType.UNKNOWN_TRIGGER) { throw new NotSupportedException(String.Format("Could not parse Trigger-Color in Map: {0} ({1}|{2})", col_t, x, y)); } else if (att != AddTriggerType.NO_TRIGGER) { AddTriggerFromMapData(att, col_t, x, y, p); } if (pzt == null) { } // No Zone else if (!pzt.IsSet()) { throw new NotSupportedException(String.Format("Could not parse PipeZone-Color in Map: {0} ({1}|{2})", col_p, x, y)); } else { AddPipeZoneFromMapData(pzt, x, y); } } } offset.AddVisionBoxes(parser.GetVisionZones()); //############# //AFTER MAP GEN //############# offset.Calculate(player.GetPosition(), viewPortWidth, viewPortHeight, mapRealWidth, mapRealHeight, false, false); foreach (DynamicEntity e in dynamicEntityList) { e.OnAfterMapGen(); } foreach (Trigger t in triggerList) { t.OnAfterMapGen(); } }