|
Last change
on this file was 21296, checked in by elexis, 7 years ago |
|
Cleanup random map Area prototype following rP9271.
Delete areaID and just identify the Area object by the actual JS object reference.
Delete all references from Areas in the RandomMap object,
especially the area property of the RandomMap object became invalid after creating a new area.
This was replaced with a cache in the Area object and a contains function.
Add getPoints getter, so that the Area property is not accessed directly.
Deepfreeze points to prevent accidental overwrites.
Implement StayAreasConstraint and extend currently unused AvoidAreaConstraint to accept multiple areas.
|
-
Property svn:eol-style
set to
native
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * The LayeredPainter sets different Terrains within the Area.
|
|---|
| 3 | * It choses the Terrain depending on the distance to the border of the Area.
|
|---|
| 4 | *
|
|---|
| 5 | * The Terrains given in the first array are painted from the border of the area towards the center (outermost first).
|
|---|
| 6 | * The widths array has one item less than the Terrains array.
|
|---|
| 7 | * Each width specifies how many tiles the corresponding Terrain should be wide (distance to the prior Terrain border).
|
|---|
| 8 | * The remaining area is filled with the last terrain.
|
|---|
| 9 | */
|
|---|
| 10 | function LayeredPainter(terrainArray, widths)
|
|---|
| 11 | {
|
|---|
| 12 | if (!(terrainArray instanceof Array))
|
|---|
| 13 | throw new Error("LayeredPainter: terrains must be an array!");
|
|---|
| 14 |
|
|---|
| 15 | this.terrains = terrainArray.map(terrain => createTerrain(terrain));
|
|---|
| 16 | this.widths = widths;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | LayeredPainter.prototype.paint = function(area)
|
|---|
| 20 | {
|
|---|
| 21 | breadthFirstSearchPaint({
|
|---|
| 22 | "area": area,
|
|---|
| 23 | "brushSize": 1,
|
|---|
| 24 | "gridSize": g_Map.getSize(),
|
|---|
| 25 | "withinArea": (area, position) => area.contains(position),
|
|---|
| 26 | "paintTile": (point, distance) => {
|
|---|
| 27 | let width = 0;
|
|---|
| 28 | let i = 0;
|
|---|
| 29 |
|
|---|
| 30 | for (; i < this.widths.length; ++i)
|
|---|
| 31 | {
|
|---|
| 32 | width += this.widths[i];
|
|---|
| 33 | if (width >= distance)
|
|---|
| 34 | break;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | this.terrains[i].place(point);
|
|---|
| 38 | }
|
|---|
| 39 | });
|
|---|
| 40 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.