| 1 | import |
| 2 | { |
| 3 | ORE_BEARING_MATERIALS, |
| 4 | oreBoulderState, |
| 5 | materialFromOreBoulderState, |
| 6 | MATERIAL_DISPLAY_NAME, |
| 7 | isGemstoneMaterial, |
| 8 | WoodTier, |
| 9 | WOOD_TIER_ORDER |
| 10 | } from "./materialTiers.js"; |
| 11 | import |
| 12 | { |
| 13 | FLOWER_COLOR_ORDER, |
| 14 | FLOWER_COLOR_DISPLAY, |
| 15 | flowerBlockState |
| 16 | } from "./dyes.js"; |
| 17 | import |
| 18 | { |
| 19 | HERB_ORDER, |
| 20 | HERB_DEFINITIONS, |
| 21 | herbDefinition |
| 22 | } from "./herbs.js"; |
| 23 | import { spriteImageName, defaultStateForType } from "./tileSprites.js"; |
| 24 | import { isSeasonalStumpState, SeasonId } from "../world/season.js"; |
| 25 | import |
| 26 | { |
| 27 | composeNeighborConnectState, |
| 28 | definitionUsesMaterialNeighborConnect, |
| 29 | definitionUsesNamedNeighborConnect, |
| 30 | parseNeighborConnectMaskFromState |
| 31 | } from "../world/neighborConnect.js"; |
| 32 | import { |
| 33 | composeDoorState, |
| 34 | doorPaletteDisplayName, |
| 35 | isDoorPassageOpen |
| 36 | } from "../world/doors.js"; |
| 37 | |
| 38 | /** |
| 39 | * Average sprite colour for a ground or block, including per-state colours when |
| 40 | * states use different art. Populated from the sprite catalog at load. |
| 41 | * Pixels with alpha <= AVERAGE_COLOR_ALPHA_THRESHOLD (16) are ignored. |
| 42 | */ |
| 43 | export { |
| 44 | AVERAGE_COLOR_ALPHA_THRESHOLD, |
| 45 | installTileAverageColors, |
| 46 | groundAverageColor, |
| 47 | blockAverageColor |
| 48 | } from "../render/tileAverageColors.js"; |
| 49 | |
| 50 | export const GroundType = Object.freeze({ |
| 51 | grass: 1, |
| 52 | wood: 2, |
| 53 | water: 3, |
| 54 | deepWater: 4, |
| 55 | dirt: 5, |
| 56 | path: 6, |
| 57 | sand: 7, |
| 58 | lava: 8 |
| 59 | }); |
| 60 | |
| 61 | export const BlockType = Object.freeze({ |
| 62 | stoneWall: 1, |
| 63 | torch: 2, |
| 64 | /** @deprecated Legacy authored block; migrated into chunk `spawners[]` on load. */ |
| 65 | spawner: 3, |
| 66 | bank: 4, |
| 67 | churchAltar: 5, |
| 68 | cauldron: 6, |
| 69 | boulder: 7, |
| 70 | furnace: 8, |
| 71 | anvil: 9, |
| 72 | woodworkingBench: 10, |
| 73 | craftingBench: 11, |
| 74 | pineTree: 12, |
| 75 | marketplace: 13, |
| 76 | table: 14, |
| 77 | flower: 15, |
| 78 | cottonPlant: 16, |
| 79 | spinningWheel: 17, |
| 80 | loom: 18, |
| 81 | tailorBench: 19, |
| 82 | bountyOffice: 20, |
| 83 | barber: 23, |
| 84 | /** Folklore herbs — state is herbId (`sage`, `mint`, …); sprites in `assets/herbs/`. */ |
| 85 | herbPlant: 24, |
| 86 | birchTree: 21, |
| 87 | oakTree: 22, |
| 88 | ebonyTree: 25, |
| 89 | lignumTree: 26, |
| 90 | heartwoodTree: 27, |
| 91 | elderTree: 28, |
| 92 | leatherworkingTable: 29, |
| 93 | doorway: 30, |
| 94 | campfire: 31, |
| 95 | oven: 32, |
| 96 | fishingSpot: 33, |
| 97 | jeweleringStation: 34, |
| 98 | flaxPlant: 35, |
| 99 | silkCocoon: 36, |
| 100 | fence: 37, |
| 101 | stoneWallThin: 38, |
| 102 | /** Former thick smooth stone wall (39) removed — id left unused. */ |
| 103 | smoothStoneWallThin: 40, |
| 104 | brickWall: 41, |
| 105 | brickWallThin: 42, |
| 106 | woodWall: 43, |
| 107 | woodWallThin: 44, |
| 108 | cliff: 45, |
| 109 | cliffThin: 46, |
| 110 | /** Wooden door — state `${wood}-${n|s}-${open|closed}`; tall magenta-tint sprite. */ |
| 111 | door: 47, |
| 112 | /** Solid black tile: blocks movement, not light or ranged LoS. */ |
| 113 | void: 48 |
| 114 | }); |
| 115 | |
| 116 | export const GROUND_DEFINITIONS = Object.freeze({ |
| 117 | [GroundType.grass]: Object.freeze({ |
| 118 | id: GroundType.grass, |
| 119 | key: "grass", |
| 120 | displayName: "Grass", |
| 121 | passable: true, |
| 122 | wades: false, |
| 123 | water: false, |
| 124 | frames: 1, |
| 125 | framesPerRow: 1, |
| 126 | animationSpeed: 0, |
| 127 | /** Outdoor grounds should expose summer/fall/winter (legacy `grass` ok for summer). */ |
| 128 | outdoor: true, |
| 129 | /** Soft-terrain edge blend when the player enables Soft terrain. */ |
| 130 | blendable: true |
| 131 | }), |
| 132 | [GroundType.wood]: Object.freeze({ |
| 133 | id: GroundType.wood, |
| 134 | key: "wood", |
| 135 | displayName: "Wood", |
| 136 | passable: true, |
| 137 | wades: false, |
| 138 | water: false, |
| 139 | frames: 1, |
| 140 | framesPerRow: 1, |
| 141 | animationSpeed: 0, |
| 142 | outdoor: false |
| 143 | }), |
| 144 | [GroundType.water]: Object.freeze({ |
| 145 | id: GroundType.water, |
| 146 | key: "water", |
| 147 | displayName: "Water", |
| 148 | passable: true, |
| 149 | wades: true, |
| 150 | water: true, |
| 151 | frames: 1, |
| 152 | framesPerRow: 1, |
| 153 | animationSpeed: 0, |
| 154 | /** Per-tile procedural caustic shader; never atlas-baked. */ |
| 155 | proceduralWaves: true, |
| 156 | outdoor: true |
| 157 | }), |
| 158 | [GroundType.deepWater]: Object.freeze({ |
| 159 | id: GroundType.deepWater, |
| 160 | key: "deep-water", |
| 161 | displayName: "Deep water", |
| 162 | passable: false, |
| 163 | wades: false, |
| 164 | water: true, |
| 165 | frames: 1, |
| 166 | framesPerRow: 1, |
| 167 | animationSpeed: 0, |
| 168 | proceduralWaves: true, |
| 169 | outdoor: true |
| 170 | }), |
| 171 | [GroundType.dirt]: Object.freeze({ |
| 172 | id: GroundType.dirt, |
| 173 | key: "dirt", |
| 174 | displayName: "Dirt", |
| 175 | passable: true, |
| 176 | wades: false, |
| 177 | water: false, |
| 178 | frames: 1, |
| 179 | framesPerRow: 1, |
| 180 | animationSpeed: 0, |
| 181 | outdoor: true, |
| 182 | blendable: true |
| 183 | }), |
| 184 | [GroundType.path]: Object.freeze({ |
| 185 | id: GroundType.path, |
| 186 | key: "path", |
| 187 | displayName: "Path", |
| 188 | passable: true, |
| 189 | wades: false, |
| 190 | water: false, |
| 191 | frames: 1, |
| 192 | framesPerRow: 1, |
| 193 | animationSpeed: 0, |
| 194 | outdoor: true, |
| 195 | blendable: true, |
| 196 | /** Running here costs half stamina; A* prefers these slightly out of combat. */ |
| 197 | pathSurface: true |
| 198 | }), |
| 199 | [GroundType.sand]: Object.freeze({ |
| 200 | id: GroundType.sand, |
| 201 | key: "sand", |
| 202 | displayName: "Sand", |
| 203 | passable: true, |
| 204 | wades: false, |
| 205 | water: false, |
| 206 | frames: 1, |
| 207 | framesPerRow: 1, |
| 208 | animationSpeed: 0, |
| 209 | /** Same look year-round; wet edge is baked toward sand-wet beside liquid water. */ |
| 210 | outdoor: false, |
| 211 | blendable: true, |
| 212 | /** Client bakes a wet shoreline toward `sand-wet` (not a placeable state). */ |
| 213 | wetShore: true |
| 214 | }), |
| 215 | [GroundType.lava]: Object.freeze({ |
| 216 | id: GroundType.lava, |
| 217 | key: "lava", |
| 218 | displayName: "Lava", |
| 219 | passable: false, |
| 220 | wades: false, |
| 221 | water: false, |
| 222 | lava: true, |
| 223 | frames: 1, |
| 224 | framesPerRow: 1, |
| 225 | animationSpeed: 0, |
| 226 | /** Per-tile procedural heat shader; never atlas-baked. */ |
| 227 | proceduralWaves: true, |
| 228 | /** Half a torch (torch is 8). */ |
| 229 | lightRangeTiles: 4, |
| 230 | outdoor: true |
| 231 | }) |
| 232 | }); |
| 233 | |
| 234 | function treeBlockDef (id, woodTier) |
| 235 | { |
| 236 | const name = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier; |
| 237 | return Object.freeze({ |
| 238 | id, |
| 239 | key: `${woodTier}-tree`, |
| 240 | displayName: `${name} tree`, |
| 241 | passable: false, |
| 242 | /** Canopy: light passes but each tree tile adds +1 falloff distance. */ |
| 243 | blocksLight: "partial", |
| 244 | lightRangeTiles: 0, |
| 245 | frames: 1, |
| 246 | framesPerRow: 1, |
| 247 | animationSpeed: 0, |
| 248 | outdoor: true, |
| 249 | gatherable: true, |
| 250 | woodTier |
| 251 | }); |
| 252 | } |
| 253 | |
| 254 | export const BLOCK_DEFINITIONS = Object.freeze({ |
| 255 | [BlockType.stoneWall]: Object.freeze({ |
| 256 | id: BlockType.stoneWall, |
| 257 | key: "thick-stone-wall", |
| 258 | displayName: "Thick stone wall", |
| 259 | passable: false, |
| 260 | lightRangeTiles: 0, |
| 261 | frames: 1, |
| 262 | framesPerRow: 1, |
| 263 | animationSpeed: 0, |
| 264 | /** Building walls count as indoor (no seasonal art required). */ |
| 265 | outdoor: false, |
| 266 | /** Autotile via named cardinal states (`thick-stone-wall`, `thick-stone-wall-esw`, …). */ |
| 267 | neighborConnect: true, |
| 268 | neighborConnectNamed: true |
| 269 | }), |
| 270 | [BlockType.stoneWallThin]: Object.freeze({ |
| 271 | id: BlockType.stoneWallThin, |
| 272 | key: "thin-stone-wall", |
| 273 | displayName: "Thin stone wall", |
| 274 | passable: false, |
| 275 | lightRangeTiles: 0, |
| 276 | frames: 1, |
| 277 | framesPerRow: 1, |
| 278 | animationSpeed: 0, |
| 279 | outdoor: false, |
| 280 | neighborConnect: true, |
| 281 | neighborConnectNamed: true |
| 282 | }), |
| 283 | [BlockType.smoothStoneWallThin]: Object.freeze({ |
| 284 | id: BlockType.smoothStoneWallThin, |
| 285 | key: "thin-smooth-stone-wall", |
| 286 | displayName: "Thin smooth stone wall", |
| 287 | passable: false, |
| 288 | lightRangeTiles: 0, |
| 289 | frames: 1, |
| 290 | framesPerRow: 1, |
| 291 | animationSpeed: 0, |
| 292 | outdoor: false, |
| 293 | neighborConnect: true, |
| 294 | neighborConnectNamed: true |
| 295 | }), |
| 296 | [BlockType.brickWall]: Object.freeze({ |
| 297 | id: BlockType.brickWall, |
| 298 | key: "thick-brick-wall", |
| 299 | displayName: "Thick brick wall", |
| 300 | passable: false, |
| 301 | lightRangeTiles: 0, |
| 302 | frames: 1, |
| 303 | framesPerRow: 1, |
| 304 | animationSpeed: 0, |
| 305 | outdoor: false, |
| 306 | neighborConnect: true, |
| 307 | neighborConnectNamed: true |
| 308 | }), |
| 309 | [BlockType.brickWallThin]: Object.freeze({ |
| 310 | id: BlockType.brickWallThin, |
| 311 | key: "thin-brick-wall", |
| 312 | displayName: "Thin brick wall", |
| 313 | passable: false, |
| 314 | lightRangeTiles: 0, |
| 315 | frames: 1, |
| 316 | framesPerRow: 1, |
| 317 | animationSpeed: 0, |
| 318 | outdoor: false, |
| 319 | neighborConnect: true, |
| 320 | neighborConnectNamed: true |
| 321 | }), |
| 322 | [BlockType.woodWall]: Object.freeze({ |
| 323 | id: BlockType.woodWall, |
| 324 | key: "thick-wood-wall", |
| 325 | displayName: "Thick wood wall", |
| 326 | passable: false, |
| 327 | lightRangeTiles: 0, |
| 328 | frames: 1, |
| 329 | framesPerRow: 1, |
| 330 | animationSpeed: 0, |
| 331 | outdoor: false, |
| 332 | /** Magenta face-lit masks `0`–`15`; catalog expands `${wood}-${mask}`. */ |
| 333 | neighborConnect: true, |
| 334 | neighborConnectByMaterial: true, |
| 335 | defaultNeighborMaterial: WoodTier.pine |
| 336 | }), |
| 337 | [BlockType.woodWallThin]: Object.freeze({ |
| 338 | id: BlockType.woodWallThin, |
| 339 | key: "thin-wood-wall", |
| 340 | displayName: "Thin wood wall", |
| 341 | passable: false, |
| 342 | lightRangeTiles: 0, |
| 343 | frames: 1, |
| 344 | framesPerRow: 1, |
| 345 | animationSpeed: 0, |
| 346 | outdoor: false, |
| 347 | neighborConnect: true, |
| 348 | neighborConnectByMaterial: true, |
| 349 | defaultNeighborMaterial: WoodTier.pine |
| 350 | }), |
| 351 | [BlockType.cliff]: Object.freeze({ |
| 352 | id: BlockType.cliff, |
| 353 | key: "thick-cliff", |
| 354 | displayName: "Thick cliff", |
| 355 | passable: false, |
| 356 | lightRangeTiles: 0, |
| 357 | frames: 1, |
| 358 | framesPerRow: 1, |
| 359 | animationSpeed: 0, |
| 360 | outdoor: true, |
| 361 | neighborConnect: true, |
| 362 | neighborConnectNamed: true, |
| 363 | /** |
| 364 | * Magenta top faces are replaced at draw time by a dedicated per-tile |
| 365 | * cliff shader that samples the chunk ground atlas (1:1 UV, soft-terrain |
| 366 | * blend included). These blocks are not baked into chunk atlas rows. |
| 367 | */ |
| 368 | cliffGroundTop: true |
| 369 | }), |
| 370 | [BlockType.cliffThin]: Object.freeze({ |
| 371 | id: BlockType.cliffThin, |
| 372 | key: "thin-cliff", |
| 373 | displayName: "Thin cliff", |
| 374 | passable: false, |
| 375 | lightRangeTiles: 0, |
| 376 | frames: 1, |
| 377 | framesPerRow: 1, |
| 378 | animationSpeed: 0, |
| 379 | outdoor: true, |
| 380 | neighborConnect: true, |
| 381 | neighborConnectNamed: true, |
| 382 | /** @see {@link BlockType.cliff} `cliffGroundTop` */ |
| 383 | cliffGroundTop: true |
| 384 | }), |
| 385 | [BlockType.torch]: Object.freeze({ |
| 386 | id: BlockType.torch, |
| 387 | key: "torch", |
| 388 | displayName: "Torch", |
| 389 | passable: true, |
| 390 | lightRangeTiles: 8, |
| 391 | frames: 1, |
| 392 | framesPerRow: 1, |
| 393 | animationSpeed: 0, |
| 394 | outdoor: false |
| 395 | }), |
| 396 | [BlockType.spawner]: Object.freeze({ |
| 397 | id: BlockType.spawner, |
| 398 | key: "spawner", |
| 399 | displayName: "Spawner", |
| 400 | passable: true, |
| 401 | lightRangeTiles: 0, |
| 402 | frames: 1, |
| 403 | framesPerRow: 1, |
| 404 | animationSpeed: 0, |
| 405 | /** Not shown in the placeable block palette; use the Spawners tab. */ |
| 406 | editorHidden: true, |
| 407 | outdoor: false |
| 408 | }), |
| 409 | [BlockType.bank]: Object.freeze({ |
| 410 | id: BlockType.bank, |
| 411 | key: "bank", |
| 412 | displayName: "Bank", |
| 413 | passable: false, |
| 414 | lightRangeTiles: 0, |
| 415 | frames: 1, |
| 416 | framesPerRow: 1, |
| 417 | animationSpeed: 0, |
| 418 | outdoor: false |
| 419 | }), |
| 420 | [BlockType.churchAltar]: Object.freeze({ |
| 421 | id: BlockType.churchAltar, |
| 422 | key: "church-altar", |
| 423 | displayName: "Church altar", |
| 424 | passable: false, |
| 425 | lightRangeTiles: 0, |
| 426 | frames: 1, |
| 427 | framesPerRow: 1, |
| 428 | animationSpeed: 0, |
| 429 | outdoor: false |
| 430 | }), |
| 431 | [BlockType.cauldron]: Object.freeze({ |
| 432 | id: BlockType.cauldron, |
| 433 | key: "cauldron", |
| 434 | displayName: "Cauldron", |
| 435 | passable: false, |
| 436 | blocksLight: false, |
| 437 | lightRangeTiles: 0, |
| 438 | frames: 1, |
| 439 | framesPerRow: 1, |
| 440 | animationSpeed: 0, |
| 441 | outdoor: false |
| 442 | }), |
| 443 | [BlockType.boulder]: Object.freeze({ |
| 444 | id: BlockType.boulder, |
| 445 | key: "boulder", |
| 446 | displayName: "Boulder", |
| 447 | passable: false, |
| 448 | blocksLight: false, |
| 449 | lightRangeTiles: 0, |
| 450 | frames: 1, |
| 451 | framesPerRow: 1, |
| 452 | animationSpeed: 0, |
| 453 | /** Ore states are synthesized in the sprite catalog (tinted boulder-ore). */ |
| 454 | gatherable: true, |
| 455 | outdoor: true |
| 456 | }), |
| 457 | [BlockType.furnace]: Object.freeze({ |
| 458 | id: BlockType.furnace, |
| 459 | key: "furnace", |
| 460 | displayName: "Furnace", |
| 461 | passable: false, |
| 462 | blocksLight: false, |
| 463 | lightRangeTiles: 4, |
| 464 | frames: 1, |
| 465 | framesPerRow: 1, |
| 466 | animationSpeed: 0, |
| 467 | craftingStationId: "furnace", |
| 468 | outdoor: false |
| 469 | }), |
| 470 | [BlockType.campfire]: Object.freeze({ |
| 471 | id: BlockType.campfire, |
| 472 | key: "campfire", |
| 473 | displayName: "Campfire", |
| 474 | passable: true, |
| 475 | blocksLight: false, |
| 476 | blocksRangedAttacks: false, |
| 477 | lightRangeTiles: 4, |
| 478 | frames: 1, |
| 479 | framesPerRow: 1, |
| 480 | animationSpeed: 0, |
| 481 | craftingStationId: "fireplace", |
| 482 | /** State is wood tier id; tinted like logs. Bloom companion is fire only. */ |
| 483 | tintFromTier: true, |
| 484 | /** Lit/expires at runtime — per-tile draw, not chunk atlas (see chunk-delta). */ |
| 485 | perTileBlock: true, |
| 486 | outdoor: true |
| 487 | }), |
| 488 | [BlockType.oven]: Object.freeze({ |
| 489 | id: BlockType.oven, |
| 490 | key: "oven", |
| 491 | displayName: "Oven", |
| 492 | passable: false, |
| 493 | blocksLight: false, |
| 494 | lightRangeTiles: 2, |
| 495 | frames: 1, |
| 496 | framesPerRow: 1, |
| 497 | animationSpeed: 0, |
| 498 | craftingStationId: "oven", |
| 499 | outdoor: false |
| 500 | }), |
| 501 | [BlockType.fishingSpot]: Object.freeze({ |
| 502 | id: BlockType.fishingSpot, |
| 503 | key: "fishing-spot", |
| 504 | displayName: "Fishing spot", |
| 505 | passable: true, |
| 506 | blocksLight: false, |
| 507 | blocksRangedAttacks: false, |
| 508 | lightRangeTiles: 0, |
| 509 | /** Ripple / splash strip (temp art; 3 frames). */ |
| 510 | frames: 3, |
| 511 | framesPerRow: 3, |
| 512 | animationSpeed: 0.18, |
| 513 | outdoor: true, |
| 514 | /** Requires water / deepWater under the tile (editor + server). */ |
| 515 | requiresWater: true |
| 516 | }), |
| 517 | [BlockType.anvil]: Object.freeze({ |
| 518 | id: BlockType.anvil, |
| 519 | key: "anvil", |
| 520 | displayName: "Anvil", |
| 521 | passable: false, |
| 522 | blocksLight: false, |
| 523 | lightRangeTiles: 0, |
| 524 | frames: 1, |
| 525 | framesPerRow: 1, |
| 526 | animationSpeed: 0, |
| 527 | craftingStationId: "anvil", |
| 528 | outdoor: false |
| 529 | }), |
| 530 | [BlockType.jeweleringStation]: Object.freeze({ |
| 531 | id: BlockType.jeweleringStation, |
| 532 | key: "jewelering-station", |
| 533 | displayName: "Jewelering station", |
| 534 | passable: false, |
| 535 | blocksLight: false, |
| 536 | lightRangeTiles: 0, |
| 537 | frames: 1, |
| 538 | framesPerRow: 1, |
| 539 | animationSpeed: 0, |
| 540 | craftingStationId: "jewelering-station", |
| 541 | outdoor: false |
| 542 | }), |
| 543 | [BlockType.woodworkingBench]: Object.freeze({ |
| 544 | id: BlockType.woodworkingBench, |
| 545 | key: "woodworking-bench", |
| 546 | displayName: "Woodworking bench", |
| 547 | passable: false, |
| 548 | blocksLight: false, |
| 549 | lightRangeTiles: 0, |
| 550 | frames: 1, |
| 551 | framesPerRow: 1, |
| 552 | animationSpeed: 0, |
| 553 | craftingStationId: "woodworking-bench", |
| 554 | outdoor: false |
| 555 | }), |
| 556 | [BlockType.craftingBench]: Object.freeze({ |
| 557 | id: BlockType.craftingBench, |
| 558 | key: "crafting-bench", |
| 559 | displayName: "Crafting bench", |
| 560 | passable: false, |
| 561 | blocksLight: false, |
| 562 | lightRangeTiles: 0, |
| 563 | frames: 1, |
| 564 | framesPerRow: 1, |
| 565 | animationSpeed: 0, |
| 566 | craftingStationId: "crafting-bench", |
| 567 | outdoor: false |
| 568 | }), |
| 569 | [BlockType.pineTree]: treeBlockDef(BlockType.pineTree, WoodTier.pine), |
| 570 | [BlockType.birchTree]: treeBlockDef(BlockType.birchTree, WoodTier.birch), |
| 571 | [BlockType.oakTree]: treeBlockDef(BlockType.oakTree, WoodTier.oak), |
| 572 | [BlockType.ebonyTree]: treeBlockDef(BlockType.ebonyTree, WoodTier.ebony), |
| 573 | [BlockType.lignumTree]: treeBlockDef(BlockType.lignumTree, WoodTier.lignum), |
| 574 | [BlockType.heartwoodTree]: treeBlockDef(BlockType.heartwoodTree, WoodTier.heartwood), |
| 575 | [BlockType.elderTree]: treeBlockDef(BlockType.elderTree, WoodTier.elder), |
| 576 | [BlockType.marketplace]: Object.freeze({ |
| 577 | id: BlockType.marketplace, |
| 578 | key: "marketplace", |
| 579 | displayName: "Central Exchange counter", |
| 580 | passable: false, |
| 581 | /** Furniture: blocks movement but not baked/dynamic light rays. */ |
| 582 | blocksLight: false, |
| 583 | lightRangeTiles: 0, |
| 584 | frames: 1, |
| 585 | framesPerRow: 1, |
| 586 | animationSpeed: 0, |
| 587 | outdoor: false, |
| 588 | /** Autotile via N/E/S/W bitmask states `"0"`…`"15"`. */ |
| 589 | neighborConnect: true |
| 590 | }), |
| 591 | [BlockType.table]: Object.freeze({ |
| 592 | id: BlockType.table, |
| 593 | key: "table", |
| 594 | displayName: "Table", |
| 595 | passable: false, |
| 596 | blocksLight: false, |
| 597 | blocksRangedAttacks: false, |
| 598 | lightRangeTiles: 0, |
| 599 | frames: 1, |
| 600 | framesPerRow: 1, |
| 601 | animationSpeed: 0, |
| 602 | outdoor: false, |
| 603 | /** Magenta base `0`–`15` (strip-union line tables); catalog expands `${wood}-${mask}`. |
| 604 | * Filled-rectangle corners can later add diagonal-aware sprites without replacing these. */ |
| 605 | neighborConnect: true, |
| 606 | neighborConnectByMaterial: true, |
| 607 | defaultNeighborMaterial: WoodTier.pine |
| 608 | }), |
| 609 | [BlockType.fence]: Object.freeze({ |
| 610 | id: BlockType.fence, |
| 611 | key: "fence", |
| 612 | displayName: "Fence", |
| 613 | passable: false, |
| 614 | blocksLight: false, |
| 615 | blocksRangedAttacks: false, |
| 616 | lightRangeTiles: 0, |
| 617 | frames: 1, |
| 618 | framesPerRow: 1, |
| 619 | animationSpeed: 0, |
| 620 | outdoor: true, |
| 621 | /** Magenta base `0`–`15`; catalog expands `${wood}-${mask}` like tables. */ |
| 622 | neighborConnect: true, |
| 623 | neighborConnectByMaterial: true, |
| 624 | defaultNeighborMaterial: WoodTier.pine |
| 625 | }), |
| 626 | [BlockType.flower]: Object.freeze({ |
| 627 | id: BlockType.flower, |
| 628 | key: "flower", |
| 629 | displayName: "Flower", |
| 630 | passable: true, |
| 631 | blocksLight: false, |
| 632 | lightRangeTiles: 0, |
| 633 | frames: 1, |
| 634 | framesPerRow: 1, |
| 635 | animationSpeed: 0, |
| 636 | outdoor: true, |
| 637 | gatherable: true, |
| 638 | plantGather: Object.freeze({ kind: "flower", requiresClippers: false, skillId: "herbalism" }) |
| 639 | }), |
| 640 | [BlockType.cottonPlant]: Object.freeze({ |
| 641 | id: BlockType.cottonPlant, |
| 642 | key: "cotton-plant", |
| 643 | displayName: "Cotton plant", |
| 644 | passable: true, |
| 645 | blocksLight: false, |
| 646 | lightRangeTiles: 0, |
| 647 | frames: 1, |
| 648 | framesPerRow: 1, |
| 649 | animationSpeed: 0, |
| 650 | outdoor: true, |
| 651 | gatherable: true, |
| 652 | plantGather: Object.freeze({ kind: "cotton", requiresClippers: false, skillId: "herbalism" }) |
| 653 | }), |
| 654 | [BlockType.flaxPlant]: Object.freeze({ |
| 655 | id: BlockType.flaxPlant, |
| 656 | key: "flax-plant", |
| 657 | displayName: "Flax plant", |
| 658 | passable: true, |
| 659 | blocksLight: false, |
| 660 | lightRangeTiles: 0, |
| 661 | frames: 1, |
| 662 | framesPerRow: 1, |
| 663 | animationSpeed: 0, |
| 664 | outdoor: true, |
| 665 | gatherable: true, |
| 666 | plantGather: Object.freeze({ |
| 667 | kind: "flax", |
| 668 | requiresClippers: true, |
| 669 | /** Linen-rank clippers or better (steel↔linen). */ |
| 670 | minClothTier: "linen", |
| 671 | skillId: "herbalism" |
| 672 | }) |
| 673 | }), |
| 674 | [BlockType.silkCocoon]: Object.freeze({ |
| 675 | id: BlockType.silkCocoon, |
| 676 | key: "silk-cocoon", |
| 677 | displayName: "Silk cocoon", |
| 678 | passable: true, |
| 679 | blocksLight: false, |
| 680 | lightRangeTiles: 0, |
| 681 | frames: 1, |
| 682 | framesPerRow: 1, |
| 683 | animationSpeed: 0, |
| 684 | outdoor: true, |
| 685 | gatherable: true, |
| 686 | plantGather: Object.freeze({ |
| 687 | kind: "silk", |
| 688 | requiresClippers: true, |
| 689 | /** Silk-rank clippers or better (adamantium↔silk). */ |
| 690 | minClothTier: "silk", |
| 691 | skillId: "herbalism" |
| 692 | }) |
| 693 | }), |
| 694 | [BlockType.spinningWheel]: Object.freeze({ |
| 695 | id: BlockType.spinningWheel, |
| 696 | key: "spinning-wheel", |
| 697 | displayName: "Spinning wheel", |
| 698 | passable: false, |
| 699 | blocksLight: false, |
| 700 | lightRangeTiles: 0, |
| 701 | frames: 1, |
| 702 | framesPerRow: 1, |
| 703 | animationSpeed: 0, |
| 704 | craftingStationId: "spinning-wheel", |
| 705 | outdoor: false |
| 706 | }), |
| 707 | [BlockType.loom]: Object.freeze({ |
| 708 | id: BlockType.loom, |
| 709 | key: "loom", |
| 710 | displayName: "Loom", |
| 711 | passable: false, |
| 712 | blocksLight: false, |
| 713 | lightRangeTiles: 0, |
| 714 | frames: 1, |
| 715 | framesPerRow: 1, |
| 716 | animationSpeed: 0, |
| 717 | craftingStationId: "loom", |
| 718 | outdoor: false |
| 719 | }), |
| 720 | [BlockType.tailorBench]: Object.freeze({ |
| 721 | id: BlockType.tailorBench, |
| 722 | key: "tailor-bench", |
| 723 | displayName: "Tailor's bench", |
| 724 | passable: false, |
| 725 | blocksLight: false, |
| 726 | lightRangeTiles: 0, |
| 727 | frames: 1, |
| 728 | framesPerRow: 1, |
| 729 | animationSpeed: 0, |
| 730 | craftingStationId: "tailor-bench", |
| 731 | outdoor: false |
| 732 | }), |
| 733 | [BlockType.leatherworkingTable]: Object.freeze({ |
| 734 | id: BlockType.leatherworkingTable, |
| 735 | key: "leatherworking-table", |
| 736 | displayName: "Leatherworking table", |
| 737 | passable: false, |
| 738 | blocksLight: false, |
| 739 | lightRangeTiles: 0, |
| 740 | frames: 1, |
| 741 | framesPerRow: 1, |
| 742 | animationSpeed: 0, |
| 743 | craftingStationId: "leatherworking-station", |
| 744 | outdoor: false |
| 745 | }), |
| 746 | [BlockType.bountyOffice]: Object.freeze({ |
| 747 | id: BlockType.bountyOffice, |
| 748 | key: "bounty-office", |
| 749 | displayName: "Bounty office", |
| 750 | passable: false, |
| 751 | blocksLight: false, |
| 752 | lightRangeTiles: 0, |
| 753 | frames: 1, |
| 754 | framesPerRow: 1, |
| 755 | animationSpeed: 0, |
| 756 | outdoor: false |
| 757 | }), |
| 758 | [BlockType.barber]: Object.freeze({ |
| 759 | id: BlockType.barber, |
| 760 | key: "barber", |
| 761 | displayName: "Barber", |
| 762 | passable: false, |
| 763 | blocksLight: false, |
| 764 | lightRangeTiles: 0, |
| 765 | frames: 1, |
| 766 | framesPerRow: 1, |
| 767 | animationSpeed: 0, |
| 768 | outdoor: false |
| 769 | }), |
| 770 | [BlockType.doorway]: Object.freeze({ |
| 771 | id: BlockType.doorway, |
| 772 | key: "doorway", |
| 773 | displayName: "Doorway", |
| 774 | passable: true, |
| 775 | blocksLight: false, |
| 776 | lightRangeTiles: 0, |
| 777 | frames: 1, |
| 778 | framesPerRow: 1, |
| 779 | animationSpeed: 0, |
| 780 | outdoor: false, |
| 781 | /** Visual variants under `blocks/doorway/`. */ |
| 782 | doorway: true, |
| 783 | defaultState: "door" |
| 784 | }), |
| 785 | [BlockType.door]: Object.freeze({ |
| 786 | id: BlockType.door, |
| 787 | key: "door", |
| 788 | displayName: "Door", |
| 789 | /** Resting by default; passage when flipped from resting (see isDoorPassageOpen). */ |
| 790 | passable: false, |
| 791 | /** |
| 792 | * Light/LoS follow passage-open via {@link blockLightOcclusionForBlock} / |
| 793 | * {@link blockBlocksRangedAttacks} — not this static flag. |
| 794 | */ |
| 795 | blocksLight: true, |
| 796 | lightRangeTiles: 0, |
| 797 | frames: 1, |
| 798 | framesPerRow: 1, |
| 799 | animationSpeed: 0, |
| 800 | outdoor: false, |
| 801 | /** Wooden door — not a dimension portal (`doorway`). */ |
| 802 | door: true, |
| 803 | tintFromTier: true, |
| 804 | /** Tall tinted sprite; state flips at runtime — never chunk-atlas baked. */ |
| 805 | perTileBlock: true, |
| 806 | defaultState: "pine-s-closed" |
| 807 | }), |
| 808 | [BlockType.herbPlant]: Object.freeze({ |
| 809 | id: BlockType.herbPlant, |
| 810 | key: "herb", |
| 811 | displayName: "Herb", |
| 812 | passable: true, |
| 813 | blocksLight: false, |
| 814 | lightRangeTiles: 0, |
| 815 | frames: 1, |
| 816 | framesPerRow: 1, |
| 817 | animationSpeed: 0, |
| 818 | outdoor: true, |
| 819 | gatherable: true, |
| 820 | /** Sprites live under `assets/herbs/` (shared with items), not `blocks/herb/`. */ |
| 821 | assetFolder: "herbs", |
| 822 | plantGather: Object.freeze({ |
| 823 | kind: "herb", |
| 824 | requiresClippers: true, |
| 825 | skillId: "herbalism" |
| 826 | }) |
| 827 | }), |
| 828 | [BlockType.void]: Object.freeze({ |
| 829 | id: BlockType.void, |
| 830 | key: "void", |
| 831 | displayName: "Void", |
| 832 | passable: false, |
| 833 | /** Movement blocker only — light and ranged LoS pass through. */ |
| 834 | blocksLight: false, |
| 835 | blocksRangedAttacks: false, |
| 836 | lightRangeTiles: 0, |
| 837 | frames: 1, |
| 838 | framesPerRow: 1, |
| 839 | animationSpeed: 0, |
| 840 | outdoor: false |
| 841 | }) |
| 842 | }); |
| 843 | |
| 844 | /** Grounds and real blocks the editor may place (excludes legacy/hidden entries). */ |
| 845 | export function listPlaceableGrounds () |
| 846 | { |
| 847 | return Object.values(GROUND_DEFINITIONS); |
| 848 | } |
| 849 | |
| 850 | export function listPlaceableBlocks () |
| 851 | { |
| 852 | return Object.values(BLOCK_DEFINITIONS).filter((def) => !def.editorHidden); |
| 853 | } |
| 854 | |
| 855 | /** Display name for an ore boulder state (`copper-ore` → "Copper ore boulder"). */ |
| 856 | export function oreBoulderDisplayName (state) |
| 857 | { |
| 858 | const material = materialFromOreBoulderState(state); |
| 859 | if (!material) |
| 860 | { return null; } |
| 861 | const label = MATERIAL_DISPLAY_NAME[material] ?? material; |
| 862 | if (material === "coal") |
| 863 | { return "Coal boulder"; } |
| 864 | if (isGemstoneMaterial(material)) |
| 865 | { return `${label} boulder`; } |
| 866 | return `${label} ore boulder`; |
| 867 | } |
| 868 | |
| 869 | /** |
| 870 | * Hover / UI label for a gatherable resource node. |
| 871 | * Ore boulders and chopable trees; fishing / herbs can extend this later. |
| 872 | * Returns null when the block is not an active resource node. |
| 873 | */ |
| 874 | export function resourceNodeDisplayName (block) |
| 875 | { |
| 876 | if (!block) |
| 877 | { return null; } |
| 878 | if (block.typeId === BlockType.fishingSpot && block.state !== "exhausted") |
| 879 | { return "Fishing spot"; } |
| 880 | if (block.typeId === BlockType.boulder) |
| 881 | { return oreBoulderDisplayName(block.state); } |
| 882 | if (isChopableTreeBlock(block)) |
| 883 | { |
| 884 | const def = BLOCK_DEFINITIONS[block.typeId]; |
| 885 | return def?.displayName ?? "Tree"; |
| 886 | } |
| 887 | if (block.typeId === BlockType.flower) |
| 888 | { |
| 889 | const color = FLOWER_COLOR_DISPLAY[block.state]; |
| 890 | return color ? `${color} flower` : "Flower"; |
| 891 | } |
| 892 | if (block.typeId === BlockType.cottonPlant) |
| 893 | { return "Cotton plant"; } |
| 894 | if (block.typeId === BlockType.flaxPlant) |
| 895 | { return "Flax plant"; } |
| 896 | if (block.typeId === BlockType.silkCocoon) |
| 897 | { return "Silk cocoon"; } |
| 898 | if (block.typeId === BlockType.herbPlant) |
| 899 | { |
| 900 | const herb = herbDefinition(block.state); |
| 901 | return herb ? herb.displayName : "Herb"; |
| 902 | } |
| 903 | return null; |
| 904 | } |
| 905 | |
| 906 | /** Wood tier for a tree block type, or null. */ |
| 907 | export function woodTierForTreeBlock (typeId) |
| 908 | { |
| 909 | const def = BLOCK_DEFINITIONS[typeId]; |
| 910 | return def?.woodTier ?? null; |
| 911 | } |
| 912 | |
| 913 | /** True when this block is a standing (non-stump) gatherable tree. */ |
| 914 | export function isChopableTreeBlock (block) |
| 915 | { |
| 916 | if (!block || woodTierForTreeBlock(block.typeId) == null) |
| 917 | { return false; } |
| 918 | return !isSeasonalStumpState(block.state); |
| 919 | } |
| 920 | |
| 921 | /** Plant gather config from block def, or null. */ |
| 922 | export function plantGatherForBlock (block) |
| 923 | { |
| 924 | if (!block) |
| 925 | { return null; } |
| 926 | const def = BLOCK_DEFINITIONS[block.typeId]; |
| 927 | return def?.plantGather ?? null; |
| 928 | } |
| 929 | |
| 930 | export function isPickablePlantBlock (block) |
| 931 | { |
| 932 | return !!plantGatherForBlock(block); |
| 933 | } |
| 934 | |
| 935 | /** |
| 936 | * Blocks baked into chunk atlas rows. Gather nodes and pickables stay as per-tile |
| 937 | * sprites so chunkDelta can hide or restyle them without rebaking the row. |
| 938 | */ |
| 939 | export function isChunkAtlasBakedBlock (block) |
| 940 | { |
| 941 | if (!block) |
| 942 | { return false; } |
| 943 | const entry = normalizeBlock(block); |
| 944 | if (!entry) |
| 945 | { return false; } |
| 946 | const def = BLOCK_DEFINITIONS[entry.typeId]; |
| 947 | if (!def || def.editorHidden) |
| 948 | { return false; } |
| 949 | if (def.perTileBlock) |
| 950 | { return false; } |
| 951 | if (def.door) |
| 952 | { return false; } |
| 953 | /** Cliff tops need a dedicated per-tile ground-sample shader, not the row atlas. */ |
| 954 | if (def.cliffGroundTop) |
| 955 | { return false; } |
| 956 | if (resourceNodeDisplayName(entry)) |
| 957 | { return false; } |
| 958 | if (isPickablePlantBlock(entry)) |
| 959 | { return false; } |
| 960 | return true; |
| 961 | } |
| 962 | |
| 963 | /** |
| 964 | * Editor palette cards: one entry per placeable, with boulder expanded into |
| 965 | * plain rock + each ore/coal variant (shared BlockType, distinct state). |
| 966 | * Flowers are a single card; colour is rolled when painting (and on respawn). |
| 967 | */ |
| 968 | export function listPlaceableBlockPaletteEntries (catalog = null) |
| 969 | { |
| 970 | const entries = []; |
| 971 | for (const def of listPlaceableBlocks()) |
| 972 | { |
| 973 | if (def.id === BlockType.boulder) |
| 974 | { |
| 975 | entries.push({ |
| 976 | typeId: def.id, |
| 977 | state: "boulder", |
| 978 | key: def.key, |
| 979 | displayName: "Boulder", |
| 980 | spriteName: spriteImageName("block", def.key, "boulder") |
| 981 | }); |
| 982 | for (const material of ORE_BEARING_MATERIALS) |
| 983 | { |
| 984 | const state = oreBoulderState(material); |
| 985 | entries.push({ |
| 986 | typeId: def.id, |
| 987 | state, |
| 988 | key: def.key, |
| 989 | displayName: oreBoulderDisplayName(state) ?? state, |
| 990 | spriteName: spriteImageName("block", def.key, state) |
| 991 | }); |
| 992 | } |
| 993 | continue; |
| 994 | } |
| 995 | if (def.id === BlockType.flower) |
| 996 | { |
| 997 | const state = flowerBlockState(FLOWER_COLOR_ORDER[0]); |
| 998 | entries.push({ |
| 999 | typeId: def.id, |
| 1000 | state, |
| 1001 | key: def.key, |
| 1002 | displayName: "Flower", |
| 1003 | spriteName: spriteImageName("block", def.key, state) |
| 1004 | }); |
| 1005 | continue; |
| 1006 | } |
| 1007 | if (def.id === BlockType.herbPlant) |
| 1008 | { |
| 1009 | for (const herbId of HERB_ORDER) |
| 1010 | { |
| 1011 | const herb = HERB_DEFINITIONS[herbId]; |
| 1012 | entries.push({ |
| 1013 | typeId: def.id, |
| 1014 | state: herbId, |
| 1015 | key: def.key, |
| 1016 | displayName: herb?.displayName ?? herbId, |
| 1017 | spriteName: spriteImageName("block", def.key, herbId) |
| 1018 | }); |
| 1019 | } |
| 1020 | continue; |
| 1021 | } |
| 1022 | if (def.door) |
| 1023 | { |
| 1024 | for (const material of WOOD_TIER_ORDER) |
| 1025 | { |
| 1026 | const state = composeDoorState(material, "s", false); |
| 1027 | entries.push({ |
| 1028 | typeId: def.id, |
| 1029 | state, |
| 1030 | key: def.key, |
| 1031 | displayName: doorPaletteDisplayName(state).replace(/ \(S closed\)$/u, ""), |
| 1032 | spriteName: spriteImageName("block", def.key, state) |
| 1033 | }); |
| 1034 | } |
| 1035 | continue; |
| 1036 | } |
| 1037 | if (def.neighborConnect) |
| 1038 | { |
| 1039 | if (definitionUsesMaterialNeighborConnect(def)) |
| 1040 | { |
| 1041 | for (const material of WOOD_TIER_ORDER) |
| 1042 | { |
| 1043 | const state = composeNeighborConnectState(def, material, 0); |
| 1044 | const label = MATERIAL_DISPLAY_NAME[material] ?? material; |
| 1045 | const noun = String(def.displayName ?? def.key).toLowerCase(); |
| 1046 | entries.push({ |
| 1047 | typeId: def.id, |
| 1048 | state, |
| 1049 | key: def.key, |
| 1050 | displayName: `${label} ${noun}`, |
| 1051 | spriteName: spriteImageName("block", def.key, state) |
| 1052 | }); |
| 1053 | } |
| 1054 | continue; |
| 1055 | } |
| 1056 | entries.push({ |
| 1057 | typeId: def.id, |
| 1058 | state: definitionUsesNamedNeighborConnect(def) ? def.key : "0", |
| 1059 | key: def.key, |
| 1060 | displayName: def.displayName, |
| 1061 | spriteName: spriteImageName( |
| 1062 | "block", |
| 1063 | def.key, |
| 1064 | definitionUsesNamedNeighborConnect(def) ? def.key : "0" |
| 1065 | ) |
| 1066 | }); |
| 1067 | continue; |
| 1068 | } |
| 1069 | const state = defaultStateForType(catalog, "block", def.key); |
| 1070 | entries.push({ |
| 1071 | typeId: def.id, |
| 1072 | state, |
| 1073 | key: def.key, |
| 1074 | displayName: def.displayName, |
| 1075 | spriteName: state |
| 1076 | ? spriteImageName("block", def.key, state) |
| 1077 | : spriteImageName("block", def.key, def.key) |
| 1078 | }); |
| 1079 | } |
| 1080 | return entries; |
| 1081 | } |
| 1082 | |
| 1083 | export function groundDefinition (typeId) |
| 1084 | { |
| 1085 | return GROUND_DEFINITIONS[typeId] ?? null; |
| 1086 | } |
| 1087 | |
| 1088 | export function blockDefinition (typeId) |
| 1089 | { |
| 1090 | return BLOCK_DEFINITIONS[typeId] ?? null; |
| 1091 | } |
| 1092 | |
| 1093 | export function isGroundPassable (typeId) |
| 1094 | { |
| 1095 | const def = groundDefinition(typeId); |
| 1096 | if (!def) |
| 1097 | { return true; } |
| 1098 | return def.passable !== false; |
| 1099 | } |
| 1100 | |
| 1101 | export function isWaterGround (typeId) |
| 1102 | { |
| 1103 | return !!groundDefinition(typeId)?.water; |
| 1104 | } |
| 1105 | |
| 1106 | export function isLavaGround (typeId) |
| 1107 | { |
| 1108 | return !!groundDefinition(typeId)?.lava; |
| 1109 | } |
| 1110 | |
| 1111 | /** |
| 1112 | * Ground contribution to light-ray occlusion. |
| 1113 | * Water / lava stay optically clear — only movement is blocked (lava also emits light). |
| 1114 | */ |
| 1115 | export function groundLightOcclusion (typeId) |
| 1116 | { |
| 1117 | if (isWaterGround(typeId) || isLavaGround(typeId)) |
| 1118 | { return LightOcclusion.clear; } |
| 1119 | if (!isGroundPassable(typeId)) |
| 1120 | { return LightOcclusion.solid; } |
| 1121 | return LightOcclusion.clear; |
| 1122 | } |
| 1123 | |
| 1124 | /** Authored ground-emitted light range (lava, …). */ |
| 1125 | export function groundLightRange (typeId) |
| 1126 | { |
| 1127 | return groundDefinition(typeId)?.lightRangeTiles ?? 0; |
| 1128 | } |
| 1129 | |
| 1130 | export function isWadeGround (typeId) |
| 1131 | { |
| 1132 | return !!groundDefinition(typeId)?.wades; |
| 1133 | } |
| 1134 | |
| 1135 | /** |
| 1136 | * Liquid water for foam / wade (shallow water freezes in winter and is solid ice). |
| 1137 | * Deep water stays liquid year-round. |
| 1138 | */ |
| 1139 | export function isLiquidWaterGround (typeId, seasonId = null) |
| 1140 | { |
| 1141 | if (!isWaterGround(typeId)) |
| 1142 | { return false; } |
| 1143 | if (typeId === GroundType.water && seasonId === SeasonId.winter) |
| 1144 | { return false; } |
| 1145 | return true; |
| 1146 | } |
| 1147 | |
| 1148 | /** Wade clip/foam only on liquid shallow water (not winter ice). */ |
| 1149 | export function isWadeGroundInSeason (typeId, seasonId = null) |
| 1150 | { |
| 1151 | return isWadeGround(typeId) && isLiquidWaterGround(typeId, seasonId); |
| 1152 | } |
| 1153 | |
| 1154 | /** |
| 1155 | * Neighbor continues a fluid coastline (no foam / shore peek toward it). |
| 1156 | * Missing tiles (cross-chunk pending), same fluid, and non-blendable floors |
| 1157 | * (wood, …) count as continuous — the fluid “runs under” to the quad edge. |
| 1158 | * Blendable land, ice, and other distinct fluids still get a coast. |
| 1159 | * |
| 1160 | * @param {number | null | undefined} neighborTypeId |
| 1161 | * @param {(typeId: number) => boolean} isSameFluid |
| 1162 | */ |
| 1163 | export function fluidCoastContinues (neighborTypeId, isSameFluid) |
| 1164 | { |
| 1165 | if (neighborTypeId == null) |
| 1166 | { return true; } |
| 1167 | if (typeof isSameFluid === "function" && isSameFluid(neighborTypeId)) |
| 1168 | { return true; } |
| 1169 | if (isWaterGround(neighborTypeId) || isLavaGround(neighborTypeId)) |
| 1170 | { return false; } |
| 1171 | return !GROUND_DEFINITIONS[neighborTypeId]?.blendable; |
| 1172 | } |
| 1173 | |
| 1174 | export function isBlockPassable (typeId, state = null) |
| 1175 | { |
| 1176 | if (typeId == null) |
| 1177 | { return true; } |
| 1178 | |
| 1179 | const def = blockDefinition(typeId); |
| 1180 | if (!def) |
| 1181 | { return false; } |
| 1182 | if (def.door) |
| 1183 | { |
| 1184 | /** Without config, authored state is resting → not yet held for passage. */ |
| 1185 | return isDoorPassageOpen({ typeId, state, config: null }); |
| 1186 | } |
| 1187 | return def.passable; |
| 1188 | } |
| 1189 | |
| 1190 | /** |
| 1191 | * Whether a block stops ranged attack / spell line of sight. |
| 1192 | * `blocksRangedAttacks`: explicit override; `craftingStationId` defaults to clear; |
| 1193 | * otherwise impassable blocks block and passable blocks do not. |
| 1194 | */ |
| 1195 | export function blockBlocksRangedAttacks (typeId, state = null, block = null) |
| 1196 | { |
| 1197 | if (typeId == null) |
| 1198 | { return false; } |
| 1199 | const def = blockDefinition(typeId); |
| 1200 | if (!def) |
| 1201 | { return true; } |
| 1202 | if (def.door) |
| 1203 | { |
| 1204 | const entry = block && typeof block === "object" |
| 1205 | ? block |
| 1206 | : { typeId, state, config: null }; |
| 1207 | return !isDoorPassageOpen(entry); |
| 1208 | } |
| 1209 | if (def.blocksRangedAttacks === false) |
| 1210 | { return false; } |
| 1211 | if (def.blocksRangedAttacks === true) |
| 1212 | { return true; } |
| 1213 | if (def.craftingStationId) |
| 1214 | { return false; } |
| 1215 | return def.passable === false; |
| 1216 | } |
| 1217 | |
| 1218 | /** |
| 1219 | * Light ray occlusion for a block tile. |
| 1220 | * - `clear` (0): no effect (default for passable; set `blocksLight: false` for furniture) |
| 1221 | * - `partial` (1): ray continues; each such tile adds +1 to falloff distance (2× cost) |
| 1222 | * - `solid` (2): ray stops (default for impassable; set `blocksLight: true` explicitly) |
| 1223 | */ |
| 1224 | export const LightOcclusion = Object.freeze({ |
| 1225 | clear: 0, |
| 1226 | partial: 1, |
| 1227 | solid: 2 |
| 1228 | }); |
| 1229 | |
| 1230 | /** |
| 1231 | * Resolve light occlusion for a block tile (type + visual state). |
| 1232 | * Stumps are a runtime/editor state override: no occlusion even on tree types. |
| 1233 | */ |
| 1234 | export function blockLightOcclusionForBlock (block) |
| 1235 | { |
| 1236 | if (!block) |
| 1237 | { return LightOcclusion.clear; } |
| 1238 | if (isSeasonalStumpState(block.state)) |
| 1239 | { return LightOcclusion.clear; } |
| 1240 | const def = blockDefinition(block.typeId ?? null); |
| 1241 | if (def?.door) |
| 1242 | { return isDoorPassageOpen(block) ? LightOcclusion.clear : LightOcclusion.solid; } |
| 1243 | return blockLightOcclusion(block.typeId ?? null); |
| 1244 | } |
| 1245 | |
| 1246 | /** |
| 1247 | * Resolve light occlusion for a block type id. |
| 1248 | * `blocksLight`: `true` | `false` | `"partial"`; omitted → solid iff `!passable`. |
| 1249 | * `blocksRangedAttacks`: `true` | `false`; omitted → false when `craftingStationId` is set, |
| 1250 | * otherwise blocks iff `!passable` (furniture/stations may block movement but not magic/ranged). |
| 1251 | * Prefer {@link blockLightOcclusionForBlock} when block state is known. |
| 1252 | */ |
| 1253 | export function blockLightOcclusion (typeId) |
| 1254 | { |
| 1255 | if (typeId == null) |
| 1256 | { return LightOcclusion.clear; } |
| 1257 | const def = blockDefinition(typeId); |
| 1258 | if (!def) |
| 1259 | { return LightOcclusion.solid; } |
| 1260 | if (def.blocksLight === "partial") |
| 1261 | { return LightOcclusion.partial; } |
| 1262 | if (def.blocksLight === false) |
| 1263 | { return LightOcclusion.clear; } |
| 1264 | if (def.blocksLight === true) |
| 1265 | { return LightOcclusion.solid; } |
| 1266 | return def.passable === false ? LightOcclusion.solid : LightOcclusion.clear; |
| 1267 | } |
| 1268 | |
| 1269 | /** True when a block fully stops light rays (not partial canopy). */ |
| 1270 | export function isBlockOccludingLight (typeId) |
| 1271 | { |
| 1272 | return blockLightOcclusion(typeId) === LightOcclusion.solid; |
| 1273 | } |
| 1274 | |
| 1275 | export function blockLightRange (typeId) |
| 1276 | { |
| 1277 | const def = blockDefinition(typeId); |
| 1278 | return def ? def.lightRangeTiles : 0; |
| 1279 | } |
| 1280 | |
| 1281 | export function normalizeGround (value, fallbackTypeId = GroundType.grass) |
| 1282 | { |
| 1283 | if (typeof value === "number") |
| 1284 | { return { typeId: value, state: null }; } |
| 1285 | if (value && Number.isInteger(value.typeId)) |
| 1286 | { return { typeId: value.typeId, state: value.state ?? null }; } |
| 1287 | return { typeId: fallbackTypeId, state: null }; |
| 1288 | } |
| 1289 | |
| 1290 | export function normalizeBlock (value) |
| 1291 | { |
| 1292 | if (!value || !Number.isInteger(value.typeId)) |
| 1293 | { return null; } |
| 1294 | let state = value.state ?? null; |
| 1295 | const def = BLOCK_DEFINITIONS[value.typeId]; |
| 1296 | if (def && definitionUsesNamedNeighborConnect(def) && state != null) |
| 1297 | { |
| 1298 | const mask = parseNeighborConnectMaskFromState(state, def); |
| 1299 | state = composeNeighborConnectState(def, state, mask); |
| 1300 | } |
| 1301 | return { typeId: value.typeId, state, config: value.config ?? null }; |
| 1302 | } |
| 1303 | |
| 1304 | export function setBlockVisualState (block, state) |
| 1305 | { |
| 1306 | if (!block) |
| 1307 | { return null; } |
| 1308 | block.state = state ?? null; |
| 1309 | return block; |
| 1310 | } |