@adatechnology/game-urban 0.2.8 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -75,8 +75,8 @@ const plan = urban.neighbourhoods.get('suburb').compose(b, { x: 0, z: 0 }, {
75
75
  locale: 'en',
76
76
  providers: {
77
77
  house: (typology, request, b) => myHouse(typology, request, b), // default: the far-away silhouettes of game-floorplan
78
- vehicle: createVehicleProvider(), // default: none (the page's box car is not shipped)
79
- plant: createPlantProvider(), // default: the cone pine and the ball tree of the props
78
+ vehicle: createVehicleProvider({ ids: myFleetIds }), // default: none (the page's box car is not shipped)
79
+ plant: createPlantProvider({ pickSpecies: myPicker }), // default: the cone pine and the ball tree of the props
80
80
  },
81
81
  })
82
82
  // plan: { id, origin, houses, buildings, poles, vehicles, plants } (what was put where)
@@ -85,7 +85,7 @@ urban.neighbourhoods.composeSampleSheet(b) // the ground and the ten cells, in
85
85
 
86
86
  ### Vehicles and plants from the other packages
87
87
 
88
- `createVehicleProvider({ ids?, pick?, paint? })` parks a vehicle of `game-vehicles-fleet` (cars, SUVs, pickups and vans by default) where a pattern parks one, and `createPlantProvider({ region?, contexts?, seed?, pick? })` plants a species of `game-vegetation-species` where a pattern plants (a tree from the region's `sidewalk_tree` table, a pine from `square`). They do not draw: they add a `placement` part (`b.place(kind, id, x, z, { ry, scale, color, seed })`) that says what to put and where. The choice depends on the spot and not on `b.random`, so the scene around it keeps the same draw order. The drawer (`game-urban-three`) asks a resolver for each kind and leaves the spot empty when it has none.
88
+ `createVehicleProvider({ ids, pick?, paint? })` parks a vehicle of the fleet the game names in `ids` where a pattern parks one, and `createPlantProvider({ pickSpecies, contexts?, seed?, pick? })` plants the species `pickSpecies(context, key)` returns where a pattern plants (a tree from the `sidewalk_tree` context, a pine from `square`). The fleet and the species come by option (the recommended path; the preset `defaultUrbanProviders()` of `@adatechnology/game-kit-defaults` uses it). Without them the providers keep the old defaults, `PARKED_VEHICLE_IDS` of `game-vehicles-fleet` and the regional tables of `game-vegetation-species`; those defaults are deprecated and removed in the next major. They do not draw: they add a `placement` part (`b.place(kind, id, x, z, { ry, scale, color, seed })`) that says what to put and where. The choice depends on the spot and not on `b.random`, so the scene around it keeps the same draw order. The drawer (`game-urban-three`) asks a resolver for each kind and leaves the spot empty when it has none.
89
89
 
90
90
  ## City plans (zoning)
91
91
 
package/dist/index.d.ts CHANGED
@@ -325,16 +325,23 @@ type UrbanScene = {
325
325
  dark: SilhouetteWindow[];
326
326
  };
327
327
  };
