/// <summary> /// Evaluates the expression for the given shape. /// </summary> /// <param name="shapes"></param> /// <returns>The result of evaluating the expression.</returns> public override bool Evaluate(ShapeSet shapes) { if (shapes == null) { throw new ArgumentNullException(nameof(shapes)); } switch (ExpressionType) { case ExpressionType.And: return(Expressions.All(e => e.Evaluate(shapes))); case ExpressionType.Or: return(Expressions.Any(e => e.Evaluate(shapes))); case ExpressionType.BoolEqual: return(Expressions.AreEqual()); case ExpressionType.Xor: Debug.Assert(Expressions.Count == 2); return(Expressions[0].Evaluate(shapes) ^ Expressions[1].Evaluate(shapes)); case ExpressionType.Not: Debug.Assert(Expressions.Count == 1); return(!Expressions[0].Evaluate(shapes)); default: Debug.Assert(false); throw new ArgumentOutOfRangeException(); } }
// private func PutAllShapesIntoGrid( // shapeSetBuilder: IShapeSetBuilder, // shapeSet: ShapeSet, // occupiedGridSquares: Grid) private void PutAllShapesIntoGrid( IShapeSetBuilder shapeSetBuilder, ShapeSet shapeSet, Grid occupiedGridSquares) { shapeSetBuilder.OccupyBorderSquares(occupiedGridSquares: occupiedGridSquares); shapeSet.OccupyGridSquares(occupiedGridSquares: occupiedGridSquares); }
public ElecComp() { shapeSet = new ShapeSet(); XYPoint = new IntPoint(0, 0); size = new IntPoint(MainWindow.GridLen, MainWindow.GridLen); RelativeInterface = new List <IntPoint>(); AddShapes(); }
/// <summary> /// Find the out size /// Cover the group shapes /// </summary> /// <param name="group"></param> private void FindGroupRegion(ShapeSet group) { int minX = int.MaxValue, minY = int.MaxValue, maxX = int.MinValue, maxY = int.MinValue; for (int i = 0; i < group.Count; i++) { Shape shape = group[i]; if (shape is Bezier curve) { FindBezierRegion(curve); } else if (shape is Polygon polygon) { FindPolygonRegion(polygon); } if (shape.startPoint.X < minX) { minX = shape.startPoint.X; } if (shape.endPoint.X < minX) { minX = shape.endPoint.X; } if (shape.startPoint.Y < minY) { minY = shape.startPoint.Y; } if (shape.endPoint.Y < minY) { minY = shape.endPoint.Y; } if (shape.startPoint.X > maxX) { maxX = shape.startPoint.X; } if (shape.endPoint.X > maxX) { maxX = shape.endPoint.X; } if (shape.startPoint.Y > maxY) { maxY = shape.startPoint.Y; } if (shape.endPoint.Y > maxY) { maxY = shape.endPoint.Y; } } group.startPoint = new Point(minX, minY); group.endPoint = new Point(maxX, maxY); }
protected void Init() { Comp = -1; shapeSet = new ShapeSet(); XYPoint = new IntPoint(0, 0); size = new IntPoint(Core.GridLen, Core.GridLen);//格点间距在主函数中定义的 RelativeInterface = new List <IntPoint>(); State = State_Move; IsWire = false; AddShapes(); }
protected void Init() { Comp = -1; shapeSet = new ShapeSet(); XYPoint = new IntPoint(0, 0); size = new IntPoint(MainWindow.GridLen, MainWindow.GridLen); RelativeInterface = new List <IntPoint>(); State = State_Move; IsWire = false; AddShapes(); }
/// <summary> /// Initializes a new instance of the <see cref="ShapeController" /> class. /// </summary> /// <param name="template">The template.</param> /// <param name="view">The view.</param> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.InvalidOperationException"></exception> public ShapeController([NotNull] Template template, [NotNull] IView view) : base(view) { if (template == null) throw new ArgumentNullException(nameof(template)); _template = template; Shapes = template.CreateShapes(); IResourceManager resourceManager = DependencyManger.GetResourceManager(); if (resourceManager == null) throw new InvalidOperationException(); _resourceManager = resourceManager; }
protected void OnInfoAreaShape(Event guiEvent, Rect guiRect) { Rect toolbarRect = new Rect(toolbarPadding, toolbarPadding, toolbarWidth * shapeIcons.Length, toolbarHeight); toolbarRect.position += guiRect.position; int activeButton = (int)activeShape; int newButton = GUI.Toolbar(toolbarRect, activeButton, shapeIcons); if (newButton != activeButton) { switch (newButton) { case ShapePoint: activeShape = ShapeSet.Point; break; case ShapeCircle: activeShape = ShapeSet.Circle; break; case ShapeTriangle: activeShape = ShapeSet.Triangle; break; case ShapeRectangle: activeShape = ShapeSet.Rectangle; break; case ShapePentagon: activeShape = ShapeSet.Pentagon; break; case ShapeHexagon: activeShape = ShapeSet.Hexagon; break; case ShapePolygon: activeShape = ShapeSet.Polygon; break; } SetFocusedShape(null); } Rect colorsRect = new Rect(toolbarRect.xMax, guiRect.position.y, guiRect.xMax - toolbarRect.xMax, guiRect.height); OnShapeColorArea(guiEvent, colorsRect); }
/// <summary> /// Initializes a new instance of the <see cref="ShapeController" /> class. /// </summary> /// <param name="template">The template.</param> /// <param name="view">The view.</param> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.InvalidOperationException"></exception> public ShapeController([NotNull] Template template, [NotNull] IView view) : base(view) { if (template == null) { throw new ArgumentNullException(nameof(template)); } _template = template; Shapes = template.CreateShapes(); IResourceManager resourceManager = DependencyManger.GetResourceManager(); if (resourceManager == null) { throw new InvalidOperationException(); } _resourceManager = resourceManager; }
protected void OnInfoAreaShape(Event guiEvent, Rect guiRect) { Rect toolbarRect = new Rect(toolbarPadding, toolbarPadding, toolbarWidth * shapeIcons.Length, toolbarHeight); toolbarRect.position += guiRect.position; int activeButton = (int)activeShape; int newButton = GUI.Toolbar(toolbarRect, activeButton, shapeIcons); if (newButton != activeButton) { activeShape = (ShapeSet)newButton; SetFocusedShape(null); } Rect colorsRect = new Rect(toolbarRect.xMax, guiRect.position.y, guiRect.xMax - toolbarRect.xMax, guiRect.height); OnShapeColorArea(guiEvent, colorsRect); }
private static ShapeSet GetShapeSet(Imd imd) { var shapes = new ShapeSet { dict = new Dictionary <ShapeSetData>(), shape = new Shape[imd.Body.PolygonArray.Polygons.Count] }; int idx = 0; foreach (var polygon in imd.Body.PolygonArray.Polygons) { shapes.dict.Add(polygon.Name, new ShapeSetData()); Shape.NNS_G3D_SHPFLAG flag = 0; if (polygon.TexFlag == "on") { flag = Shape.NNS_G3D_SHPFLAG.NNS_G3D_SHPFLAG_USE_TEXCOORD; } if (polygon.ClrFlag == "on") { flag |= Shape.NNS_G3D_SHPFLAG.NNS_G3D_SHPFLAG_USE_COLOR; } if (polygon.NrmFlag == "on") { flag |= Shape.NNS_G3D_SHPFLAG.NNS_G3D_SHPFLAG_USE_NORMAL; } //TODO shapes.shape[idx++] = new Shape { flag = flag, DL = G3dDisplayList.Encode(polygon.MatrixPrimitives[0].PrimitiveArray.GetDisplayList()) }; } return(shapes); }
//Group shapes private void btnGroup_Click(object sender, EventArgs e) { UncheckButton(); if (shapes.Count(shape => shape.isSelect) > 1) { ShapeSet group = new ShapeSet(); for (int i = 0; i < shapes.Count; i++) { if (shapes[i].isSelect) { group.Add(shapes[i]); shapes.RemoveAt(i); i--; } } FindGroupRegion(group); shapes.Add(group); group.isSelect = true; pnlPaint.Invalidate(); } }
private void A_PatchGame(object sender, EventArgs e) { if (Process.GetProcessesByName("ScrapMechanic.exe").Length != 0) { MessageBox.Show("You cannot install mods while the game is running. Please close it first.", "Please close Scrap Mechanic", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult box = MessageBox.Show("Have you verified the game cache?\n\nThis is necessary for the patching to work. Your game might stop working if you skipped the previous step.", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (box == DialogResult.Yes) { // Check for dependency issues foreach (ModInfo i in this.Mods) { foreach (string dependency in i.Dependencies.Where((d) => !ModIDs.Contains(d))) { try { // Show error string[] dependencyInfo = ModInfo.ParseModID(dependency); MessageBox.Show("Error: Mod " + i.ModName + " requires you have the mod " + dependencyInfo[1] + " by " + dependencyInfo[0], "Mod dependency error"); return; } catch { } } } Dictionary <ModInfo, ZipFile> modZipFiles = new Dictionary <ModInfo, ZipFile>(); try { pbPatch.Value = 5; // Load reader GameReader reader = new GameReader(ScrapMechanicFolder); // 1. Load physics materials // 2. Load blocks // 3. Load rotation sets // 4. Load shapesets // 5. Load inventory item descriptions // 6. Load IconMap images Dictionary <string, Material> materials = reader.ReadPhysicsMaterials(); pbPatch.Value = 6; Dictionary <Guid, Block> blocks = reader.ReadBlocks(materials); pbPatch.Value = 7; Dictionary <string, RotationSet> rotationSets = reader.ReadRotationSets(); pbPatch.Value = 8; Dictionary <string, ShapeSet> shapeSets = reader.ReadShapesets(rotationSets, materials); pbPatch.Value = 9; Dictionary <Guid, InventoryItemDescription> invItemDescs = reader.ReadInventoryItemDescriptions(); pbPatch.Value = 10; Dictionary <Guid, Image> icons = reader.ReadIconMap(); pbPatch.Value = 11; Dictionary <string, byte[]> resources = new Dictionary <string, byte[]>(); List <string> addedMaterials = new List <string>(); List <Guid> addedBlocks = new List <Guid>(); List <string> addedRotationSets = new List <string>(); List <Guid> addedInvItemDescs = new List <Guid>(); List <Guid> addedIcons = new List <Guid>(); // 7. Load for all mods mods those things in same order string physicsMaterialsPath = "Data/Objects/Database/physicsmaterials.json"; string blocksPath = "Data/Objects/Database/basicmaterials.json"; string shapeSetsListPath = "Data/Objects/Database/shapesets.json"; string rotationSetsPath = "Data/Objects/Database/rotationsets.json"; string inventoryItemDescriptionsPath = "Data/Gui/InventoryItemDescriptions.json"; foreach (ModInfo i in this.Mods) { modZipFiles[i] = ZipFile.Read(i.FileName); } pbPatch.Value = 15; // Read physics materials foreach (ZipFile zip in modZipFiles.Values) { // If the mod offers new Physics Materials if (zip.ContainsEntry(physicsMaterialsPath)) { // Read and parse the physics materials Dictionary <string, Material> thisModMaterials = Material.ReadFromJson(Zip.ReadText(zip[physicsMaterialsPath])); // Loop over each material foreach (KeyValuePair <string, Material> kvp in thisModMaterials) { // If there is already a material with this name if (!addedMaterials.Contains(kvp.Key)) { // Add the material to the material dictionary, and make sure it won't be overwritten materials[kvp.Key] = kvp.Value; addedMaterials.Add(kvp.Key); } } } } pbPatch.Value = 20; // Read rotation sets foreach (ZipFile zip in modZipFiles.Values) { // If the mod offers new rotation sets if (zip.ContainsEntry(rotationSetsPath)) { // Read and parse the rotation sets Dictionary <string, RotationSet> thisModRotationSets = RotationSet.ReadFromJson(Zip.ReadText(zip[rotationSetsPath])); // Loop over each rotation set foreach (KeyValuePair <string, RotationSet> kvp in thisModRotationSets) { // If there is already a rotation set with this name if (!addedRotationSets.Contains(kvp.Key)) { // Add the rotation set to the rotation set dictionary, and make sure it won't be overwritten rotationSets[kvp.Key] = kvp.Value; addedRotationSets.Add(kvp.Key); } } } } pbPatch.Value = 25; // Read blocks foreach (ZipFile zip in modZipFiles.Values) { // If the mod offers new rotation sets if (zip.ContainsEntry(blocksPath)) { // Read and parse the blocks Dictionary <Guid, Block> thisModBlocks = Block.ReadFromJson(Zip.ReadText(zip[blocksPath]), materials); // Loop over each block foreach (KeyValuePair <Guid, Block> kvp in thisModBlocks) { // If there is already a block with this name if (!addedBlocks.Contains(kvp.Key)) { // Add the block to the rotation set dictionary, and make sure it won't be overwritten blocks[kvp.Key] = kvp.Value; addedBlocks.Add(kvp.Key); } } } } pbPatch.Value = 30; // Load ShapeSets foreach (ZipFile zipFile in modZipFiles.Values) { if (zipFile.ContainsEntry(shapeSetsListPath)) { // Load the shape set list json to a dictionary string sslJson = Zip.ReadText(zipFile[shapeSetsListPath]); IDictionary <string, object> sslDict = JsonConvert.DeserializeObject <ExpandoObject>(sslJson); // See if it has a shape set list if (sslDict.ContainsKey("shapeSetList")) { // Loop over the shape set list foreach (object lObj in (List <object>)sslDict["shapeSetList"]) { string shapeSetName = lObj.ToString(); if (!shapeSets.ContainsKey(shapeSetName)) { if (zipFile.ContainsEntry("Data/Objects/Database/ShapeSets/" + shapeSetName)) { string shapeSetJson = Zip.ReadText(zipFile["Data/Objects/Database/ShapeSets/" + shapeSetName]); shapeSets[shapeSetName] = new ShapeSet(shapeSetName, shapeSetJson, rotationSets, materials); } } else { throw new Exception("There is already a ShapeSet named " + shapeSetName + ".\n\nIf you are the mod maker: To prevent name collisions, prefix your shapesets with your username, and give every ShapeSet in your mods a different name."); } } } } } pbPatch.Value = 35; // Load inventory items foreach (ZipFile zip in modZipFiles.Values) { // If the mod has an Inventory Item Descriptions file if (zip.ContainsEntry(inventoryItemDescriptionsPath)) { // Load the description items Dictionary <Guid, InventoryItemDescription> descs = InventoryItemDescription.ReadFromJson(Zip.ReadText(zip[inventoryItemDescriptionsPath])); foreach (KeyValuePair <Guid, InventoryItemDescription> kvp in descs) { // If no (custom) description for this item exists yet; add one and make sure it won't be overwritten if (!addedInvItemDescs.Contains(kvp.Key)) { addedInvItemDescs.Add(kvp.Key); invItemDescs[kvp.Key] = kvp.Value; } } } } pbPatch.Value = 40; // Load inventory icons foreach (ZipFile zip in modZipFiles.Values) { // If this mod both has a icon information file ... if (zip.ContainsEntry("Data/Gui/IconMap.json")) { // ... and an actual icon map if (zip.ContainsEntry("Data/Gui/IconMap.png")) { // Load all the points into the iconPoints dictionary IDictionary <string, object> imDict = JsonConvert.DeserializeObject <ExpandoObject>(Zip.ReadText(zip["Data/Gui/IconMap.json"])); Dictionary <Guid, Point> iconPoints = new Dictionary <Guid, Point>(); foreach (KeyValuePair <string, object> kvp in imDict) { Guid itemUuid; if (Guid.TryParse(kvp.Key.ToString(), out itemUuid)) { IDictionary <string, object> objDict = kvp.Value as IDictionary <string, object>; if (objDict.ContainsKey("x") && objDict.ContainsKey("y")) { int x, y; if (int.TryParse(objDict["x"].ToString(), out x)) { if (int.TryParse(objDict["y"].ToString(), out y)) { iconPoints.Add(itemUuid, new Point(x, y)); } } } } } // Open the icon map picture using (CrcCalculatorStream stream = zip["Data/Gui/IconMap.png"].OpenReader()) { try { using (Image iconMapImage = Image.FromStream(stream)) { using (Bitmap iconMapImg = new Bitmap(iconMapImage)) { // And for every item without a (custom) icon the icon image; and make sure it won't be overwritten by a lower mod foreach (KeyValuePair <Guid, Point> kvp in iconPoints.Where((p) => !addedIcons.Contains(p.Key))) { int x = kvp.Value.X, y = kvp.Value.Y; Rectangle destination = new Rectangle(x, y, Math.Min(80, iconMapImg.Width - x), Math.Min(80, iconMapImg.Height - y)); Bitmap newIcon = iconMapImg.Clone(destination, iconMapImg.PixelFormat); icons.Add(kvp.Key, newIcon); addedIcons.Add(kvp.Key); } } } } catch (Exception ex) { throw new Exception(ex.Message + " Image data invalid."); } } } else { throw new Exception("Mod provides IconMap.json but no IconMap.png"); } } } pbPatch.Value = 45; // Load resources foreach (KeyValuePair <ModInfo, ZipFile> pair in modZipFiles) { foreach (ZipEntry entry in pair.Value.Entries) { // For every entry that is not a shapeset if (entry.FileName.StartsWith("Data/") && !entry.FileName.Contains("/ShapeSets/") && !entry.FileName.EndsWith("/")) { switch (entry.FileName) { // and also is not one of the files already read by case "Data/Objects/Database/physicsmaterials.json": case "Data/Objects/Database/basicmaterials.json": case "Data/Objects/Database/shapesets.json": case "Data/Objects/Database/rotationsets.json": case "Data/Gui/InventoryItemDescriptions.json": case "Data/Gui/IconMap.json": break; default: // Find file name for in Scrap Mechanic/Data string dataFileName = entry.FileName.Substring(5); // Read bytes from resource file if no higher mod adds this resource as well if (!resources.ContainsKey(dataFileName)) { using (BinaryReader r = new BinaryReader(entry.OpenReader())) resources[dataFileName] = r.ReadBytes((int)entry.UncompressedSize); } break; } } } } pbPatch.Value = 50; // Write everything to the game directory GameWriter writer = new GameWriter(Properties.Settings.Default.ScrapMechanicFolder); writer.WritePhysicsMaterials(materials); pbPatch.Value = 60; writer.WriteRotationSets(rotationSets); pbPatch.Value = 70; writer.WriteInventoryItemDescriptions(invItemDescs); pbPatch.Value = 80; writer.WriteBlocks(blocks); pbPatch.Value = 85; writer.WriteResources(resources); pbPatch.Value = 90; writer.WriteIcons(icons); pbPatch.Value = 95; writer.WriteShapesets(shapeSets); pbPatch.Value = 100; DialogResult r2 = MessageBox.Show("All " + this.Mods.Count + " mods are now installed. Do you want to start Scrap Mechanic to test it?", "Mods installed", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (r2 == System.Windows.Forms.DialogResult.Yes) { Process.Start("steam://rungameid/387990"); } } catch (Exception ex) { MessageBox.Show("An exception occurred while loading the mods.\n\n" + ex.Message + "\n\n" + ex.Source + "\n\n" + ex.StackTrace, "An error occurred", MessageBoxButtons.OK, MessageBoxIcon.Error); Console.WriteLine(ex.Message + " on " + ex.Source); } finally { foreach (ZipFile f in modZipFiles.Values) { f.Dispose(); } btnPatchGame.Enabled = false; } } }
/// <summary> /// Evaluates the expression for the given set of shapes. /// </summary> /// <param name="shapes">The shapes to evaluate the expression for.</param> /// <returns>The result of evaluating the expression.</returns> public override float Evaluate(ShapeSet shapes) { if (shapes == null) { throw new ArgumentNullException(nameof(shapes)); } bool first = true; switch (ExpressionType) { case ExpressionType.Add: float sum = 0; foreach (float val in Expressions.Select(e => e.Evaluate(shapes))) { sum += val; } return(sum); case ExpressionType.Subtract: if (Expressions.Count == 1) { return(-Expressions[0].Evaluate(shapes)); } float sub = 0; foreach (float val in Expressions.Select(e => e.Evaluate(shapes))) { if (first) { sub = val; } else { sub -= val; } first = false; } return(sub); case ExpressionType.Multiply: float mul = 1f; foreach (float val in Expressions.Select(e => e.Evaluate(shapes))) { if (first) { mul = val; } else { mul *= val; } first = false; } return(mul); case ExpressionType.Divide: Debug.Assert(Expressions.Count == 2); return(Expressions[0].Evaluate(shapes) / Expressions[1].Evaluate(shapes)); default: Debug.Assert(false); throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Evaluates the expression for the given set of shapes. /// </summary> /// <param name="shapes">The shapes to evaluate the expression for.</param> /// <returns>The result of evaluating the expression.</returns> public float Evaluate(ShapeSet shapes) => shapes.GetVertex(VertexName).Angle;
/// <summary> /// Evaluates the expression for the given set of shapes. /// </summary> /// <param name="shapes">The shapes to evaluate the expression for.</param> /// <returns>The result of evaluating the expression.</returns> public override bool Evaluate(ShapeSet shapes) { if (shapes == null) { throw new ArgumentNullException(nameof(shapes)); } const float tolerance = 0.0001f; float last = 0; bool first = true; switch (ExpressionType) { case ExpressionType.Equal: float min = 0, max = 0; foreach (float val in Expressions.Select(e => e.Evaluate(shapes))) { if (first) { min = max = val; } else { if (val < min) { min = val; } else if (val > max) { max = val; } if (max - min > tolerance) { return(false); } } first = false; } return(true); case ExpressionType.NotEqual: HashSet <float> set = new HashSet <float>(); foreach (float val in Expressions.Select(e => e.Evaluate(shapes))) { if (!set.Add(val)) { return(false); } } return(true); case ExpressionType.GreaterThan: foreach (float val in Expressions.Select(e => e.Evaluate(shapes))) { if (!first) { if (last <= val || Math.Abs(last - val) > tolerance) { return(false); } } last = val; first = false; } return(true); case ExpressionType.LessThan: foreach (float val in Expressions.Select(e => e.Evaluate(shapes))) { if (!first) { if (last >= val || Math.Abs(last - val) > tolerance) { return(false); } } last = val; first = false; } return(true); case ExpressionType.GreaterThanOrEqual: foreach (float val in Expressions.Select(e => e.Evaluate(shapes))) { if (!first && last < val) { return(false); } last = val; first = false; } return(true); case ExpressionType.LessThanOrEqual: foreach (float val in Expressions.Select(e => e.Evaluate(shapes))) { if (!first && last > val) { return(false); } last = val; first = false; } return(true); default: Debug.Assert(false); throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Evaluates the expression for the given shape. /// </summary> /// <param name="shapes"></param> /// <returns>The result of evaluating the expression.</returns> public float Evaluate(ShapeSet shapes) => Value;
public Model(EndianBinaryReader er) { long basepos = er.BaseStream.Position; size = er.ReadUInt32(); ofsSbc = er.ReadUInt32(); ofsMat = er.ReadUInt32(); ofsShp = er.ReadUInt32(); ofsEvpMtx = er.ReadUInt32(); info = new ModelInfo(er); nodes = new NodeSet(er); long curpos = er.BaseStream.Position; er.BaseStream.Position = ofsSbc + basepos; sbc = er.ReadBytes((int)(ofsMat - ofsSbc)); er.BaseStream.Position = curpos; er.BaseStream.Position = ofsMat + basepos; materials = new MaterialSet(er); er.BaseStream.Position = ofsShp + basepos; shapes = new ShapeSet(er); if (ofsEvpMtx != size && ofsEvpMtx != 0) { er.BaseStream.Position = ofsEvpMtx + basepos; evpMatrices = new EvpMatrices(er, nodes.dict.numEntry); } /*long modelset = er.GetMarker("ModelSet"); er.ClearMarkers(); curpos = er.BaseStream.Position; er.BaseStream.Position = modelset; er.SetMarkerOnCurrentOffset("ModelSet"); er.BaseStream.Position = curpos;*/ }
/// <summary> /// Evaluates the expression for the given set of shapes. /// </summary> /// <param name="shapes">The shapes to evaluate the expression for.</param> /// <returns>The result of evaluating the expression.</returns> public abstract TResult Evaluate(ShapeSet shapes);
/// <summary> /// Evaluates the expression for the given set of shapes. /// </summary> /// <param name="shapes">The shapes to evaluate the expression for.</param> /// <returns>The result of evaluating the expression.</returns> public float Evaluate(ShapeSet shapes) => shapes.GetEdge(EdgeName).Length;
// init (shapeSet: ShapeSet, occupiedGridSquares: Grid) public ShapeController(ShapeSet shapeSet, Grid occupiedGridSquares) { _occupiedGridSquares = occupiedGridSquares; _shapeSet = shapeSet; _lastGoodLocation = SquareFillPoint(x: 0, y: 0); }
private void InitializeCollections() { _shapes = new ShapeSet <Package>(this); _products = new ProductSet <Package>(this); }
public void WriteShapesets(Dictionary <string, ShapeSet> shapeSets) { Dictionary <Guid, ShapeSet> definedParts = new Dictionary <Guid, ShapeSet>(); // Check for overwrites and overwrite violations foreach (ShapeSet s in shapeSets.Values) { foreach (Part p in s.Parts.Values) { if (definedParts.ContainsKey(p.ItemUuid)) { ShapeSet overwrites = definedParts[p.ItemUuid]; if (s.Overwrites.Contains(overwrites.Name)) { overwrites.Parts[p.ItemUuid] = p; s.Parts.Remove(p.ItemUuid); } else { throw new Exception("Part from ShapeSet " + s.Name + " overwrites part from " + overwrites.Name + " without specifying an 'overwrites' declaration for it."); } } } } using (StreamWriter wr = new StreamWriter(Path.Combine(this.GameDir, "Data", "Objects", "Database", "shapesets.json"))) { using (JsonWriter writer = new JsonTextWriter(wr)) { writer.Formatting = Formatting.Indented; writer.WriteStartObject(); writer.WritePropertyName("shapeSetList"); writer.WriteStartArray(); foreach (ShapeSet s in shapeSets.Values) { writer.WriteValue(s.Name); } writer.WriteEndArray(); writer.WriteEndObject(); } } foreach (ShapeSet s in shapeSets.Values) { using (StreamWriter wr = new StreamWriter(Path.Combine(this.GameDir, "Data", "Objects", "Database", "ShapeSets", s.Name))) { using (JsonWriter writer = new JsonTextWriter(wr)) { writer.Formatting = Formatting.Indented; writer.WriteStartObject(); writer.WritePropertyName("itemlist"); writer.WriteStartArray(); foreach (Part p in s.Parts.Values) { p.WriteToJson(writer); } writer.WriteEndArray(); writer.WriteEndObject(); } } } }
private void InitCollections() { _units = new UnitSet(this); _shapes = new ShapeSet <UnitGroup>(this); }
/// <summary> /// Evaluates the expression for the given set of shapes. /// </summary> /// <param name="shapes">The shapes to evaluate the expression for.</param> /// <returns>The result of evaluating the expression.</returns> public T Evaluate(ShapeSet shapes) => _eval(shapes);