/// <summary> /// Creates view element /// </summary> /// <param name="widget">Widget to show</param> /// <param name="style">Style of widget</param> /// <returns>View element</returns> protected T CreateElement(ElementManager widget, Y style) { T element = _elementFactory.CreateElement(widget, style); ElementIndex.Add(widget.Identifier, element); return(element); }
internal static Result <BaseSegment> TrySetSegment(BaseSegment?segment, ElementIndex elementIndex, string newValue) { if (segment == null) { return(ErrorReturn <BaseSegment>($"failed to find field({elementIndex.FieldIndex} on message with {elementIndex}, as the segment was not found")); } if (elementIndex.FieldIndex?.HasValue == true) { List <BaseField> fields = segment.FieldList.ToList(); if (!TryGetField(fields, elementIndex.FieldIndex, out int foundIndex).DecomposeResult(out BaseField field, out string?error)) { return(ErrorReturn <BaseSegment>(error ?? "unknown error getting field")); } if (!TrySetField(field, elementIndex, newValue).DecomposeResult(out BaseField result, out error)) { return(ErrorReturn <BaseSegment>(error ?? "unknown error setting field")); } fields[foundIndex - 1] = result; return(new Result <BaseSegment>(CreateSegment(segment, fields))); } else { return(new Result <BaseSegment>(CreateSegment(segment, newValue))); } }
internal static Result <MessageElement> TryGetField(BaseSegment segment, ElementIndex elementIndex) { if (!TryGetField(segment.FieldList, elementIndex.FieldIndex, out _).DecomposeResult(out BaseField field, out string?error)) { ErrorReturn(error ?? "unknown error trying to get field"); } if (elementIndex.SubFieldIndex?.HasValue == true) { if (!(field is RepetitionField rf)) { return(ErrorReturn <MessageElement>($"failed to find RepititionField({elementIndex.SubFieldIndex}) on message with {elementIndex}, as the field was not a repetition field")); } if (!TryGetField(rf.Repetitions, elementIndex.SubFieldIndex, out _).DecomposeResult(out field, out error)) { ErrorReturn(error ?? "unknown error trying to get subfield"); } if (field == null) { return(ErrorReturn <MessageElement>($"failed to find RepititionField({elementIndex.SubFieldIndex}) on message with {elementIndex}")); } } if (elementIndex.ComponentIndex?.HasValue == true) { if (field == null) { return(ErrorReturn <MessageElement>($"failed to find component({elementIndex.ComponentIndex}) on message with {elementIndex}, as the field was not found")); } return(TryGetComponent(field, elementIndex)); } else { return(new Result <MessageElement>(field, null)); } }
/// <summary> /// Shows specific widget /// </summary> /// <param name="widget">Widget to show</param> /// <param name="position">X position to show widget</param> /// <returns></returns> public override float ShowWidget(ElementManager widget, WindowsStyleProperties style) { // Create control Control control = null; if (ElementIndex.ContainsKey(widget.Identifier)) { control = ElementIndex[widget.Identifier]; control.Location = new Point(0, style.YPosition); } else { control = CreateElement(widget, style); } // Calculate bottom position int newBottom = control.Height + control.Location.Y; // Check if form has enough space, extend if needed if (_widgetContainer.Height < newBottom) { _widgetContainer.Height = newBottom + (int)InitialPosition; } // Add control to form _widgetContainer.Controls.Add(control); // Return bottom return(newBottom); }
public bool AddItem(ElementIndex itemIndex, int number = 1) // 添加物品到背包 { if (itemIndex.first < 0 || itemIndex.second < 0 || number < 0) { return(false); } ItemsType item = ResourcesManager.instance.itemsPool [itemIndex.first] [itemIndex.second]; for (int i = 0; i < bagContent.Count; ++i) { if (bagContent [i].ID == item.ID) { if (item.usingtimes <= 0) // 不允许叠加无限耐久度的物品 { return(true); } ItemsType tmp = bagContent [i]; tmp.number += number; tmp.cur_usingtimes = (int)tmp.usingtimes; bagContent [i] = tmp; return(true); } } item.number = number; item.cur_usingtimes = (int)item.usingtimes; bagContent.Add(item); return(true); }
private static void ValidateNamesMatch(ElementIndex subjectElementIndex, IEnumerable <OsmGeo> elements, string parentFilterKey, string childKey, Action <OsmGeo, string> whenMissing = null) { whenMissing = whenMissing ?? ((element, key) => element.Tags.AddOrAppend(InfoKey, "Cannot find a matching " + key)); var parentNames = subjectElementIndex.Elements .Where(w => w.Tags != null && w.Tags.ContainsKey(parentFilterKey)) .SelectMany(w => Tags.GetNames(w.Tags)) .ToHashSet(); var parentNamesMinusPunctuation = parentNames .GroupBy(s => Tags.WithoutPunctuation(s), StringComparer.OrdinalIgnoreCase) .ToDictionary(g => g.Key, g => g.ToArray(), StringComparer.OrdinalIgnoreCase); var elementsWithKeyChanges = elements.Where(e => e.Tags.ContainsKey(childKey) && (e.Tags.ContainsKey(Static.maineE911id) || // added element e.Tags.ContainsKey(Static.maineE911id + ":" + childKey))); // changed element foreach (var element in elementsWithKeyChanges) { var childName = element.Tags[childKey]; if (!parentNames.Contains(childName)) { if (parentNamesMinusPunctuation.TryGetValue(childName, out string[] withPunctuationAndCase) &&
internal static Result <BaseField> TrySetField(BaseField field, ElementIndex elementIndex, string newValue, bool navigateSubField = true) { BaseField?returnValue = null; bool subFieldWasSet = false; if (navigateSubField && elementIndex.SubFieldIndex?.HasValue == true) { if (!(field is RepetitionField repField)) { return(ErrorReturn <BaseField>($"failed to find RepetitionField on message with {elementIndex}")); } List <BaseField>?fields = repField.Repetitions?.ToList(); if (fields == null) { return(ErrorReturn <BaseField>($"Attempted to set field, but there was no field collection found at {elementIndex}")); } if (!TryGetField(fields !, elementIndex.SubFieldIndex, out int foundIndex).DecomposeResult(out BaseField innerField, out string?error)) { return(ErrorReturn <BaseField>(error ?? "Unknown error getting field")); } if (!TrySetField(innerField, elementIndex, newValue, false).DecomposeResult(out var result, out error)) { return(ErrorReturn <BaseField>(error ?? "Unknown error setting field")); } fields[foundIndex - 1] = result; returnValue = new RepetitionField(repField, fields); subFieldWasSet = true; } if (!subFieldWasSet)//prevents trying to do this twice in recursion scenarios for RepetitionFields { if (elementIndex.ComponentIndex?.HasValue == true) { if (!(field is ComponentField componentField)) { return(ErrorReturn <BaseField>($"failed to find component({elementIndex.ComponentIndex}) on message with {elementIndex}, as the field was not found")); } if (!TryGetComponent(componentField, elementIndex.ComponentIndex, out int fieldIndex).DecomposeResult(out BaseComponent component, out string?error)) { return(ErrorReturn <BaseField>(error ?? "unknown error getting component")); } if (!TrySetComponent(component, newValue, elementIndex).DecomposeResult(out var result, out error)) { return(ErrorReturn <BaseField>(error ?? "Unknown error setting component")); } List <BaseComponent> components = componentField.Components.ToList(); components[fieldIndex - 1] = result; returnValue = new ComponentField(componentField, components); } else//probably value field - but override the whole value anyway { returnValue = CreateField(field.Encoding, newValue); } } if (returnValue == null) { return(ErrorReturn <BaseField>($"attempted to set field {elementIndex}, but failed to make any updates")); } return(new Result <BaseField>(returnValue !, null)); }
/// <summary> /// Remove element by ID /// </summary> /// <param name="id">widgetID</param> public void DestroyElement(string id) { // Remove from view RemoveFromView(ElementIndex[id]); // Remove from storage ElementIndex.Remove(id); }
public Element(string elementName, ElementType type, ElementIndex index, string detail, Dictionary <Planet.LandType, ElementGrowInfo> infos) { this.elementName = elementName; this.type = type; this.index = index; this.detail = detail; growInfos = infos; }
/// <summary>初期化</summary> public void Init() { if (!orderableList) { orderableList = GetComponentInParent <ReOrderableList> (); scrollRect = GetComponentInParent <ScrollRect> (); elementIndex = GetComponentInChildren <ElementIndex> (); buttons = GetComponentsInChildren <Button> (); } }
public void AddEnemyByID(string ID) { ElementIndex t = ResourcesManager.instance.GetEnemyIndex(ID); try{ EnemiesType obj = ResourcesManager.instance.enemiesPool [t.first] [t.second]; List <EnemiesType> l = new List <EnemiesType> (); l.Add(obj); boardScript.LayoutObjectAtRandom_Enemy(l, 1, 1); }catch { return; } }
/// <summary> /// 获得某种元素的定义, 禁止对其进行修改 /// </summary> public static bool GetElement(ElementType type, ElementIndex index, out Element element) { var count = GetElementCount(type); if ((int)index > count) { Debug.Log("你还没有定义" + type + "_" + index); element = null; return(false); } element = elements[type][(int)index]; return(true); }
/// <summary> /// Compares this instance to the <paramref name="other"/> <see cref="EdiPath"/>. /// </summary> /// <param name="other"></param> /// <returns></returns> public int CompareTo(EdiPath other) { var result = string.Compare(Segment, other.Segment, StringComparison.OrdinalIgnoreCase); if (result == 0) { result = ElementIndex.CompareTo(other.ElementIndex); } if (result == 0) { result = ComponentIndex.CompareTo(other.ComponentIndex); } return(result); }
// Use this for initialization void Start() { if (type == ElementType.food || type == ElementType.item) { index = ResourcesManager.instance.GetItemIndex(ID); ItemsType f = ResourcesManager.instance.itemsPool [index.first] [index.second]; if (f.fadingtime > 0) { Completed.GameManager.instance.AddItemToFaing(this, f.fadingtime); } } else { index = ResourcesManager.instance.GetStoriesIndex(ID); } }
// When matching, consider pulling capitalization and punctuation from local names. public static Osm FindMissingRoads(Osm subject, CompleteWay[] reference) { var missing = new List <CompleteWay>(); var misShapen = new List <CompleteWay>(); var keysToIndex = new Dictionary <string, Func <string, string[]> >() { { "name", Tags.WithOrWithoutPunctuation } }; var subjectWays = subject.Ways .Where(e => e.Tags != null && e.Tags.ContainsKey("name") && e.Tags.ContainsKey("highway")) .ToArray(); var subjectNodes = subject.Nodes.ToDictionary(n => n.Id.Value); var subjectElementIndex = new ElementIndex(subjectWays, keysToIndex); foreach (var referenceRoad in reference) { var searchTags = new TagsCollection(new Tag("name", referenceRoad.Tags["name"])); if (subjectElementIndex.TryGetMatchingElements(searchTags, out var candidates)) { var candidateNodes = candidates.OfType <Way>().SelectMany(c => c.Nodes.Select(n => subjectNodes[n])); var byLat = new SortedList <double, Node[]>(candidateNodes.GroupBy(n => n.Latitude.Value).ToDictionary(g => g.Key, g => g.ToArray())); var byLon = new SortedList <double, Node[]>(candidateNodes.GroupBy(n => n.Longitude.Value).ToDictionary(g => g.Key, g => g.ToArray())); var near = referenceRoad.Nodes.RatioWhere(n => BoundsExtentions.FastNodesInBounds(n.AsBounds().ExpandBy(30), byLat, byLon).Any()); if (near == 0) { missing.Add(referenceRoad); } else if (near < 1) { // This needs to be defined better, maybe closeness to the line, vs closeness to a point. misShapen.Add(referenceRoad); } } else { missing.Add(referenceRoad); } } return(missing.AsOsm()); }
/// <summary> /// Updates the view of a specific widget /// </summary> /// <param name="widget">Target widget</param> public override void UpdateView(ElementManager widget) { if (widget.Active == true) { if (!ElementIndex.ContainsKey(widget.Identifier)) { // TODO: ADD WIDGET ON CORRECT POSITION IN VIEW ShowWidget(widget, DefaultStyle); } else { _elementFactory.UpdateElement(widget, ElementIndex[widget.Identifier]); } } else if (ElementIndex.ContainsKey(widget.Identifier)) { DestroyElement(widget.Identifier); } }
// Collections are modified by reference. Errors removed and logged. Warns just logged. // Whitelist suppresses warns and errors. private static List <OsmGeo> GatherExceptions(List <long> whiteList, List <long> ignoreList, ElementIndex subjectElementIndex, params List <OsmGeo>[] elementss) { var review = new List <OsmGeo>(); foreach (var elements in elementss) { var errors = elements.Where(e => e.Tags.ContainsKey(ErrorKey)).ToList(); ExcuseListedElements(errors, whiteList, WhiteListKey); review.AddRange(errors); var warns = elements.Where(e => e.Tags.ContainsKey(WarnKey)).ToList(); ExcuseListedElements(warns, whiteList, WhiteListKey); review.AddRange(warns); elements.RemoveAll(errors.Contains); ExcuseListedElements(elements.ToList(), whiteList, WhiteListKey); // doesn't remove, just to add maineE911id:whitelist=yes var distinct = elements.Distinct().ToArray(); elements.Clear(); elements.AddRange(distinct); } ExcuseListedElements(review, ignoreList, IgnoreListKey); AddFixMe(review); var reviewsWith = review.ToArray().Where(e => e.Tags.ContainsKey(ReviewWithKey)).Distinct() .ToDictionary(r => r, r => r.Tags[ReviewWithKey].Split(";").Select(rw => subjectElementIndex.ByOsmGeoKey[rw])); foreach (var reviewWith in reviewsWith) { foreach (var with in reviewWith.Value) { var arrow = Geometry.GetDirectionArrow( with.AsComplete(subjectElementIndex.ByOsmGeoKey).AsPosition(), reviewWith.Key.AsComplete(subjectElementIndex.ByOsmGeoKey).AsPosition()); with.Tags.AddOrAppend(InfoKey, arrow.ToString()); with.Tags.AddOrAppend(Static.maineE911id + ":osm-id", with.Type + "/" + with.Id); review.Add(with); } } return(review); }
//OnCantMove is called if Enemy attempts to move into a space occupied by a Player, it overrides the OnCantMove function of MovingObject //and takes a generic parameter T which we use to pass in the component we expect to encounter, in this case Player protected override void OnCantMove <T> (T component) { //Declare hitPlayer and set it to equal the encountered component. Player hitPlayer = component as Player; //Call the LoseFood function of hitPlayer passing it playerDamage, the amount of foodpoints to be subtracted. if (!iscopied) { //type_copy = ResourcesManager.instance.enemyPool [ResourcesManager.instance.GetEnemyPoolIndex (Enemy_ID)]; ElementIndex v2t = ResourcesManager.instance.GetEnemyIndex(Enemy_ID); type_copy = ResourcesManager.instance.enemiesPool [v2t.first] [v2t.second]; iscopied = true; } if (HP > 0) { //ChangeHP (-hitPlayer.Atk); if (type_copy.effect == null) { hitPlayer.BeAttacked(playerDamage); // 若无技能,则只产生普通攻击影响 } else { float ran = Random.Range(0.0f, 1.0f); //计算几率 if (ran < type_copy.rate) { type_copy.effect.Call(hitPlayer); //若随机满足,则产生技能影响 } else { hitPlayer.BeAttacked(playerDamage); // 若不满足,则产生普通攻击影响 } } //Set the attack trigger of animator to trigger Enemy attack animation. animator.SetTrigger("enemyAttack"); //Call the RandomizeSfx function of SoundManager passing in the two audio clips to choose randomly between. SoundManager.instance.RandomizeSfx(attackSound1, attackSound2); } }
public bool ReduceItem(ElementIndex itemIndex, int number = 1, bool notBellowZero = false) // 减少物品数量 { if (itemIndex.first < 0 || itemIndex.second < 0 || number < 0) { return(false); } ItemsType item = ResourcesManager.instance.itemsPool [itemIndex.first] [itemIndex.second]; for (int i = 0; i < bagContent.Count; ++i) { if (bagContent [i].ID == item.ID) { ItemsType tmp = bagContent [i]; tmp.number -= number; if (tmp.number == 0) { bagContent.RemoveAt(i); } else if (tmp.number < 0) { if (notBellowZero) { return(false); } else { bagContent.RemoveAt(i); } } else { bagContent [i] = tmp; } return(true); } } return(false); }
public static OsmChange Merge(Osm reference, Osm subject, string scopeName, GeoJsonAPISource.Municipality municipality) { Log = Log ?? Static.LogFactory.CreateLogger(typeof(Conflate)); // Can blacklist subject elements also! Fixme: colisions between different element types with the same ID var subjectElements = subject.GetElements().Where(e => !municipality.BlackList.Contains(e.Id.Value)); var subjectElementIndex = new ElementIndex(subjectElements.ToArray()); List <OsmGeo> create = new List <OsmGeo>(reference.Nodes); List <OsmGeo> modify = new List <OsmGeo>(); List <OsmGeo> delete = new List <OsmGeo>(); Log.LogInformation("Starting conflation, matching by tags"); MergeNodesByTags(new[] { "addr:street", "addr:housenumber", "addr:unit" }, subjectElementIndex, municipality.WhiteList, create, modify); MergeNodesByTags(new[] { "addr:street", "addr:housenumber" }, subjectElementIndex, municipality.WhiteList, create, modify); MergeNodesByTags(new[] { "name" }, subjectElementIndex, municipality.WhiteList, create, modify); Log.LogInformation("Starting conflation, matching by geometry"); MergeNodesByGeometry(subjectElementIndex, municipality.WhiteList, create, modify); ValidateNamesMatch(subjectElementIndex, create.Concat(modify), "highway", "addr:street", (element, key) => ShouldStreetBeAPlace(element, subjectElementIndex)); ValidateNamesMatch(subjectElementIndex, create.Concat(modify), "place", "addr:place"); Log.LogInformation($"Writing {scopeName} review files"); var review = GatherExceptions(municipality.WhiteList, municipality.IgnoreList, subjectElementIndex, create, delete, modify); WriteToFileWithChildrenIfAny(scopeName + "/Conflated.Review.osm", review, subjectElementIndex); WriteToFileWithChildrenIfAny(scopeName + "/Conflated.Create.osm", create, subjectElementIndex); WriteToFileWithChildrenIfAny(scopeName + "/Conflated.Delete.osm", delete, subjectElementIndex); WriteToFileWithChildrenIfAny(scopeName + "/Conflated.Modify.osm", modify, subjectElementIndex); RemoveReviewTags(create, delete, modify); var change = Changes.FromGeos(create, modify, delete, "OsmPipeline"); LogSummary(change, review); return(change); }
public bool LayoutObject(ElementIndex index, Vector3 position) { GameObject tile = ResourcesManager.instance.itemsPool[index.first][index.second].tile; if (tile == null) { return(false); } if (checkBlock(position.x, position.y) != null) { return(false); } Vector3 final_pos = new Vector3(Mathf.Round(position.x), Mathf.Round(position.y), 0.0f); if (final_pos.x >= columns || final_pos.x < 0 || final_pos.y >= rows || final_pos.y < 0) { return(false); } //Physics2D.BoxCast Instantiate(tile, final_pos, Quaternion.identity); return(true); }
internal static Result <BaseComponent> TrySetComponent(BaseComponent?component, string newValue, ElementIndex elementIndex) { if (elementIndex.SubComponentIndex.HasValue) { if (component == null || !(component is ComplexComponent complexComponent)) { return(ErrorReturn <BaseComponent>($"failed to find subComponent on message with {elementIndex}, as the component was not found")); } List <BaseSubComponent> subComponents = complexComponent?.SubComponents != null?complexComponent.SubComponents.ToList() : new List <BaseSubComponent>(); BaseSubComponent?subComponent = subComponents?.ElementAtOrDefault(elementIndex.SubComponentIndex.Value - 1); if (subComponent == null) { return(ErrorReturn <BaseComponent>($"failed to find subComponent {elementIndex}")); } subComponents ![elementIndex.SubComponentIndex.Value - 1] = new SubComponent(subComponent, newValue);//set the right type of subcomponent if we ever add others.
public static void AddConsume(BuildingResourceConsume buildingResourceConsume, ElementType type, ElementIndex index, float amount) { buildingResourceConsume.consumeList.Add(new BuildingResource(new ElementID(type, index), amount)); }
public ElementID(Element e) { type = e.type; index = e.index; }
public static Result <MessageElement> TryGetSpecifiedMessageElement(this Message message, ElementIndex elementIndex) { var valResult = ValidateNameAndIndexes(elementIndex); if (!valResult) { return(ErrorReturn <MessageElement>(valResult.Error ?? $"Request format is not valid: segmentName: {elementIndex}")); } var segmentAndList = TryGetSegmentAndSegmentCollectionAndIndex(message, elementIndex.SegmentIndex); if (!segmentAndList) { return(ErrorReturn <MessageElement>(segmentAndList.Error ?? "Did not find segment and index")); } if (elementIndex.FieldIndex?.HasValue == true) { if (segmentAndList.Value.Segment == null) { return(ErrorReturn <MessageElement>($"failed to find field {elementIndex} as the segment was not found")); } return(TryGetField(segmentAndList.Value.Segment, elementIndex)); } else { if (segmentAndList.Value.Segment == null) { return(ErrorReturn <MessageElement>($"Did not find a segment for {elementIndex}")); } return(new Result <MessageElement>(segmentAndList.Value.Segment, null)); } }
public ElementID(ElementType type, ElementIndex index) { this.type = type; this.index = index; }