328
- /** The lights a scene may spend. Every lamp that is on takes one, and the first ones win; the rest keep only their glowing lens. */
329
- type LightBudget = {
328
+ /**
329
+ * How many lights a scene may spend (a counter, not the render budget of `@adatechnology/game-render-three`). Every lamp that is on takes one, and the first ones win; the rest keep only their
330
+ * glowing lens.
331
+ */
332
+ type LightAllowance = {
330
333
  /** Lights left. It goes below zero when more lamps ask than the budget had, as the team's counter does. */
331
334
  left: number;
332
335
  /** True while the budget lasts (spends one either way). */
333
336
  take(): boolean;
334
337
  };
338
+ /** @deprecated Renamed `LightAllowance`: `LightBudget` is the name of the render budget of `@adatechnology/game-render-three`. Removed in the next major. */
339
+ type LightBudget = LightAllowance;
335
340
 
336
- /** The team's counter: `take()` is `left-- > 0`, so the count keeps falling after the budget is spent. */
337
- declare function createLightBudget(count: number): LightBudget;
341
+ /** The team's counter: `take()` is `left-- > 0`, so the count keeps falling after the allowance is spent. */
342
+ declare function createLightAllowance(count: number): LightAllowance;
343
+ /** @deprecated Renamed `createLightAllowance`: `LightBudget` is the name of the render budget of `@adatechnology/game-render-three`. Removed in the next major. */
344
+ declare const createLightBudget: typeof createLightAllowance;
338
345
 
339
346
  type BoxOptions = {
340
347
  parent?: number;
@@ -345,7 +352,7 @@ type BoxOptions = {
345
352
  };
346
353
  type UrbanBuilderOptions = {
347
354
  /** Lights the scene may spend; omitted means no limit. */
348
- budget?: LightBudget;
355
+ budget?: LightAllowance;
349
356
  };
350
357
  /**
351
358
  * Collects the parts of an urban scene the way the team's page adds them to its root: every helper appends in call order, so a
@@ -355,7 +362,7 @@ type UrbanBuilderOptions = {
355
362
  declare function createUrbanBuilder(random: RandomSource, options?: UrbanBuilderOptions): {
356
363
  random: RandomSource;
357
364
  pick: <TEntry>(list: readonly TEntry[]) => TEntry;
358
- lights: LightBudget;
365
+ lights: LightAllowance;
359
366
  parts: UrbanPart[];
360
367
  items: ItemBox[];
361
368
  windows: {
@@ -532,7 +539,10 @@ type PoleOptions = {
532
539
  /** Adds the transformer drum (single arm). */
533
540
  transformer?: boolean;
534
541
  };
535
- type PoleShapeBuilder = (b: UrbanBuilder, spec: any, o: PoleOptions) => void;
542
+ /** Draws a pole from its `spec`. Declared as a method so the registry can hold each builder with its own spec type (the `PoleDef` names the builder that reads its spec). */
543
+ type PoleShapeBuilder<TSpec extends object = object> = {
544
+ build(b: UrbanBuilder, spec: TSpec, o: PoleOptions): void;
545
+ }['build'];
536
546
  type PoleDef = {
537
547
  id: string;
538
548
  /** Key of the shape builder that reads `spec`. */
@@ -919,7 +929,13 @@ type ComposeContext<TParams = Record<string, unknown>> = {
919
929
  shop?: number;
920
930
  }): void;
921
931
  };
