public IEnumerable <IMapObject> Create(UniqueNumberGenerator generator, Box box, string texture, int roundDecimals) { var useCentroid = _useCentroid.GetValue(); // The lower Z plane will be the triangle, with the lower Y value getting the two corners var c1 = new Vector3(box.Start.X, box.Start.Y, box.Start.Z).Round(roundDecimals); var c2 = new Vector3(box.End.X, box.Start.Y, box.Start.Z).Round(roundDecimals); var c3 = new Vector3(box.Center.X, box.End.Y, box.Start.Z).Round(roundDecimals); var centroid = new Vector3((c1.X + c2.X + c3.X) / 3, (c1.Y + c2.Y + c3.Y) / 3, box.End.Z); var c4 = (useCentroid ? centroid : new Vector3(box.Center.X, box.Center.Y, box.End.Z)).Round(roundDecimals); var faces = new[] { new[] { c1, c2, c3 }, new[] { c4, c1, c3 }, new[] { c4, c3, c2 }, new[] { c4, c2, c1 } }; var solid = new Solid(generator.Next("MapObject")); solid.Data.Add(new ObjectColor(Colour.GetRandomBrushColour())); foreach (var arr in faces) { var face = new Face(generator.Next("Face")) { Plane = new Plane(arr[0], arr[1], arr[2]), Texture = { Name = texture } }; face.Vertices.AddRange(arr); solid.Data.Add(face); } solid.DescendantsChanged(); yield return(solid); }
//List<Texture2D> itemTextures; public GameScreen(GraphicsDevice graphicDevice, int width, int height) : base("Game", graphicDevice, Vector2.Zero, Color.White, width, height) { IsRendering = true; _backgroundColor = Color.White; _random = new UniqueNumberGenerator(); spawningTime = TimeSpan.FromMilliseconds(150); elapsedSpawningTime = TimeSpan.Zero; elapsedDifficultyTime = TimeSpan.Zero; difficultyTime = TimeSpan.FromSeconds(20); elapsedArrowTime = TimeSpan.Zero; fallingLocation = new Vector2[4]; fallingLocation[0] = new Vector2(125, 0); fallingLocation[1] = new Vector2(385, 0); fallingLocation[2] = new Vector2(655, 0); fallingLocation[3] = new Vector2(935, 0); _drawTime = TimeSpan.FromSeconds(1); _elapsedDrawTime = TimeSpan.Zero; _drawCounter = 0; }
public override IMapObject ToMapObject(UniqueNumberGenerator generator) { var grp = new Group(generator.Next("MapObject")); Editor.Apply(grp); return(grp); }
private IEnumerable <IMapObject> CreateCopy(UniqueNumberGenerator gen, Vector3 origin, Vector3 rotation, List <string> names, List <IMapObject> objectsToPaste, bool makeEntitesUnique, bool prefixEntityNames, string entityNamePrefix) { var box = new Box(objectsToPaste.Select(x => x.BoundingBox)); var rads = rotation * (float)Math.PI / 180; var mov = Matrix4x4.CreateTranslation(-box.Center); // Move to zero var rot = Matrix4x4.CreateFromQuaternion(Quaternion.CreateFromYawPitchRoll(rads.Y, rads.X, rads.Z)); // Do rotation var fin = Matrix4x4.CreateTranslation(origin); // Move to final origin var transform = mov * rot * fin; foreach (var mo in objectsToPaste) { // Copy, transform and fix entity names var copy = (IMapObject)mo.Copy(gen); // Transform the object copy.Transform(transform); // Paste special will always texture lock (always uniform too, only translation and rotation possible) foreach (var t in copy.Data.OfType <ITextured>()) { t.Texture.TransformUniform(transform); } FixEntityNames(copy, names, makeEntitesUnique, prefixEntityNames, entityNamePrefix); yield return(copy); } }
private IEnumerable <IMapObject> GroupCopy(UniqueNumberGenerator gen, IMapObject allGroup, List <IMapObject> copy, PasteSpecialDialog.PasteSpecialGrouping grouping) { switch (grouping) { case PasteSpecialDialog.PasteSpecialGrouping.None: // No grouping - add directly to tree return(copy); case PasteSpecialDialog.PasteSpecialGrouping.Individual: // Use one group per copy var group = new Group(gen.Next("MapObject")); copy.ForEach(x => x.Hierarchy.Parent = group); return(new List <IMapObject> { group }); case PasteSpecialDialog.PasteSpecialGrouping.All: // Use one group for all copies copy.ForEach(x => x.Hierarchy.Parent = allGroup); return(new IMapObject[0]); default: throw new ArgumentOutOfRangeException(); } }
public IEnumerable <IMapObject> Create(UniqueNumberGenerator generator, Box box, string texture, int roundDecimals) { var solid = new Solid(generator.Next("MapObject")); solid.Data.Add(new ObjectColor(Colour.GetRandomBrushColour())); // The lower Z plane will be base var c1 = new Vector3(box.Start.X, box.Start.Y, box.Start.Z).Round(roundDecimals); var c2 = new Vector3(box.End.X, box.Start.Y, box.Start.Z).Round(roundDecimals); var c3 = new Vector3(box.End.X, box.End.Y, box.Start.Z).Round(roundDecimals); var c4 = new Vector3(box.Start.X, box.End.Y, box.Start.Z).Round(roundDecimals); var c5 = new Vector3(box.Center.X, box.Center.Y, box.End.Z).Round(roundDecimals); var faces = new[] { new[] { c1, c2, c3, c4 }, new[] { c2, c1, c5 }, new[] { c3, c2, c5 }, new[] { c4, c3, c5 }, new[] { c1, c4, c5 } }; foreach (var arr in faces) { var face = new Face(generator.Next("Face")) { Plane = new Plane(arr[0], arr[1], arr[2]), Texture = { Name = texture } }; face.Vertices.AddRange(arr); solid.Data.Add(face); } solid.DescendantsChanged(); yield return(solid); }
private Face ReadFace(string line, UniqueNumberGenerator generator) { const NumberStyles ns = NumberStyles.Float; var parts = line.Split(' ').Where(x => !String.IsNullOrWhiteSpace(x)).ToList(); Assert(parts[0] == "("); Assert(parts[4] == ")"); Assert(parts[5] == "("); Assert(parts[9] == ")"); Assert(parts[10] == "("); Assert(parts[14] == ")"); var face = new Face(generator.Next("Face")) { Plane = new Plane( NumericsExtensions.Parse(parts[1], parts[2], parts[3], ns, CultureInfo.InvariantCulture), NumericsExtensions.Parse(parts[6], parts[7], parts[8], ns, CultureInfo.InvariantCulture), NumericsExtensions.Parse(parts[11], parts[12], parts[13], ns, CultureInfo.InvariantCulture) ), Texture = { Name = parts[15] } }; // Cater for older-style map formats // TODO Quake 3: when the MAP face has 24 parts, the last three parts are: content_flags, surface_flags, value if (parts.Count == 21 || parts.Count == 24) { QuakeEdAlignTextureToWorld(face); var xshift = float.Parse(parts[16], ns, CultureInfo.InvariantCulture); var yshift = float.Parse(parts[17], ns, CultureInfo.InvariantCulture); var rotate = float.Parse(parts[18], ns, CultureInfo.InvariantCulture); var xscale = float.Parse(parts[19], ns, CultureInfo.InvariantCulture); var yscale = float.Parse(parts[20], ns, CultureInfo.InvariantCulture); face.Texture.Rotation = -rotate; face.Texture.Rotation = rotate; face.Texture.XScale = xscale; face.Texture.YScale = yscale; face.Texture.XShift = xshift; face.Texture.YShift = yshift; } else { Assert(parts[16] == "["); Assert(parts[21] == "]"); Assert(parts[22] == "["); Assert(parts[27] == "]"); face.Texture.UAxis = NumericsExtensions.Parse(parts[17], parts[18], parts[19], ns, CultureInfo.InvariantCulture); face.Texture.XShift = float.Parse(parts[20], ns, CultureInfo.InvariantCulture); face.Texture.VAxis = NumericsExtensions.Parse(parts[23], parts[24], parts[25], ns, CultureInfo.InvariantCulture); face.Texture.YShift = float.Parse(parts[26], ns, CultureInfo.InvariantCulture); face.Texture.Rotation = float.Parse(parts[28], ns, CultureInfo.InvariantCulture); face.Texture.XScale = float.Parse(parts[29], ns, CultureInfo.InvariantCulture); face.Texture.YScale = float.Parse(parts[30], ns, CultureInfo.InvariantCulture); } return(face); }
protected virtual void EnsureThatAllOperationsHaveNumber(CustomerOrder order) { var store = StoreService.GetById(order.StoreId); foreach (var operation in order.GetFlatObjectsListWithInterface <Domain.Commerce.Model.IOperation>()) { if (operation.Number == null) { var objectTypeName = operation.OperationType; // take uppercase chars to form operation type, or just take 2 first chars. (CustomerOrder => CO, PaymentIn => PI, Shipment => SH) var opType = string.Concat(objectTypeName.Select(c => char.IsUpper(c) ? c.ToString() : "")); if (opType.Length < 2) { opType = objectTypeName.Substring(0, 2).ToUpper(); } var numberTemplate = opType + "{0:yyMMdd}-{1:D5}"; if (store != null) { numberTemplate = store.Settings.GetSettingValue("Order." + objectTypeName + "NewNumberTemplate", numberTemplate); } operation.Number = UniqueNumberGenerator.GenerateNumber(numberTemplate); } } }
/// <inheritdoc /> public virtual IMapElement Copy(UniqueNumberGenerator numberGenerator) { var inst = (BaseMapObject)GetType().GetConstructor(new[] { typeof(long) }).Invoke(new object[] { numberGenerator.Next("MapObject") }); CopyBase(inst, numberGenerator); return(inst); }
public override IMapObject ToMapObject(UniqueNumberGenerator generator) { var sol = new Solid(generator.Next("MapObject")); Editor.Apply(sol); CreateFaces(sol, Sides, generator); return(sol); }
public IEnumerable <IMapObject> Create(UniqueNumberGenerator generator, Box box, string texture, int roundDecimals) { var wallWidth = (float)_wallWidth.GetValue(); if (wallWidth < 1) { yield break; } var numSides = (int)_numSides.GetValue(); if (numSides < 3) { yield break; } // Very similar to the cylinder, except we have multiple solids this time var width = box.Width; var length = box.Length; var height = box.Height; var majorOut = width / 2; var majorIn = majorOut - wallWidth; var minorOut = length / 2; var minorIn = minorOut - wallWidth; var angle = 2 * Math.PI / numSides; // Calculate the X and Y points for the inner and outer ellipses var outer = new Vector3[numSides]; var inner = new Vector3[numSides]; for (var i = 0; i < numSides; i++) { var a = i * angle; var xval = box.Center.X + majorOut * (float)Math.Cos(a); var yval = box.Center.Y + minorOut * (float)Math.Sin(a); var zval = box.Start.Z; outer[i] = new Vector3(xval, yval, zval).Round(roundDecimals); xval = box.Center.X + majorIn * (float)Math.Cos(a); yval = box.Center.Y + minorIn * (float)Math.Sin(a); inner[i] = new Vector3(xval, yval, zval).Round(roundDecimals); } // Create the solids var colour = Colour.GetRandomBrushColour(); var z = new Vector3(0, 0, height).Round(roundDecimals); for (var i = 0; i < numSides; i++) { var faces = new List <Vector3[]>(); var next = (i + 1) % numSides; faces.Add(new[] { outer[i], outer[i] + z, outer[next] + z, outer[next] }); faces.Add(new[] { inner[next], inner[next] + z, inner[i] + z, inner[i] }); faces.Add(new[] { outer[next], outer[next] + z, inner[next] + z, inner[next] }); faces.Add(new[] { inner[i], inner[i] + z, outer[i] + z, outer[i] }); faces.Add(new[] { inner[next] + z, outer[next] + z, outer[i] + z, inner[i] + z }); faces.Add(new[] { inner[i], outer[i], outer[next], inner[next] }); yield return(MakeSolid(generator, faces, texture, colour)); } }
private Solid ReadSolid(StreamReader rdr, UniqueNumberGenerator generator) { var faces = new List <Face>(); string line; while ((line = CleanLine(rdr.ReadLine())) != null) { if (String.IsNullOrWhiteSpace(line)) { continue; } if (line == "}") { if (!faces.Any()) { return(null); } var poly = new Polyhedron(faces.Select(x => x.Plane)); var ret = new Solid(generator.Next("MapObject")); ret.Data.Add(new ObjectColor(Colour.GetRandomBrushColour())); foreach (var face in faces) { var pg = poly.Polygons.FirstOrDefault(x => x.Plane.Normal.EquivalentTo(face.Plane.Normal)); if (pg == null) { // TODO: Report invalid solids Debug.WriteLine("Invalid solid!"); return(null); } face.Vertices.AddRange(pg.Vertices); } ret.Data.AddRange(faces); ret.DescendantsChanged(); return(ret); } else if (line == "patchDef2") { // Quake 3 has bezier faces // TODO: support bezier faces... while (CleanLine(rdr.ReadLine()) != "}") { // Skip... } } else if (line == "brushDef") { throw new Exception("Maps containing the 'brushDef' structure are not currently supported"); } else { faces.Add(ReadFace(line, generator)); } } return(null); }
public virtual async Task SaveSubscriptionsAsync(Subscription[] subscriptions) { var pkMap = new PrimaryKeyResolvingMap(); var changedEntries = new List <GenericChangedEntry <Subscription> >(); using (var repository = SubscriptionRepositoryFactory()) { var existEntities = await repository.GetSubscriptionsByIdsAsync(subscriptions.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray()); foreach (var subscription in subscriptions) { //Generate numbers for new subscriptions if (string.IsNullOrEmpty(subscription.Number)) { var store = await StoreService.GetByIdAsync(subscription.StoreId); var numberTemplate = store.Settings.GetSettingValue("Subscription.SubscriptionNewNumberTemplate", "SU{0:yyMMdd}-{1:D5}"); subscription.Number = UniqueNumberGenerator.GenerateNumber(numberTemplate); } //Save subscription order prototype with same as subscription Number if (subscription.CustomerOrderPrototype != null) { subscription.CustomerOrderPrototype.Number = subscription.Number; subscription.CustomerOrderPrototype.IsPrototype = true; await CustomerOrderService.SaveChangesAsync(new[] { subscription.CustomerOrderPrototype }); } var originalEntity = existEntities.FirstOrDefault(x => x.Id == subscription.Id); var originalSubscription = originalEntity != null?originalEntity.ToModel(AbstractTypeFactory <Subscription> .TryCreateInstance()) : subscription; var modifiedEntity = AbstractTypeFactory <SubscriptionEntity> .TryCreateInstance().FromModel(subscription, pkMap); if (originalEntity != null) { changedEntries.Add(new GenericChangedEntry <Subscription>(subscription, originalEntity.ToModel(AbstractTypeFactory <Subscription> .TryCreateInstance()), EntryState.Modified)); modifiedEntity.Patch(originalEntity); //force the subscription.ModifiedDate update, because the subscription object may not have any changes in its properties originalEntity.ModifiedDate = DateTime.UtcNow; } else { repository.Add(modifiedEntity); changedEntries.Add(new GenericChangedEntry <Subscription>(subscription, EntryState.Added)); } } //Raise domain events await EventPublisher.Publish(new SubscriptionChangingEvent(changedEntries)); await repository.UnitOfWork.CommitAsync(); pkMap.ResolvePrimaryKeys(); await EventPublisher.Publish(new SubscriptionChangedEvent(changedEntries)); } ClearCacheFor(subscriptions); }
public MapDataCollection Copy(UniqueNumberGenerator numberGenerator) { var copy = new MapDataCollection(); foreach (var d in Data) { copy.Add((IMapData)d.Copy(numberGenerator)); } return(copy); }
public IMapElement Copy(UniqueNumberGenerator numberGenerator) { return(new Visgroup { ID = numberGenerator.Next("Visgroup"), Name = Name, Visible = Visible, Colour = Colour, }); }
public Face ToFace(UniqueNumberGenerator idGenerator) { var f = new Face(idGenerator.Next("Face")) { Texture = Texture.Clone() }; f.Vertices.AddRange(Vertices.Select(x => x.Position)); return(f); }
protected void CopyBase(BaseMapObject copy, UniqueNumberGenerator numberGenerator) { copy.IsSelected = IsSelected; copy.Data = Data.Copy(numberGenerator); foreach (var child in Hierarchy) { var c = (IMapObject)child.Copy(numberGenerator); c.Hierarchy.Parent = copy; } copy.DescendantsChanged(); }
public IEnumerable <IMapObject> Create(UniqueNumberGenerator generator, Box box, string texture, int roundDecimals) { var numSides = (int)_numSides.GetValue(); if (numSides < 3) { yield break; } // This is all very similar to the cylinder brush. var width = box.Width; var length = box.Length; var major = width / 2; var minor = length / 2; var angle = 2 * Math.PI / numSides; var points = new Vector3[numSides]; for (var i = 0; i < numSides; i++) { var a = i * angle; var xval = box.Center.X + major * (float)Math.Cos(a); var yval = box.Center.Y + minor * (float)Math.Sin(a); var zval = box.Start.Z; points[i] = new Vector3(xval, yval, zval).Round(roundDecimals); } var faces = new List <Vector3[]>(); var point = new Vector3(box.Center.X, box.Center.Y, box.End.Z).Round(roundDecimals); for (var i = 0; i < numSides; i++) { var next = (i + 1) % numSides; faces.Add(new[] { points[i], point, points[next] }); } faces.Add(points.ToArray()); var solid = new Solid(generator.Next("MapObject")); solid.Data.Add(new ObjectColor(Colour.GetRandomBrushColour())); foreach (var arr in faces) { var face = new Face(generator.Next("Face")) { Plane = new Plane(arr[0], arr[1], arr[2]), Texture = { Name = texture } }; face.Vertices.AddRange(arr); solid.Data.Add(face); } solid.DescendantsChanged(); yield return(solid); }
public override IMapObject ToMapObject(UniqueNumberGenerator generator) { var ent = new Entity(generator.Next("MapObject")); ent.Data.Add(EntityData); if (Origin != null) { ent.Data.Add(new Origin(Origin.Value)); } Editor.Apply(ent); return(ent); }
private void RaiseCaseDeleteRequest() { var confirmation = new ConditionalConfirmation { Content = string.Format("Are you sure you want to delete Case '{0}'?".Localize(), InnerItem.Number), Title = "Delete confirmation".Localize(null, LocalizationScope.DefaultCategory) }; CommonConfirmRequest.Raise(confirmation, (x) => { if (x.Confirmed) { /// TODO: implement this InnerItem.Number = UniqueNumberGenerator.GetUniqueNumber(); } }); }
private List <Entity> ReadAllEntities(StreamReader rdr, UniqueNumberGenerator generator, BspFileLoadResult result) { var list = new List <Entity>(); string line; while ((line = CleanLine(rdr.ReadLine())) != null) { if (String.IsNullOrWhiteSpace(line)) { continue; } if (line == "{") { list.Add(ReadEntity(rdr, generator, result)); } } return(list); }
private Solid MakeSolid(UniqueNumberGenerator generator, IEnumerable <Vector3[]> faces, string texture, Color col) { var solid = new Solid(generator.Next("MapObject")); solid.Data.Add(new ObjectColor(col)); foreach (var arr in faces) { var face = new Face(generator.Next("Face")) { Plane = new Plane(arr[0], arr[1], arr[2]), Texture = { Name = texture } }; face.Vertices.AddRange(arr); solid.Data.Add(face); } solid.DescendantsChanged(); return(solid); }
public IEnumerable <IMapObject> Create(UniqueNumberGenerator idGenerator, Box box, string texture, int roundDecimals) { var solid = new Solid(idGenerator.Next("MapObject")); solid.Data.Add(new ObjectColor(Colour.GetRandomBrushColour())); foreach (var arr in box.GetBoxFaces()) { var face = new Face(idGenerator.Next("Face")) { Plane = new Plane(arr[0], arr[1], arr[2]), Texture = { Name = texture } }; face.Vertices.AddRange(arr.Select(x => x.Round(roundDecimals))); solid.Data.Add(face); } solid.DescendantsChanged(); yield return(solid); }
private void CreateFaces(Solid solid, List <VmfSide> sides, UniqueNumberGenerator generator) { // If all the sides don't have enough vertices, calculate them if (!sides.All(x => x.Vertices.Count >= 3)) { // We need to create the solid from intersecting planes var poly = new Polyhedron(sides.Select(x => x.Plane)); foreach (var side in sides) { side.Vertices.Clear(); var pg = poly.Polygons.FirstOrDefault(x => x.Plane.Normal.EquivalentTo(side.Plane.Normal)); if (pg == null) { continue; } side.Vertices.AddRange(pg.Vertices.Select(x => x.ToStandardVector3())); } } foreach (var emptySide in sides.Where(x => !x.Vertices.Any())) { Console.WriteLine(emptySide.ID); } // We know the vertices, now create the faces foreach (var side in sides) { var face = new Face(generator.Next("Face")) { Plane = side.Plane.ToStandardPlane(), Texture = side.Texture }; face.Vertices.AddRange(side.Vertices); if (face.Vertices.Any()) { solid.Data.Add(face); } } solid.DescendantsChanged(); }
protected override void EnsureThatAllOperationsHaveNumber(CustomerOrder order) { var store = StoreService.GetById(order.StoreId); foreach (var operation in order.GetFlatObjectsListWithInterface <Domain.Commerce.Model.IOperation>()) { if (operation.Number == null) { if (operation.OperationType == "CustomerOrder") { CustomerOrderSearchCriteria criteria = new CustomerOrderSearchCriteria() { Sort = "createdDate:desc", Take = 1, ResponseGroup = "default" }; var lastOrder = _orderSearchService.SearchCustomerOrders(criteria).Results.First(); if (lastOrder != null) { operation.Number = (Convert.ToInt32(lastOrder.Number) + 1).ToString(); } } else { var objectTypeName = operation.OperationType; // take uppercase chars to form operation type, or just take 2 first chars. (CustomerOrder => CO, PaymentIn => PI, Shipment => SH) var opType = string.Concat(objectTypeName.Select(c => char.IsUpper(c) ? c.ToString() : "")); if (opType.Length < 2) { opType = objectTypeName.Substring(0, 2).ToUpper(); } var numberTemplate = opType + "{0:yyMMdd}-{1:D5}"; if (store != null) { numberTemplate = store.Settings.GetSettingValue("Order." + objectTypeName + "NewNumberTemplate", numberTemplate); } operation.Number = UniqueNumberGenerator.GenerateNumber(numberTemplate); } } } }
private Entity ReadEntity(StreamReader rdr, UniqueNumberGenerator generator, BspFileLoadResult result) { var ent = new Entity(generator.Next("Face")) { Data = { new EntityData(), new ObjectColor(Colour.GetRandomBrushColour()) } }; string line; while ((line = CleanLine(rdr.ReadLine())) != null) { if (String.IsNullOrWhiteSpace(line)) { continue; } if (line[0] == '"') { ReadProperty(ent, line); } else if (line[0] == '{') { var s = ReadSolid(rdr, generator, result); if (s != null) { s.Hierarchy.Parent = ent; } } else if (line[0] == '}') { break; } } ent.DescendantsChanged(); return(ent); }
private IMapObject GetBrush(MapDocument document, Box bounds, UniqueNumberGenerator idg) { var brush = _activeBrush; if (brush == null) { return(null); } // Don't round if the box is rather small var rounding = RoundVertices ? 0 : 2; if (bounds.SmallestDimension < 10) { rounding = 2; } var ti = document.Map.Data.GetOne <ActiveTexture>()?.Name ?? "aaatrigger"; var created = brush.Create(idg, bounds, ti, rounding).ToList(); // Align all textures to the face and set the texture scale foreach (var f in created.SelectMany(x => x.Data.OfType <Face>())) { f.Texture.XScale = f.Texture.YScale = (float)document.Environment.DefaultTextureScale; f.Texture.AlignToNormal(f.Plane.Normal); } // If there's more than one object in the result, group them up if (created.Count > 1) { var g = new Group(idg.Next("MapObject")); created.ForEach(x => x.Hierarchy.Parent = g); g.DescendantsChanged(); return(g); } return(created.FirstOrDefault()); }
public IMapElement Copy(UniqueNumberGenerator numberGenerator) { return(Clone()); }
public override IMapObject ToMapObject(UniqueNumberGenerator generator) { throw new NotSupportedException(); }
public abstract IMapObject ToMapObject(UniqueNumberGenerator generator);