* defaults * Defaults are the Presets and Categories offered to the user when adding a new feature. * Each geometry type has its own set of defaults. * The fallback preset for the given geometry is appended to the list automatically. * @param geometry * @param limit
(geometry, limit = 10, startWithRecents = true, loc = null)
| 487 | * @return Collection |
| 488 | */ |
| 489 | defaults(geometry, limit = 10, startWithRecents = true, loc = null) { |
| 490 | let results = new Map(); // Map (itemID -> item) (may be a Preset or a Category) |
| 491 | |
| 492 | if (startWithRecents) { |
| 493 | for (const preset of this.getRecents()) { |
| 494 | if (results.size < MAXRECENTS_SHOW && preset.matchGeometry(geometry)) { |
| 495 | results.set(preset.id, preset); |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | // If there is a set of addable presetIDs, use that instead of defaults |
| 501 | if (this.addablePresetIDs instanceof Set) { |
| 502 | for (const itemID of this.addablePresetIDs) { |
| 503 | const item = this.item(itemID); |
| 504 | if (item?.matchGeometry(geometry)) { |
| 505 | results.set(itemID, item); |
| 506 | } |
| 507 | } |
| 508 | } else { |
| 509 | for (const item of this._defaults[geometry]) { |
| 510 | if (item.matchGeometry(geometry)) { |
| 511 | results.set(item.id, item); |
| 512 | } |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | const fallback = this.fallback(geometry); |
| 517 | if (fallback && !results.has(fallback.id)) { |
| 518 | results.set(fallback.id, fallback); |
| 519 | } |
| 520 | |
| 521 | // If a location was provided, filter results to only those valid here. |
| 522 | let arr = [...results.values()]; |
| 523 | if (Array.isArray(loc)) { |
| 524 | const locations = this.context.systems.locations; |
| 525 | const validHere = locations.locationSetsAt(loc); |
| 526 | arr = arr.filter(item => !item.locationSetID || validHere[item.locationSetID]); |
| 527 | } |
| 528 | |
| 529 | return new Collection(this.context, arr.slice(0, limit - 1)); |
| 530 | } |
| 531 | |
| 532 | |
| 533 | /** |
no test coverage detected