922
- type Composer<TParams = any> = (context: ComposeContext<TParams>) => void;
932
+ /**
933
+ * Draws a pattern from its params. Declared as a method so a registry of composers can hold each with its own params type
934
+ * (the pattern that names the composer carries the matching params).
935
+ */
936
+ type Composer<TParams = Record<string, unknown>> = {
937
+ compose(context: ComposeContext<TParams>): void;
938
+ }['compose'];
923
939
  type ComposeOptions = {
924
940
  locale?: Locale;
925
941
  providers?: Providers;
@@ -1127,9 +1143,9 @@ type Origin = {
1127
1143
  z: number;
1128
1144
  };
1129
1145
  /** Draws one pattern at `origin`: its composer, then the board with the title and the caption. */
1130
- declare function composePattern(kit: UrbanKitCore, pattern: NeighbourhoodPattern<any>, composer: Composer, b: UrbanBuilder, origin: Origin, options?: ComposeOptions): UrbanPlan;
1146
+ declare function composePattern(kit: UrbanKitCore, pattern: NeighbourhoodPattern, composer: Composer, b: UrbanBuilder, origin: Origin, options?: ComposeOptions): UrbanPlan;
1131
1147
  /** The marker (map pin) of a pattern at an origin: where it stands, how high, and what it says. */
1132
- declare function patternMarker(pattern: NeighbourhoodPattern<any>, origin: Origin, locale?: Locale): {
1148
+ declare function patternMarker(pattern: NeighbourhoodPattern, origin: Origin, locale?: Locale): {
1133
1149
  x: number;
1134
1150
  y: number;
1135
1151
  z: number;
@@ -1180,6 +1196,8 @@ type Terrain = ReturnType<typeof createTerrain>;
1180
1196
  declare function drawTerrain(b: UrbanBuilder, terrain: Terrain, segments?: number): void;
1181
1197
 
1182
1198
  /** Lights a scene may spend: the Galeria spends 16 real point lights. */
1199
+ declare const DEFAULT_LIGHT_ALLOWANCE = 16;
1200
+ /** @deprecated Renamed `DEFAULT_LIGHT_ALLOWANCE`. Removed in the next major. */
1183
1201
  declare const DEFAULT_LIGHT_BUDGET = 16;
1184
1202
  /** Seed of the Galeria's generator. */
1185
1203
  declare const DEFAULT_URBAN_SEED = 7;
@@ -1187,14 +1205,14 @@ type UrbanOptions = {
1187
1205
  /** Entries added to the catalogues (an entry with an existing id replaces it). */
1188
1206
  packs?: {
1189
1207
  poles?: readonly PoleDef[];
1190
- neighbourhoods?: readonly NeighbourhoodPattern<any>[];
1208
+ neighbourhoods?: readonly NeighbourhoodPattern[];
1191
1209
  districtKinds?: readonly DistrictKindDef[];
1192
1210
  cityPlans?: readonly CityPlanInput[];
1193
1211
  };
1194
1212
  /** Numbers changed on shipped entries, by id (objects merge, arrays replace). */
1195
1213
  patch?: {
1196
1214
  poles?: Record<string, DeepPartial<PoleDef>>;
1197
- neighbourhoods?: Record<string, DeepPartial<NeighbourhoodPattern<any>>>;
1215
+ neighbourhoods?: Record<string, DeepPartial<NeighbourhoodPattern>>;
1198
1216
  districtKinds?: Record<string, DeepPartial<DistrictKindDef>>;
1199
1217
  cityPlans?: Record<string, DeepPartial<CityPlanInput>>;
1200
1218
  };
@@ -1268,7 +1286,7 @@ declare function createUrban(options?: UrbanOptions): {
1268
1286
  neighbourhoods: {
1269
1287
  ids: () => string[];
1270
1288
  get(id: string): {
1271
- pattern: NeighbourhoodPattern<any>;
1289
+ pattern: NeighbourhoodPattern;
1272
1290
  /** Draws the pattern at `origin` and gives back what it put there. */
1273
1291
  compose: (b: UrbanBuilder, origin: Origin, o?: ComposeOptions) => UrbanPlan;
1274
1292
  marker: (origin: Origin, locale?: Locale) => {
@@ -1721,10 +1739,13 @@ declare const SILHOUETTE_TYPOLOGIES: Readonly<Record<string, SilhouetteFactory>>
1721
1739
  /** The default provider: the silhouette of game-floorplan for the typology, added to the builder with its shared random. */
1722
1740
  declare function createSilhouetteHouses(typologies?: Readonly<Record<string, SilhouetteFactory>>): HouseProvider;
1723
1741
 
1724
- /** The vehicles of the fleet that park on a street: cars, SUVs, pickups and vans. */
1742
+ /**
1743
+ * The vehicles of the fleet that park on a street: cars, SUVs, pickups and vans.
1744
+ * @deprecated the fleet is content: pass `ids` to `createVehicleProvider` (`PARKED_VEHICLE_IDS` of `@adatechnology/game-kit-defaults` is the same list). The default is removed in the next major.
1745
+ */
1725
1746
  declare const PARKED_VEHICLE_IDS: readonly string[];
1726
1747
  type VehicleProviderOptions = {
1727
- /** Ids of the fleet to choose from. Default `PARKED_VEHICLE_IDS`. */
1748
+ /** Ids of the fleet to choose from. Default `PARKED_VEHICLE_IDS`, which is deprecated: pass the ids (`game-kit-defaults` has the same list). */
1728
1749
  ids?: readonly string[];
1729
1750
  /** Replaces the choice: the id for a request. The default picks by the spot, so the same pattern parks the same cars every time. */
1730
1751
  pick?: (request: VehicleRequest, ids: readonly string[]) => string;
@@ -1737,7 +1758,12 @@ type VehicleProviderOptions = {
1737
1758
  */
1738
1759
  declare function createVehicleProvider(options?: VehicleProviderOptions): VehicleProvider;
1739
1760
  type PlantProviderOptions = {
1740
- /** Planting table of a region. Default Brazil's. */
1761
+ /** Chooses the species id for a context of the planting table and a key (`defaultPlantPicker` of `game-kit-defaults`, or the game's own). Without it the species come from the `region` table (deprecated default). */
1762
+ pickSpecies?: (context: string, key: string) => string;
1763
+ /**
1764
+ * Planting table of a region, used only when `pickSpecies` is absent. Default Brazil's.
1765
+ * @deprecated pass `pickSpecies`; the default is removed in the next major.
1766
+ */
1741
1767
  region?: Region;
1742
1768
  /** Context of the table for each kind the patterns plant. */
1743
1769
  contexts?: Partial<Record<PlantRequest['kind'], string>>;
@@ -1747,11 +1773,11 @@ type PlantProviderOptions = {
1747
1773
  pick?: (request: PlantRequest, context: string, seed: string) => string;
1748
1774
  };
1749
1775
  declare const DEFAULT_PLANT_CONTEXTS: Readonly<Record<PlantRequest['kind'], string>>;
1750
- /** A plant provider that asks the drawer for a species of the pack, drawn from the region's table for the kind (a tree on the sidewalk, a pine in the square). */
1776
+ /** A plant provider that asks the drawer for a species chosen by `pickSpecies`, from the table of the context for the kind (a tree on the sidewalk, a pine in the square). */
1751
1777
  declare function createPlantProvider(options?: PlantProviderOptions): PlantProvider;
1752
1778
 
1753
1779
  /** The ten patterns of the Galeria's sample sheet, in the order the page builds them. */
1754
- declare const DEFAULT_PATTERNS: readonly NeighbourhoodPattern<any>[];
1780
+ declare const DEFAULT_PATTERNS: readonly NeighbourhoodPattern[];
1755
1781
  /** Where the sample sheet puts each pattern: a 3 x 3 grid 80 by 56 m apart, and the military cell off to the east. */
1756
1782
  declare const SAMPLE_CELLS: Readonly<Record<string, {
1757
1783
  x: number;
@@ -1759,11 +1785,11 @@ declare const SAMPLE_CELLS: Readonly<Record<string, {
1759
1785
  }>>;
1760
1786
 
1761
1787
  /** The patterns of the tower pack. */
1762
- declare const TOWER_PATTERNS: readonly NeighbourhoodPattern<any>[];
1788
+ declare const TOWER_PATTERNS: readonly NeighbourhoodPattern[];
1763
1789
  /** Where the sample sheet puts them (pass it as `cells`). */
1764
1790
  declare const TOWER_SAMPLE_CELLS: Readonly<Record<string, {
1765
1791
  x: number;
1766
1792
  z: number;
1767
1793
  }>>;
1768
1794
 
1769
- export { type BarSpec, type Block, type BlockBuilding, type BlockUse, type BuilderOptions, type BuildingOptions, COMPOSERS, type Cities, type CitiesOptions, type CityLayout, type CityPlanDef, type CityPlanInput, type CityScale, type ColorRule, type ComposeContext, type ComposeOptions, type Composer, type ConePart, type CrossarmSpec, type CrownPart, DEFAULT_CITY_PLANS, DEFAULT_DISTRICT_KINDS, DEFAULT_FACADES, DEFAULT_LIGHT_BUDGET, DEFAULT_MAX_FLOORS, DEFAULT_PATTERNS, DEFAULT_PLANT_CONTEXTS, DEFAULT_POLES, DEFAULT_PROP_COLORS, DEFAULT_ROAD_STYLE, DEFAULT_STOREY_PRESETS, DEFAULT_STREET, DEFAULT_TOWER_PRESETS, DEFAULT_URBAN_SEED, DEFAULT_WALK_STYLE, type DistrictKindDef, type DistrictKindText, type DoubleArmSpec, type DowntownParams, type FillBlockCityOptions, type FillBlockOptions, type Flatten, type FloodTowerSpec, type ForestOptions, type HistoricParams, type HouseProvider, type HouseRequest, type IndustrialParams, type ItemBox, type KindStats, type LabelPart, type Lake, type LampLightSpec, type LampSpec, type LanternSpec, type LayoutOptions, type LensSpec, type LightBudget, type LightPart, type Locale, type MastSpec, type MilitaryParams, type MountainParams, type NeighbourhoodPattern, type Origin, PARKED_VEHICLE_IDS, POLE_SHAPES, type PartStyle, type PatternText, type PlacementPart, type PlanDistrict, type PlanLandmark, type PlanLine, type PlanPoint, type PlanRect, type PlanePart, type PlantProvider, type PlantProviderOptions, type PlantRequest, type Point, type Pole, type PoleDef, type PoleOptions, type PoleShapeBuilder, type PropColors, type Providers, type RailwayParams, type Ramp, type Rect, type ResolvedDistrict, type River, type RiverBed, type RoadStyle, type RuralParams, SAMPLE_CELLS, SILHOUETTE_TYPOLOGIES, type SampleSheetOptions, type SilhouetteFactory, type SingleArmSpec, type StiltParams, type StreetOptions, type SuburbParams, TOWER_DEFAULTS, TOWER_PATTERNS, TOWER_SAMPLE_CELLS, type Terrain, type TerrainGrid, type TerrainLayer, type TerrainOptions, type TerrainPart, type TowerOptions, type TowerPreset, type TowerProvider, type TowerRequest, type Trig, type UrbanBuilder, type UrbanBuilderOptions, type UrbanKit, type UrbanKitCore, type UrbanOptions, type UrbanPart, type UrbanPlan, type UrbanScene, type VaultPart, type VehicleProvider, type VehicleProviderOptions, type VehicleRequest, type WalkStyle, type Wave, type WorkingClassParams, type WorldFrame, clamp, composePattern, createCities, createLightBudget, createPlantProvider, createSilhouetteHouses, createTerrain, createTowerDrawer, createUrban, createUrbanBuilder, createVehicleProvider, distanceToPolyline, drawBuilding, drawContainer, drawFence, drawGround, drawPine, drawRoad, drawSandbags, drawStreetGrid, drawStripLabel, drawTent, drawTerrain, drawTower, drawTree, drawWalk, drawWatchtower, drawWires, fillBlock, hash2, insideEllipse, insideRect, lerp, patternMarker, pickTowerPreset, smoothstep, towerPresetOf, towerStoreys };
1795
+ export { type BarSpec, type Block, type BlockBuilding, type BlockUse, type BuilderOptions, type BuildingOptions, COMPOSERS, type Cities, type CitiesOptions, type CityLayout, type CityPlanDef, type CityPlanInput, type CityScale, type ColorRule, type ComposeContext, type ComposeOptions, type Composer, type ConePart, type CrossarmSpec, type CrownPart, DEFAULT_CITY_PLANS, DEFAULT_DISTRICT_KINDS, DEFAULT_FACADES, DEFAULT_LIGHT_ALLOWANCE, DEFAULT_LIGHT_BUDGET, DEFAULT_MAX_FLOORS, DEFAULT_PATTERNS, DEFAULT_PLANT_CONTEXTS, DEFAULT_POLES, DEFAULT_PROP_COLORS, DEFAULT_ROAD_STYLE, DEFAULT_STOREY_PRESETS, DEFAULT_STREET, DEFAULT_TOWER_PRESETS, DEFAULT_URBAN_SEED, DEFAULT_WALK_STYLE, type DistrictKindDef, type DistrictKindText, type DoubleArmSpec, type DowntownParams, type FillBlockCityOptions, type FillBlockOptions, type Flatten, type FloodTowerSpec, type ForestOptions, type HistoricParams, type HouseProvider, type HouseRequest, type IndustrialParams, type ItemBox, type KindStats, type LabelPart, type Lake, type LampLightSpec, type LampSpec, type LanternSpec, type LayoutOptions, type LensSpec, type LightAllowance, type LightBudget, type LightPart, type Locale, type MastSpec, type MilitaryParams, type MountainParams, type NeighbourhoodPattern, type Origin, PARKED_VEHICLE_IDS, POLE_SHAPES, type PartStyle, type PatternText, type PlacementPart, type PlanDistrict, type PlanLandmark, type PlanLine, type PlanPoint, type PlanRect, type PlanePart, type PlantProvider, type PlantProviderOptions, type PlantRequest, type Point, type Pole, type PoleDef, type PoleOptions, type PoleShapeBuilder, type PropColors, type Providers, type RailwayParams, type Ramp, type Rect, type ResolvedDistrict, type River, type RiverBed, type RoadStyle, type RuralParams, SAMPLE_CELLS, SILHOUETTE_TYPOLOGIES, type SampleSheetOptions, type SilhouetteFactory, type SingleArmSpec, type StiltParams, type StreetOptions, type SuburbParams, TOWER_DEFAULTS, TOWER_PATTERNS, TOWER_SAMPLE_CELLS, type Terrain, type TerrainGrid, type TerrainLayer, type TerrainOptions, type TerrainPart, type TowerOptions, type TowerPreset, type TowerProvider, type TowerRequest, type Trig, type UrbanBuilder, type UrbanBuilderOptions, type UrbanKit, type UrbanKitCore, type UrbanOptions, type UrbanPart, type UrbanPlan, type UrbanScene, type VaultPart, type VehicleProvider, type VehicleProviderOptions, type VehicleRequest, type WalkStyle, type Wave, type WorkingClassParams, type WorldFrame, clamp, composePattern, createCities, createLightAllowance, createLightBudget, createPlantProvider, createSilhouetteHouses, createTerrain, createTowerDrawer, createUrban, createUrbanBuilder, createVehicleProvider, distanceToPolyline, drawBuilding, drawContainer, drawFence, drawGround, drawPine, drawRoad, drawSandbags, drawStreetGrid, drawStripLabel, drawTent, drawTerrain, drawTower, drawTree, drawWalk, drawWatchtower, drawWires, fillBlock, hash2, insideEllipse, insideRect, lerp, patternMarker, pickTowerPreset, smoothstep, towerPresetOf, towerStoreys };