public static void Zintegruj(Vector_Rectangle aObj1, Vector_Rectangle aObj2, MapFactory aMapFactory) { Vector_Rectangle obj1; Vector_Rectangle obj2; int delId; int colorGroupListIdx; ColorGroupList colorGroupList; if ((aObj2.parentVectorGroup == null) || (aObj1.parentVectorGroup.lpGroup < aObj2.parentVectorGroup.lpGroup)) { obj1 = aObj1; obj2 = aObj2; } else { obj1 = aObj2; obj2 = aObj1; }; //jeśli sąsiad jest niezintegrowany i ma taki sam kolor if ((obj2.parentVectorGroup == null) && (obj2.color == obj1.color)) //dodajemy do grupy obj na którym jesteśmy { obj2.parentVectorGroup = obj1.parentVectorGroup; obj2.parentVectorGroupId = obj1.parentVectorGroupId; obj2.parentVectorGroup.lpGroup = obj1.parentVectorGroup.lpGroup; obj1.parentVectorGroup.Add(obj1.parentVectorGroup.Count, obj2); //jeśli sąsiad jest ma grupę, ale ta grupa ma takisam kolor, to } else if ((obj2.parentVectorGroup != obj1.parentVectorGroup) && (obj2.color == obj1.color)) { //jeśli nasza grupa jest liczniejsza, to dodajemy grupę sąsiada do naszej if (obj1.parentVectorGroup.Count > obj2.parentVectorGroup.Count) { delId = obj2.parentVectorGroupId; obj1.DopiszGrupe(obj2.parentVectorGroup); colorGroupListIdx = obj2.parentVectorGroup.sourceColor.ToArgb(); } //jeśli grupa sąsiadaj est silniejsza, to dołączamy się do niej else { delId = obj1.parentVectorGroupId; obj2.DopiszGrupe(obj1.parentVectorGroup); colorGroupListIdx = obj1.parentVectorGroup.sourceColor.ToArgb(); }; //usunięcie przepisanej grupy z listy grup //assert(aMapFactory.indexOf(delIdx) >== 0, 'Brak grupy do usunięcia: ' + intToStr(delIdx) + '.'); aMapFactory.Remove(delId); colorGroupList = aMapFactory.vectRectGroupsByColor[colorGroupListIdx]; colorGroupList.Remove(delId); }; }
/// <summary> /// Opens a web map item in a map pane. /// </summary> /// <param name="item"></param> private async void OpenWebMapAsync(object item) { if (item is WebMapItem) { WebMapItem clickedWebMapItem = (WebMapItem)item; //Open WebMap var currentItem = ItemFactory.Create(clickedWebMapItem.ID, ItemFactory.ItemType.PortalItem); if (MapFactory.CanCreateMapFrom(currentItem)) { var newMap = await MapFactory.CreateMapAsync(currentItem); await FrameworkApplication.Panes.CreateMapPaneAsync(newMap); } } }
/// <summary> /// Creates an instance of the given <paramref name="type"/> using the public properties of the /// supplied <paramref name="sample"/> object as input. /// This method will try to determine the least-cost route to constructing the instance, which /// implies mapping as many properties as possible to constructor parameters. Remaining properties /// on the source are mapped to properties on the created instance or ignored if none matches. /// TryCreateInstance is very liberal and attempts to convert values that are not otherwise /// considered compatible, such as between strings and enums or numbers, Guids and byte[], etc. /// </summary> /// <returns>An instance of <paramref name="type"/>.</returns> public static object TryCreateInstance(this Type type, object sample) { Type sourceType = sample.GetType(); SourceInfo sourceInfo = sourceInfoCache.Get(sourceType); if (sourceInfo == null) { sourceInfo = SourceInfo.CreateFromType(sourceType); sourceInfoCache.Insert(sourceType, sourceInfo); } object[] paramValues = sourceInfo.GetParameterValues(sample); MethodMap map = MapFactory.PrepareInvoke(type, sourceInfo.ParamNames, sourceInfo.ParamTypes, paramValues); return(map.Invoke(paramValues)); }
public void ChangeMap(string mcdfname) { DisposeMap(); IMap map = MapFactory.LoadMapFrom(mcdfname); if (map == null) { return; } if (_mapRuntime == null || _isDisposed) { CreateMapRuntime(); } _mapRuntime.Apply(map); }
public List <List <Map> > Build() { var mapFactory = new MapFactory(); var map = new List <List <Map> >(); var mapLine = new List <Map>(); if (_entity != null) { mapLine.Add(mapFactory.GetWithEntity(_entity)); } map.Add(mapLine); return(map); }
private void _buildPcOffline() { #region map_creation var locations = new[] { new Vector2(1.75f, 3.45f), new Vector2(4.78f, 2.02f), new Vector2(-2.04f, 1.34f), new Vector2(0.42f, -0.4f), new Vector2(-2.07f, -2.43f), new Vector2(4.49f, -2.43f) }; MapFactory.GetInstance(); MapFactory.PlatformScale = 2; foreach (var location in locations) { creator.PlatformConstructor(location, Vector2.one * 2, PlatformTypes.Normal); } #endregion #region player_creation const int pScale = 4; var p1 = creator.PlayerConstructor(new Vector2(-2.78f, 2.48f), Vector2.one * pScale, PlayerState.Jump); p1.name = "p1"; var p2 = creator.PlayerConstructor(new Vector2(3.904f, -3.963f), Vector2.one * pScale, PlayerState.Attack); p2.GetComponent <PcKeyboardModel>().walk = new[] { KeyCode.UpArrow, KeyCode.DownArrow, KeyCode.LeftArrow, KeyCode.RightArrow }; p2.GetComponent <PcKeyboardModel>().clicked = KeyCode.KeypadEnter; p2.name = "p2"; var prefabManager = PrefabManager.GetInstance(); if (prefabManager == null) { print("null prefab manager"); } _setPlayerSprite(prefabManager.GetGameObject("P1Sprite"), p1); _setPlayerSprite(prefabManager.GetGameObject("P2Sprite"), p2); #endregion var round = new GameObject("GameRound"); round.AddComponent <GameRound>(); var ui = PrefabManager.GetInstance().GetGameObject("UIController"); Instantiate(ui, canvas); }
public void Apply(string mcdfile) { if (_mapRuntime == null || _isDisposed) { CreateMapRuntime(); } if (mcdfile != null && File.Exists(mcdfile)) { _mapRuntime.Apply(MapFactory.LoadMapFrom(mcdfile)); } else { _mapRuntime.Apply(new Map()); } _mapRuntime.RuntimeExchanger.AutoRefreshWhileFinishOneGrid = false; }
public static void ShopInfo_Req(InPacket lea, Client c) { int CharacterID = lea.ReadInt(); Map map = MapFactory.GetMap(c.Character.MapX, c.Character.MapY); Character Seller = null; foreach (Character chr in map.Characters) { if (chr.CharacterID == CharacterID) { Seller = chr; } } PlayerShopPacket.ShopInfo(c, Seller, CharacterID); }
public static void PvPInvite(InPacket lea, Client c) { int CharacterID = lea.ReadInt(); Map map = MapFactory.GetMap(c.Character.MapX, c.Character.MapY); foreach (Character chr in map.Characters) { if (chr.CharacterID == CharacterID) { c.Character.Competitor = chr; chr.Competitor = c.Character; PvPPacket.PvPInvite(chr.Client, CharacterID); break; } } }
private void btnMainThread_Click(object sender, EventArgs e) { RasterToVectorSettings rasterToVectorSettings = new RasterToVectorSettings(); rasterToVectorSettings.ReadGeoCorners(windowSettings.leftXCoord, windowSettings.leftYCoord, windowSettings.rightXCoord, windowSettings.rightYCoord); rasterToVectorSettings.sourceBmp = sourceBmp; rasterToVectorSettings.CalculateGeoPx(); mapFactory = RasterToVectorRunner.RunRasterToVectorMainThread(rasterToVectorSettings); desinationImageCrooper = new VectorImageCrooper(new Size(sourcePanel.Width, sourcePanel.Height), mapFactory, sourceImageCropper.centerX, sourceImageCropper.centerY, windowSettings); DrawCroppedScaledImage(float.Parse(ScaleTB.Text)); }
public Character(string id, string name) { this.Name = name; this.Map = MapFactory.CreateMap(); this.Gold = 5; this.Level = 1; this.UserId = id; this.XCoord = 10; this.YCoord = 16; this.CurrentHp = 12; this.MaxHp = 12; this.Strength = 3; this.Speed = 1; this.Inventory = new List <Item>(); this.Inventory.Add(new HealingPotion()); }
public async Task Run() { // TODO: check if map is decompressed already? // Load to determine where to write patches to using var map = File.Open(this.Args.MapPath, FileMode.Open); var factory = new MapFactory(Path.GetDirectoryName(this.Args.MapPath)); var h2map = factory.Load(Path.GetFileName(this.Args.MapPath)); if (h2map is not H2mccMap mccMap) { throw new NotSupportedException("Only MCC maps are supported in this tool"); } ScriptTreePatcher.PatchMap(mccMap, map, this.Args.ScriptPatchPath); }
public static void InvenUseSpendStart_Req(InPacket lea, Client c) { short PositionX = lea.ReadShort(); short PositionY = lea.ReadShort(); int Slot = lea.ReadInt(); var chr = c.Character; Map map = MapFactory.GetMap(chr.MapX, chr.MapY); Item Item = chr.Items.getItem((byte)InventoryType.ItemType.Spend3, (byte)Slot); foreach (Character All in map.Characters) { InventoryPacket.UseSpendStart(All.Client, chr, PositionX, PositionY, Item.ItemID, (byte)InventoryType.ItemType.Spend3, Slot); } chr.Items.Remove((byte)InventoryType.ItemType.Spend3, (byte)Slot, 1); UpdateInventory(c, (byte)InventoryType.ItemType.Spend3); }
public override void OnInspectorGUI() { //base.OnInspectorGUI(); DrawDefaultInspector(); MapFactory builder = (MapFactory)target; if (GUILayout.Button("Build Maze")) { builder.SetupScene(); } if (GUILayout.Button("Add Random Walls")) { builder.addSomeWalls(builder.wallsToAdd); } }
private void RunEngine() { var displaySize = new Size(60, 20); var consoleUi = new ConsoleUi(displaySize, new ConsolePresentationConfiguration()); var presentation = consoleUi as Presentation; var logger = consoleUi as Logger; var configuration = ConfigurationFactory.FromFile <MapConfiguration>("mapConfiguration.json"); var dice = new YoloDice(); var mapFactory = new MapFactory(dice, new DefaultHealingHealingShrineFactory(dice)); _engine = new Engine(presentation, logger, mapFactory.GenerateMap(configuration), new YoloTeam(YoloTeamBaseHitpoints)); _engineInitialized.Set(); _engine.Run(); _engine.AnounceResult(); }
public void EnumerableListObjectTestWithAutoMapping() { MapFactory.ResetAllMaps(); var map = MapFactory.CreateMapRule <InnTypeEnum, OutTypeEnum>(); var target = CreateTestTarget(); var timer = Stopwatch.StartNew(); var result = target.Map().To <OutTypeEnum>(); Assert.AreEqual(3, result.Count()); Assert.IsTrue(timer.ElapsedMilliseconds < 20); Assert.IsNotNull(result); Assert.AreEqual((object)target.First().DateTimeValue, result.First().DateTimeValue); Assert.AreEqual(3, result.First().Child.Count()); Assert.AreEqual(2, result.First().Child.First().Child.Count()); }
public StrongholdCommandLineModule(ITribeManager tribeManager, IWorld world, ILocker locker, IStrongholdManager strongholdManager, MapFactory mapFactory, Formula formula, ITileLocator tileLocator) { this.tribeManager = tribeManager; this.world = world; this.locker = locker; this.strongholdManager = strongholdManager; this.mapFactory = mapFactory; this.formula = formula; this.tileLocator = tileLocator; }
private void _serverCreated(SocketIOEvent e) { UnityMainThread.Worker.AddJob(() => { StopCoroutine(_gameKiller); }); print($"receive raw {e}"); if (e.data["success"].b) { UnityMainThread.Worker.AddJob(() => { const int pScale = 4; var p1 = creator.PlayerConstructor(new Vector2(-2.78f, 2.48f), Vector2.one * pScale, PlayerState.Jump); var p2 = creator.PlayerConstructor(new Vector2(3.904f, -3.963f), Vector2.one * pScale, PlayerState.Attack); p1.name = "p1"; p2.name = "p2"; var jsonObject = new JSONObject(); jsonObject.AddField("ids", new JSONObject(JSONObject.Type.ARRAY)); jsonObject["ids"].Add(p1.uuid.ToString()); jsonObject["ids"].Add(p2.uuid.ToString()); NetworkManager.GetInstance().GetComponent().Emit("setPlayerID", jsonObject); #region map_creation var locations = new[] { new Vector2(1.75f, 3.45f), new Vector2(4.78f, 2.02f), new Vector2(-2.04f, 1.34f), new Vector2(0.42f, -0.4f), new Vector2(-2.07f, -2.43f), new Vector2(4.49f, -2.43f) }; MapFactory.GetInstance(); MapFactory.PlatformScale = 2; foreach (var location in locations) { creator.PlatformConstructor(location, Vector2.one * 2, PlatformTypes.Normal); } #endregion }); } else { throw new ApplicationException("return failed on creating server"); } }
public void TestRectMapLoad() { var map = MapFactory.Create(@"E:\github\MagCore\src\server\MagCore.Server\Maps\RectSmall.map"); Assert.IsNotNull(map); Assert.AreEqual(map.Size.H, 10); Assert.AreEqual(map.Size.W, 10); for (int i = 0; i < map.Rows.Count; i++) { for (int j = 0; j < map.Rows[i].Count; j++) { Debug.Write((int)map.Rows[i].Cells[j].Type); } Debug.WriteLine(""); } }
static void Main() { IMap map = new Map("../../../Content/Levels/Level1.txt", 50, 50); IMapFactory mapFactory = new MapFactory(); ITileFactory tileFactory = new TileFactory(); //TODO GO THROUGH ALL TODOS AT END OF DEVELOPMENT using (var game = new Engine.Engine(map, mapFactory, tileFactory)) game.Run(); //при разчиатенто на мапа да сложа енемитата в dictionary //da se podava tozi dictionary na attack v player.cs v metod Act //kogato nqkoi hitva drug, da mu vika //public void UpdateHealthBar() // { // healthBar = new Rectangle((int)this.Position.X, (int)this.Position.Y, this.TextureWidth, this.TextureHeight); // } }
public void TypeTypeConverterTest() { MapFactory.ResetAllMaps(); try { TypeDescriptor.AddAttributes(typeof(Type), new[] { new TypeConverterAttribute(typeof(TypeStringTypeConverter)) }); } catch (Exception) { } var stringRep = (string)TypeDescriptor.GetConverter(typeof(Type)).ConvertTo(typeof(string), typeof(string)); Assert.AreEqual(typeof(string).FullName, stringRep); var type = (Type)TypeDescriptor.GetConverter(typeof(Type)).ConvertFrom(typeof(int).FullName); Assert.AreEqual(typeof(int), type); }
/// <summary> /// Obtains a list of all methods with the given <paramref name="methodName"/> on the given /// <paramref name="obj" />, and invokes the best match for the supplied parameters. /// TryCallMethod is very liberal and attempts to convert values that are not otherwise /// considered compatible, such as between strings and enums or numbers, Guids and byte[16], etc. /// </summary> /// <param name="obj">The type of which an instance should be created.</param> /// <param name="methodName">The name of the overloaded methods.</param> /// <param name="mustUseAllParameters">Specifies whether all supplied parameters must be used in the /// invocation. Unless you know what you are doing you should pass true for this parameter.</param> /// <param name="parameterNames">The names of the supplied parameters.</param> /// <param name="parameterTypes">The types of the supplied parameters.</param> /// <param name="parameterValues">The values of the supplied parameters.</param> /// <returns>The result of the invocation.</returns> public static object TryCallMethod(this object obj, string methodName, bool mustUseAllParameters, string[] parameterNames, Type[] parameterTypes, object[] parameterValues) { bool isStatic = obj is Type; var type = isStatic ? obj as Type : obj.GetType(); var names = parameterNames ?? new string[0]; var types = parameterTypes ?? new Type[0]; var values = parameterValues ?? new object[0]; if (names.Length != values.Length || names.Length != types.Length) { throw new ArgumentException("Mismatching name, type and value arrays (must be of identical length)."); } MethodMap map = MapFactory.DetermineBestMethodMatch(type.Methods(methodName).Cast <MethodBase>(), mustUseAllParameters, names, types, values); return(isStatic ? map.Invoke(values) : map.Invoke(obj, values)); }
public static MapFactory FromBaseObject(BaseObject baseObj) { if (baseObj == null || baseObj.NativeObject == IntPtr.Zero) { return(null); } MapFactory obj = baseObj as MapFactory; if (object.Equals(obj, null)) { obj = new MapFactory(CreatedWhenConstruct.CWC_NotToCreate); obj.BindNativeObject(baseObj.NativeObject, "CMapFactory"); obj.IncreaseCast(); } return(obj); }
public MapImageGeneratorPool(int maxInstanceCount, string outputDir, string outputUrlBase, string mapConfigDocument) { for (int i = 0; i < maxInstanceCount; i++) { try { IMapImageGenerator gen = new MapImageGeneratorDefault(); IMap map = MapFactory.LoadMapFrom(mapConfigDocument); gen.ApplyMap(map); _instances.Add(new MapImageGeneratorInstance(gen)); } catch (Exception ex) { Log.WriterException(ex); } } }
private void _buildAppOffline() { Screen.orientation = ScreenOrientation.Portrait; #region map_creation var locations = new[] { new Vector2(1.75f, 6.45f), new Vector2(4.78f, 4.02f), new Vector2(-2.04f, 2.34f), new Vector2(0.42f, -0.4f), new Vector2(-2.07f, -4.43f), new Vector2(4.49f, -4.43f) }; var mapFactory = MapFactory.GetInstance(); MapFactory.PlatformScale = 2; mapFactory.YLocation = 9; mapFactory.SpawnSpeed = 2.5f; foreach (var location in locations) { creator.PlatformConstructor(location, Vector2.one * 2, PlatformTypes.Normal); } #endregion #region player_creation const int pScale = 4; var p1 = creator.PlayerConstructor(new Vector2(-2.78f, 2.48f), Vector2.one * pScale, PlayerState.Jump); p1.name = "p1"; var p2 = creator.PlayerConstructor(new Vector2(3.904f, -3.963f), Vector2.one * pScale, PlayerState.Attack); p2.name = "p2"; var prefabManager = PrefabManager.GetInstance(); if (prefabManager == null) { print("null prefab manager"); } _setPlayerSprite(prefabManager.GetGameObject("P1Sprite"), p1); _setPlayerSprite(prefabManager.GetGameObject("P2Sprite"), p2); #endregion var round = new GameObject("GameRound"); round.AddComponent <GameRound>(); var ui = PrefabManager.GetInstance().GetGameObject("AppUIController"); Instantiate(ui, canvas); }
public bool Spawn(Entity entity) { var mapPoint = _map[entity.Position.CurY][entity.Position.CurX]; if (mapPoint.Entity is Empty) { var newMapPoint = new MapFactory().GetWithEntity(entity); _map[entity.Position.CurY][entity.Position.CurX] = newMapPoint; return(true); } else if (CanDestroy(entity, mapPoint.Entity)) { (entity as IDamager).DamageDestroyable(mapPoint.Entity as IDestroyable); CleanDead(); } return(false); }
private void PopulateMap(List <List <Map> > map, List <List <char> > charMap) { var entityFactory = new EntityFactory(); var mapFactory = new MapFactory(); for (int y = 0; y < charMap.Count; y++) { for (int x = 0; x < charMap[y].Count; x++) { var character = charMap[y][x]; var entity = entityFactory.GetEntity(character); var mapPoint = mapFactory.GetWithEntity(entity); entity.Position.CurX = x; entity.Position.CurY = y; map[y][x] = mapPoint; } } }
public BarbarianTribeWeightedConfigurator(MapFactory mapFactory, IRegionManager regionManager, ICityManager cityManager) { this.mapFactory = mapFactory; this.regionManager = regionManager; this.cityManager = cityManager; if (Config.map_width % REGION_WIDTH != 0) { throw new Exception("Map width must be divisible by barbarian tribe width"); } if (Config.map_height % REGION_WIDTH != 0) { throw new Exception("Map height must be divisible by barbarian tribe width"); } }
public CityTileNextToFriendLocationStrategy(int distance, IPlayer player, MapFactory mapFactory, ITileLocator tileLocator, Random random, Formula formula, IForestManager forestManager, IWorld world) { this.distance = distance; this.player = player; this.mapFactory = mapFactory; this.tileLocator = tileLocator; this.random = random; this.formula = formula; this.forestManager = forestManager; this.world = world; }
public void SaveToFile(string path, bool olt = false) { if (olt) { var oltMapHeader = new MapHeader(); *(oltMapHeader.Ctm) = 0x43; *(oltMapHeader.Ctm + 1) = 0x54; *(oltMapHeader.Ctm + 2) = 0x4D; oltMapHeader.Version_hi = 1; oltMapHeader.Version_lo = 0; MapFactory.SaveToFile(path, oltMapHeader, Entries, true); } else { MapFactory.SaveToFile(path, mapHeader, Entries); } }
private void init() { missionMap = MapFactory.loadMissionFromTemplate("configs/maps/templates/smallRoadToBoss", 1000); missionMap.currentMapPoint = null; background = "texture/main_scene"; var image = Resources.Load <Sprite>(background); transform.Find(Constants.BACKGROUND).GetComponent <SpriteRenderer>().sprite = image; printFightPoints(); PartiesSingleton.currentGame.activeHeroes.Clear(); PartiesSingleton.currentGame.activeHeroes.AddRange(PartiesSingleton.currentGame.selectedHeroes); foreach (var p in PartiesSingleton.currentGame.activeHeroes) { p.initHealthMana(); } }
static void Main(string[] args) { var maps = Directory.GetFiles(@"D:\H2vMaps", "*.map"); foreach (var map in maps) { var factory = new MapFactory(Path.GetDirectoryName(map)); var h2map = factory.Load(Path.GetFileName(map)); if (h2map is not H2vMap scene) { throw new NotSupportedException("Only Vista maps are supported"); } Console.WriteLine("Checking " + map); foreach (var v in scene.Scenario.TriggerVolumes) { var vect = v.Orientation; var vect2 = v.OrientationAxis; if (Math.Abs(vect.Length() - 1) > 0.001f) { Console.WriteLine($"Invalid Vector: {v.Description}/orientation, len: {vect.Length()} - values {vect.X},{vect.Y},{vect.Z}"); } if (vect.Z > 0.001f) { Console.WriteLine($"NonZero Z component {v.Description}/orientation, len: {vect.Length()} - values {vect.X},{vect.Y},{vect.Z}"); Console.WriteLine($" /something, len: {vect2.Length()} - values {vect2.X},{vect2.Y},{vect2.Z}"); } if (Math.Abs(vect2.Length() - 1) > 0.001f) { Console.WriteLine($"Invalid Vector: {v.Description}/something, len: {vect2.Length()} - values {vect2.X},{vect2.Y},{vect2.Z}"); } } } Console.WriteLine("done"); Console.ReadLine(); }
private void btnMainThread_Click(object sender, EventArgs e) { R2VSettings r2vSettings = new R2VSettings(); r2vSettings.ReadGeoCorners(windowSettings.leftXCoord, windowSettings.leftYCoord, windowSettings.rightXCoord, windowSettings.rightYCoord); r2vSettings.sourceBmp = posterizedBmp; r2vSettings.CalculateGeoPx(); r2vSettings.sliceWidth = windowSettings.sliceWidthVect; r2vSettings.sliceHeight = windowSettings.sliceHeightVect; r2vSettings.simplifyPhase1 = windowSettings.SimplifyPhase1(); r2vSettings.simplifyPhase2 = windowSettings.SimplifyPhase2(); r2vSettings.simplifyPhase3 = windowSettings.SimplifyPhase3(); mapFactory = R2VRunner.RunR2VMainThread(r2vSettings, new UpdateInfoBoxTimeDelegate(UpdateInfoBoxTime)); desinationImageCropper = new VectorImageCrooper(new Size(posterizedPanel.Width, posterizedPanel.Height), mapFactory, posterizedImageCropper.centerX, posterizedImageCropper.centerY, windowSettings, posterizedBmp); DrawCroppedScaledImage(float.Parse(txtScaleLvlVect.Text), UpdateInfoBoxTime); }
public VectorImageCrooper(Size aPanelSize, MapFactory aMapFactory, int aCenterX, int aCenterY, MainWindowSettings aSettings) : base(aPanelSize, 0, 0) { mapFactory = aMapFactory; settings = aSettings; if (aMapFactory != null) { srcBmpWidth = aMapFactory.vectArr.Length; Debug.Assert(aMapFactory.vectArr[0] != null, "aMapFactory.vectArr[0] jest null"); srcBmpHeight = aMapFactory.vectArr[0].Length; } centerX = aCenterX; centerY = aCenterY; }
//HEY! groups[index] = subexpression for regexpression. public static Map CreateMap(Game game, Texture2D spriteMap, String[] gameDesc) { Map ret = null; //int subMapCounter = 0; Regex tileRegex = new Regex(@"t (?:(\d+),(\d+)) (?:(\d+),(\d+)|null) (?:(\d+),(\d+)|null) (true)?"); //This is looking at specific locations in the original tile map. The 2nd to last entry is a 'refernce' to be used for the submap, and the string is a reference to determine what the tile corresponds to. Regex subMapRegex = new Regex(@"(\d+)\-(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+) ?(\d+)"); //This is defined to be the tiles specified for a submap Regex mapDefine = new Regex(@"md (\d+) (\d+)"); //This is defined as the dimensions of the map. //Regex subMapModeRegex = new Regex(@"(?:(\d),(\d)|null) (?:(\d),(\d)|null) (?:(\d),(\d)|null) (true|false)"); Regex mapSet = new Regex(@"ms (\d+) (\d+) (\d+)"); //Regex mapCreate = new Regex( //Regex tileRegex = new Regex(@"(?:(\d),(\d)|null) (?:(\d),(\d)|null) (?:(\d),(\d)|null) (true|false)"); MatchCollection matches; MapFactory mapFact = null; TileFactory tiles = new TileFactory(spriteMap); SubMapFactory subMaps = new SubMapFactory(tiles); //For each string of lines in the textual map foreach (String line in gameDesc) { //If this is defined to be a map, if (mapDefine.IsMatch(line)) { matches = mapDefine.Matches(line); mapFact = new MapFactory(subMaps, int.Parse(matches[0].Groups[1].Value), int.Parse(matches[0].Groups[2].Value)); } //If it is information for a tile, else if (tileRegex.IsMatch(line)) { matches = tileRegex.Matches(line); //Collection of matches based on regex //[1],[2] = first set of (\d+),(\d+) tiles.SetBaseSprite(new Rectangle(int.Parse(matches[0].Groups[1].Value) * 32, int.Parse(matches[0].Groups[2].Value) * 32, 32, 32)); //[3] [4] = second set of (\d+),(\d+). Most often, both are null. if (matches[0].Groups[3].Success) { tiles.SetAccentSprite(new Rectangle(int.Parse(matches[0].Groups[3].Value) * 32, int.Parse(matches[0].Groups[4].Value) * 32, 32, 32)); } //[5] = passability [6] = third set of (\d+),(\d+). Most often, both are null. if (matches[0].Groups[5].Success) { tiles.SetTopSprite(new Rectangle(int.Parse(matches[0].Groups[5].Value) * 32, int.Parse(matches[0].Groups[6].Value) * 32, 32, 32)); } //[7] = Passability tiles.SetPassible(matches[0].Groups[7].Success); tiles.AddTile(); } //Or if it is information for a submap, else if (subMapRegex.IsMatch(line)) { matches = subMapRegex.Matches(line); //From the first tile entry onward... for (int x = 0; x < 32; x++) { //[2] = row entry, [x+3] = col entry, [1] = sub-map subMaps.setTile(x, int.Parse(matches[0].Groups[2].Value), int.Parse(matches[0].Groups[x + 3].Value), int.Parse(matches[0].Groups[1].Value)); } if (int.Parse(matches[0].Groups[1].Value) == 31) subMaps.AddSubMap(); } //If it is defined for a specific submap (Submap 1-2, Submap 2-2, etc...), else if (mapSet.IsMatch(line)) { matches = mapSet.Matches(line); mapFact.setSubSector(int.Parse(matches[0].Groups[1].Value), int.Parse(matches[0].Groups[2].Value), int.Parse(matches[0].Groups[3].Value)); } else { throw new System.ArgumentException("Line does not match known regex lines", "line"); } } //Generate the sprite map based on the map returned. spriteMap is the 2D map used as a reference. ret = mapFact.generate(spriteMap); return ret; }
private void btnStartR2V_Click_1(object sender, EventArgs e) { Debug.Assert(sourceBmp != null, "Nie wgrano obrazu źródłowego."); RasterToVectorSettings rasterToVectorSettings = new RasterToVectorSettings{ sourceBmp = sourceBmp }; rasterToVectorSettings.ReadGeoCorners(windowSettings.leftXCoord, windowSettings.leftYCoord, windowSettings.rightXCoord, windowSettings.rightYCoord); if (rbMainThread.Checked) { mapFactory = RasterToVectorRunner.RunRasterToVectorMainThread(rasterToVectorSettings); // Bitmap res = mapFactory.getBitmap(new Rectangle(0, 0, sourceBmp.Width, sourceBmp.Height)); } else if (rbSeparateThread.Checked) { RasterToVectorRunner.RunRasterToVectorSeparateThread(); } else { Debug.Assert(false, "Oba: Main i Separate = false"); } }