| 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 | |
| 33 | export const GroundType = Object.freeze({ |
| 34 | grass: 1, |
| 35 | wood: 2, |
| 36 | water: 3, |
| 37 | deepWater: 4, |
| 38 | dirt: 5 |
| 39 | }); |
| 40 | |
| 41 | export const BlockType = Object.freeze({ |
| 42 | stoneWall: 1, |
| 43 | torch: 2, |
| 44 | /** @deprecated Legacy authored block; migrated into chunk `spawners[]` on load. */ |
| 45 | spawner: 3, |
| 46 | bank: 4, |
| 47 | churchAltar: 5, |
| 48 | cauldron: 6, |
| 49 | boulder: 7, |
| 50 | furnace: 8, |
| 51 | anvil: 9, |
| 52 | woodworkingBench: 10, |
| 53 | craftingBench: 11, |
| 54 | pineTree: 12, |
| 55 | marketplace: 13, |
| 56 | table: 14, |
| 57 | flower: 15, |
| 58 | cottonPlant: 16, |
| 59 | spinningWheel: 17, |
| 60 | loom: 18, |
| 61 | tailorBench: 19, |
| 62 | bountyOffice: 20, |
| 63 | barber: 23, |
| 64 | /** Folklore herbs — state is herbId (`sage`, `mint`, …); sprites in `assets/herbs/`. */ |
| 65 | herbPlant: 24, |
| 66 | birchTree: 21, |
| 67 | oakTree: 22, |
| 68 | ebonyTree: 25, |
| 69 | lignumTree: 26, |
| 70 | heartwoodTree: 27, |
| 71 | elderTree: 28, |
| 72 | leatherworkingTable: 29, |
| 73 | doorway: 30, |
| 74 | campfire: 31, |
| 75 | oven: 32, |
| 76 | fishingSpot: 33, |
| 77 | jeweleringStation: 34, |
| 78 | flaxPlant: 35, |
| 79 | silkCocoon: 36, |
| 80 | fence: 37, |
| 81 | stoneWallThin: 38, |
| 82 | smoothStoneWall: 39, |
| 83 | smoothStoneWallThin: 40 |
| 84 | }); |
| 85 | |
| 86 | export const GROUND_DEFINITIONS = Object.freeze({ |
| 87 | [GroundType.grass]: Object.freeze({ |
| 88 | id: GroundType.grass, |
| 89 | key: "grass", |
| 90 | displayName: "Grass", |
| 91 | passable: true, |
| 92 | wades: false, |
| 93 | water: false, |
| 94 | frames: 1, |
| 95 | framesPerRow: 1, |
| 96 | animationSpeed: 0, |
| 97 | /** Outdoor grounds should expose summer/fall/winter (legacy `grass` ok for summer). */ |
| 98 | outdoor: true, |
| 99 | /** Soft-terrain edge blend when the player enables Soft terrain. */ |
| 100 | blendable: true |
| 101 | }), |
| 102 | [GroundType.wood]: Object.freeze({ |
| 103 | id: GroundType.wood, |
| 104 | key: "wood", |
| 105 | displayName: "Wood", |
| 106 | passable: true, |
| 107 | wades: false, |
| 108 | water: false, |
| 109 | frames: 1, |
| 110 | framesPerRow: 1, |
| 111 | animationSpeed: 0, |
| 112 | outdoor: false |
| 113 | }), |
| 114 | [GroundType.water]: Object.freeze({ |
| 115 | id: GroundType.water, |
| 116 | key: "water", |
| 117 | displayName: "Water", |
| 118 | passable: true, |
| 119 | wades: true, |
| 120 | water: true, |
| 121 | frames: 4, |
| 122 | framesPerRow: 4, |
| 123 | animationSpeed: 0.12, |
| 124 | outdoor: true |
| 125 | }), |
| 126 | [GroundType.deepWater]: Object.freeze({ |
| 127 | id: GroundType.deepWater, |
| 128 | key: "deep-water", |
| 129 | displayName: "Deep water", |
| 130 | passable: false, |
| 131 | wades: false, |
| 132 | water: true, |
| 133 | frames: 4, |
| 134 | framesPerRow: 4, |
| 135 | animationSpeed: 0.12, |
| 136 | outdoor: true |
| 137 | }), |
| 138 | [GroundType.dirt]: Object.freeze({ |
| 139 | id: GroundType.dirt, |
| 140 | key: "dirt", |
| 141 | displayName: "Dirt", |
| 142 | passable: true, |
| 143 | wades: false, |
| 144 | water: false, |
| 145 | frames: 1, |
| 146 | framesPerRow: 1, |
| 147 | animationSpeed: 0, |
| 148 | outdoor: true, |
| 149 | blendable: true |
| 150 | }) |
| 151 | }); |
| 152 | |
| 153 | function treeBlockDef (id, woodTier) |
| 154 | { |
| 155 | const name = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier; |
| 156 | return Object.freeze({ |
| 157 | id, |
| 158 | key: `${woodTier}-tree`, |
| 159 | displayName: `${name} tree`, |
| 160 | passable: false, |
| 161 | /** Canopy: light passes but each tree tile adds +1 falloff distance. */ |
| 162 | blocksLight: "partial", |
| 163 | lightRangeTiles: 0, |
| 164 | frames: 1, |
| 165 | framesPerRow: 1, |
| 166 | animationSpeed: 0, |
| 167 | outdoor: true, |
| 168 | gatherable: true, |
| 169 | woodTier |
| 170 | }); |
| 171 | } |
| 172 | |
| 173 | export const BLOCK_DEFINITIONS = Object.freeze({ |
| 174 | [BlockType.stoneWall]: Object.freeze({ |
| 175 | id: BlockType.stoneWall, |
| 176 | key: "thick-stone-wall", |
| 177 | displayName: "Thick stone wall", |
| 178 | passable: false, |
| 179 | lightRangeTiles: 0, |
| 180 | frames: 1, |
| 181 | framesPerRow: 1, |
| 182 | animationSpeed: 0, |
| 183 | /** Building walls count as indoor (no seasonal art required). */ |
| 184 | outdoor: false, |
| 185 | /** Autotile via named cardinal states (`thick-stone-wall`, `thick-stone-wall-esw`, …). */ |
| 186 | neighborConnect: true, |
| 187 | neighborConnectNamed: true |
| 188 | }), |
| 189 | [BlockType.stoneWallThin]: Object.freeze({ |
| 190 | id: BlockType.stoneWallThin, |
| 191 | key: "thin-stone-wall", |
| 192 | displayName: "Thin stone wall", |
| 193 | passable: false, |
| 194 | lightRangeTiles: 0, |
| 195 | frames: 1, |
| 196 | framesPerRow: 1, |
| 197 | animationSpeed: 0, |
| 198 | outdoor: false, |
| 199 | neighborConnect: true, |
| 200 | neighborConnectNamed: true |
| 201 | }), |
| 202 | [BlockType.smoothStoneWall]: Object.freeze({ |
| 203 | id: BlockType.smoothStoneWall, |
| 204 | key: "thick-smooth-stone-wall", |
| 205 | displayName: "Thick smooth stone wall", |
| 206 | passable: false, |
| 207 | lightRangeTiles: 0, |
| 208 | frames: 1, |
| 209 | framesPerRow: 1, |
| 210 | animationSpeed: 0, |
| 211 | outdoor: false, |
| 212 | neighborConnect: true, |
| 213 | neighborConnectNamed: true |
| 214 | }), |
| 215 | [BlockType.smoothStoneWallThin]: Object.freeze({ |
| 216 | id: BlockType.smoothStoneWallThin, |
| 217 | key: "thin-smooth-stone-wall", |
| 218 | displayName: "Thin smooth stone wall", |
| 219 | passable: false, |
| 220 | lightRangeTiles: 0, |
| 221 | frames: 1, |
| 222 | framesPerRow: 1, |
| 223 | animationSpeed: 0, |
| 224 | outdoor: false, |
| 225 | neighborConnect: true, |
| 226 | neighborConnectNamed: true |
| 227 | }), |
| 228 | [BlockType.torch]: Object.freeze({ |
| 229 | id: BlockType.torch, |
| 230 | key: "torch", |
| 231 | displayName: "Torch", |
| 232 | passable: true, |
| 233 | lightRangeTiles: 8, |
| 234 | frames: 1, |
| 235 | framesPerRow: 1, |
| 236 | animationSpeed: 0, |
| 237 | outdoor: false |
| 238 | }), |
| 239 | [BlockType.spawner]: Object.freeze({ |
| 240 | id: BlockType.spawner, |
| 241 | key: "spawner", |
| 242 | displayName: "Spawner", |
| 243 | passable: true, |
| 244 | lightRangeTiles: 0, |
| 245 | frames: 1, |
| 246 | framesPerRow: 1, |
| 247 | animationSpeed: 0, |
| 248 | /** Not shown in the placeable block palette; use the Spawners tab. */ |
| 249 | editorHidden: true, |
| 250 | outdoor: false |
| 251 | }), |
| 252 | [BlockType.bank]: Object.freeze({ |
| 253 | id: BlockType.bank, |
| 254 | key: "bank", |
| 255 | displayName: "Bank", |
| 256 | passable: false, |
| 257 | lightRangeTiles: 0, |
| 258 | frames: 1, |
| 259 | framesPerRow: 1, |
| 260 | animationSpeed: 0, |
| 261 | outdoor: false |
| 262 | }), |
| 263 | [BlockType.churchAltar]: Object.freeze({ |
| 264 | id: BlockType.churchAltar, |
| 265 | key: "church-altar", |
| 266 | displayName: "Church altar", |
| 267 | passable: false, |
| 268 | lightRangeTiles: 0, |
| 269 | frames: 1, |
| 270 | framesPerRow: 1, |
| 271 | animationSpeed: 0, |
| 272 | outdoor: false |
| 273 | }), |
| 274 | [BlockType.cauldron]: Object.freeze({ |
| 275 | id: BlockType.cauldron, |
| 276 | key: "cauldron", |
| 277 | displayName: "Cauldron", |
| 278 | passable: false, |
| 279 | blocksLight: false, |
| 280 | lightRangeTiles: 0, |
| 281 | frames: 1, |
| 282 | framesPerRow: 1, |
| 283 | animationSpeed: 0, |
| 284 | outdoor: false |
| 285 | }), |
| 286 | [BlockType.boulder]: Object.freeze({ |
| 287 | id: BlockType.boulder, |
| 288 | key: "boulder", |
| 289 | displayName: "Boulder", |
| 290 | passable: false, |
| 291 | blocksLight: false, |
| 292 | lightRangeTiles: 0, |
| 293 | frames: 1, |
| 294 | framesPerRow: 1, |
| 295 | animationSpeed: 0, |
| 296 | /** Ore states are synthesized in the sprite catalog (tinted boulder-ore). */ |
| 297 | gatherable: true, |
| 298 | outdoor: true |
| 299 | }), |
| 300 | [BlockType.furnace]: Object.freeze({ |
| 301 | id: BlockType.furnace, |
| 302 | key: "furnace", |
| 303 | displayName: "Furnace", |
| 304 | passable: false, |
| 305 | blocksLight: false, |
| 306 | lightRangeTiles: 4, |
| 307 | frames: 1, |
| 308 | framesPerRow: 1, |
| 309 | animationSpeed: 0, |
| 310 | craftingStationId: "furnace", |
| 311 | outdoor: false |
| 312 | }), |
| 313 | [BlockType.campfire]: Object.freeze({ |
| 314 | id: BlockType.campfire, |
| 315 | key: "campfire", |
| 316 | displayName: "Campfire", |
| 317 | passable: true, |
| 318 | blocksLight: false, |
| 319 | blocksRangedAttacks: false, |
| 320 | lightRangeTiles: 4, |
| 321 | frames: 1, |
| 322 | framesPerRow: 1, |
| 323 | animationSpeed: 0, |
| 324 | craftingStationId: "fireplace", |
| 325 | /** State is wood tier id; tinted like logs. Bloom companion is fire only. */ |
| 326 | tintFromTier: true, |
| 327 | /** Lit/expires at runtime — per-tile draw, not chunk atlas (see chunk-delta). */ |
| 328 | perTileBlock: true, |
| 329 | outdoor: true |
| 330 | }), |
| 331 | [BlockType.oven]: Object.freeze({ |
| 332 | id: BlockType.oven, |
| 333 | key: "oven", |
| 334 | displayName: "Oven", |
| 335 | passable: false, |
| 336 | blocksLight: false, |
| 337 | lightRangeTiles: 2, |
| 338 | frames: 1, |
| 339 | framesPerRow: 1, |
| 340 | animationSpeed: 0, |
| 341 | craftingStationId: "oven", |
| 342 | outdoor: false |
| 343 | }), |
| 344 | [BlockType.fishingSpot]: Object.freeze({ |
| 345 | id: BlockType.fishingSpot, |
| 346 | key: "fishing-spot", |
| 347 | displayName: "Fishing spot", |
| 348 | passable: true, |
| 349 | blocksLight: false, |
| 350 | blocksRangedAttacks: false, |
| 351 | lightRangeTiles: 0, |
| 352 | /** Ripple / splash strip (temp art; 3 frames). */ |
| 353 | frames: 3, |
| 354 | framesPerRow: 3, |
| 355 | animationSpeed: 0.18, |
| 356 | outdoor: true, |
| 357 | /** Requires water / deepWater under the tile (editor + server). */ |
| 358 | requiresWater: true |
| 359 | }), |
| 360 | [BlockType.anvil]: Object.freeze({ |
| 361 | id: BlockType.anvil, |
| 362 | key: "anvil", |
| 363 | displayName: "Anvil", |
| 364 | passable: false, |
| 365 | blocksLight: false, |
| 366 | lightRangeTiles: 0, |
| 367 | frames: 1, |
| 368 | framesPerRow: 1, |
| 369 | animationSpeed: 0, |
| 370 | craftingStationId: "anvil", |
| 371 | outdoor: false |
| 372 | }), |
| 373 | [BlockType.jeweleringStation]: Object.freeze({ |
| 374 | id: BlockType.jeweleringStation, |
| 375 | key: "jewelering-station", |
| 376 | displayName: "Jewelering station", |
| 377 | passable: false, |
| 378 | blocksLight: false, |
| 379 | lightRangeTiles: 0, |
| 380 | frames: 1, |
| 381 | framesPerRow: 1, |
| 382 | animationSpeed: 0, |
| 383 | craftingStationId: "jewelering-station", |
| 384 | outdoor: false |
| 385 | }), |
| 386 | [BlockType.woodworkingBench]: Object.freeze({ |
| 387 | id: BlockType.woodworkingBench, |
| 388 | key: "woodworking-bench", |
| 389 | displayName: "Woodworking bench", |
| 390 | passable: false, |
| 391 | blocksLight: false, |
| 392 | lightRangeTiles: 0, |
| 393 | frames: 1, |
| 394 | framesPerRow: 1, |
| 395 | animationSpeed: 0, |
| 396 | craftingStationId: "woodworking-bench", |
| 397 | outdoor: false |
| 398 | }), |
| 399 | [BlockType.craftingBench]: Object.freeze({ |
| 400 | id: BlockType.craftingBench, |
| 401 | key: "crafting-bench", |
| 402 | displayName: "Crafting bench", |
| 403 | passable: false, |
| 404 | blocksLight: false, |
| 405 | lightRangeTiles: 0, |
| 406 | frames: 1, |
| 407 | framesPerRow: 1, |
| 408 | animationSpeed: 0, |
| 409 | craftingStationId: "crafting-bench", |
| 410 | outdoor: false |
| 411 | }), |
| 412 | [BlockType.pineTree]: treeBlockDef(BlockType.pineTree, WoodTier.pine), |
| 413 | [BlockType.birchTree]: treeBlockDef(BlockType.birchTree, WoodTier.birch), |
| 414 | [BlockType.oakTree]: treeBlockDef(BlockType.oakTree, WoodTier.oak), |
| 415 | [BlockType.ebonyTree]: treeBlockDef(BlockType.ebonyTree, WoodTier.ebony), |
| 416 | [BlockType.lignumTree]: treeBlockDef(BlockType.lignumTree, WoodTier.lignum), |
| 417 | [BlockType.heartwoodTree]: treeBlockDef(BlockType.heartwoodTree, WoodTier.heartwood), |
| 418 | [BlockType.elderTree]: treeBlockDef(BlockType.elderTree, WoodTier.elder), |
| 419 | [BlockType.marketplace]: Object.freeze({ |
| 420 | id: BlockType.marketplace, |
| 421 | key: "marketplace", |
| 422 | displayName: "Central Exchange counter", |
| 423 | passable: false, |
| 424 | /** Furniture: blocks movement but not baked/dynamic light rays. */ |
| 425 | blocksLight: false, |
| 426 | lightRangeTiles: 0, |
| 427 | frames: 1, |
| 428 | framesPerRow: 1, |
| 429 | animationSpeed: 0, |
| 430 | outdoor: false, |
| 431 | /** Autotile via N/E/S/W bitmask states `"0"`…`"15"`. */ |
| 432 | neighborConnect: true |
| 433 | }), |
| 434 | [BlockType.table]: Object.freeze({ |
| 435 | id: BlockType.table, |
| 436 | key: "table", |
| 437 | displayName: "Table", |
| 438 | passable: false, |
| 439 | blocksLight: false, |
| 440 | blocksRangedAttacks: false, |
| 441 | lightRangeTiles: 0, |
| 442 | frames: 1, |
| 443 | framesPerRow: 1, |
| 444 | animationSpeed: 0, |
| 445 | outdoor: false, |
| 446 | /** Magenta base `0`–`15` (strip-union line tables); catalog expands `${wood}-${mask}`. |
| 447 | * Filled-rectangle corners can later add diagonal-aware sprites without replacing these. */ |
| 448 | neighborConnect: true, |
| 449 | neighborConnectByMaterial: true, |
| 450 | defaultNeighborMaterial: WoodTier.pine |
| 451 | }), |
| 452 | [BlockType.fence]: Object.freeze({ |
| 453 | id: BlockType.fence, |
| 454 | key: "fence", |
| 455 | displayName: "Fence", |
| 456 | passable: false, |
| 457 | blocksLight: false, |
| 458 | blocksRangedAttacks: false, |
| 459 | lightRangeTiles: 0, |
| 460 | frames: 1, |
| 461 | framesPerRow: 1, |
| 462 | animationSpeed: 0, |
| 463 | outdoor: true, |
| 464 | /** Magenta base `0`–`15`; catalog expands `${wood}-${mask}` like tables. */ |
| 465 | neighborConnect: true, |
| 466 | neighborConnectByMaterial: true, |
| 467 | defaultNeighborMaterial: WoodTier.pine |
| 468 | }), |
| 469 | [BlockType.flower]: Object.freeze({ |
| 470 | id: BlockType.flower, |
| 471 | key: "flower", |
| 472 | displayName: "Flower", |
| 473 | passable: true, |
| 474 | blocksLight: false, |
| 475 | lightRangeTiles: 0, |
| 476 | frames: 1, |
| 477 | framesPerRow: 1, |
| 478 | animationSpeed: 0, |
| 479 | outdoor: true, |
| 480 | gatherable: true, |
| 481 | plantGather: Object.freeze({ kind: "flower", requiresClippers: false, skillId: "herbalism" }) |
| 482 | }), |
| 483 | [BlockType.cottonPlant]: Object.freeze({ |
| 484 | id: BlockType.cottonPlant, |
| 485 | key: "cotton-plant", |
| 486 | displayName: "Cotton plant", |
| 487 | passable: true, |
| 488 | blocksLight: false, |
| 489 | lightRangeTiles: 0, |
| 490 | frames: 1, |
| 491 | framesPerRow: 1, |
| 492 | animationSpeed: 0, |
| 493 | outdoor: true, |
| 494 | gatherable: true, |
| 495 | plantGather: Object.freeze({ kind: "cotton", requiresClippers: false, skillId: "herbalism" }) |
| 496 | }), |
| 497 | [BlockType.flaxPlant]: Object.freeze({ |
| 498 | id: BlockType.flaxPlant, |
| 499 | key: "flax-plant", |
| 500 | displayName: "Flax plant", |
| 501 | passable: true, |
| 502 | blocksLight: false, |
| 503 | lightRangeTiles: 0, |
| 504 | frames: 1, |
| 505 | framesPerRow: 1, |
| 506 | animationSpeed: 0, |
| 507 | outdoor: true, |
| 508 | gatherable: true, |
| 509 | plantGather: Object.freeze({ |
| 510 | kind: "flax", |
| 511 | requiresClippers: true, |
| 512 | /** Linen-rank clippers or better (steel↔linen). */ |
| 513 | minClothTier: "linen", |
| 514 | skillId: "herbalism" |
| 515 | }) |
| 516 | }), |
| 517 | [BlockType.silkCocoon]: Object.freeze({ |
| 518 | id: BlockType.silkCocoon, |
| 519 | key: "silk-cocoon", |
| 520 | displayName: "Silk cocoon", |
| 521 | passable: true, |
| 522 | blocksLight: false, |
| 523 | lightRangeTiles: 0, |
| 524 | frames: 1, |
| 525 | framesPerRow: 1, |
| 526 | animationSpeed: 0, |
| 527 | outdoor: true, |
| 528 | gatherable: true, |
| 529 | plantGather: Object.freeze({ |
| 530 | kind: "silk", |
| 531 | requiresClippers: true, |
| 532 | /** Silk-rank clippers or better (adamantium↔silk). */ |
| 533 | minClothTier: "silk", |
| 534 | skillId: "herbalism" |
| 535 | }) |
| 536 | }), |
| 537 | [BlockType.spinningWheel]: Object.freeze({ |
| 538 | id: BlockType.spinningWheel, |
| 539 | key: "spinning-wheel", |
| 540 | displayName: "Spinning wheel", |
| 541 | passable: false, |
| 542 | blocksLight: false, |
| 543 | lightRangeTiles: 0, |
| 544 | frames: 1, |
| 545 | framesPerRow: 1, |
| 546 | animationSpeed: 0, |
| 547 | craftingStationId: "spinning-wheel", |
| 548 | outdoor: false |
| 549 | }), |
| 550 | [BlockType.loom]: Object.freeze({ |
| 551 | id: BlockType.loom, |
| 552 | key: "loom", |
| 553 | displayName: "Loom", |
| 554 | passable: false, |
| 555 | blocksLight: false, |
| 556 | lightRangeTiles: 0, |
| 557 | frames: 1, |
| 558 | framesPerRow: 1, |
| 559 | animationSpeed: 0, |
| 560 | craftingStationId: "loom", |
| 561 | outdoor: false |
| 562 | }), |
| 563 | [BlockType.tailorBench]: Object.freeze({ |
| 564 | id: BlockType.tailorBench, |
| 565 | key: "tailor-bench", |
| 566 | displayName: "Tailor's bench", |
| 567 | passable: false, |
| 568 | blocksLight: false, |
| 569 | lightRangeTiles: 0, |
| 570 | frames: 1, |
| 571 | framesPerRow: 1, |
| 572 | animationSpeed: 0, |
| 573 | craftingStationId: "tailor-bench", |
| 574 | outdoor: false |
| 575 | }), |
| 576 | [BlockType.leatherworkingTable]: Object.freeze({ |
| 577 | id: BlockType.leatherworkingTable, |
| 578 | key: "leatherworking-table", |
| 579 | displayName: "Leatherworking table", |
| 580 | passable: false, |
| 581 | blocksLight: false, |
| 582 | lightRangeTiles: 0, |
| 583 | frames: 1, |
| 584 | framesPerRow: 1, |
| 585 | animationSpeed: 0, |
| 586 | craftingStationId: "leatherworking-station", |
| 587 | outdoor: false |
| 588 | }), |
| 589 | [BlockType.bountyOffice]: Object.freeze({ |
| 590 | id: BlockType.bountyOffice, |
| 591 | key: "bounty-office", |
| 592 | displayName: "Bounty office", |
| 593 | passable: false, |
| 594 | blocksLight: false, |
| 595 | lightRangeTiles: 0, |
| 596 | frames: 1, |
| 597 | framesPerRow: 1, |
| 598 | animationSpeed: 0, |
| 599 | outdoor: false |
| 600 | }), |
| 601 | [BlockType.barber]: Object.freeze({ |
| 602 | id: BlockType.barber, |
| 603 | key: "barber", |
| 604 | displayName: "Barber", |
| 605 | passable: false, |
| 606 | blocksLight: false, |
| 607 | lightRangeTiles: 0, |
| 608 | frames: 1, |
| 609 | framesPerRow: 1, |
| 610 | animationSpeed: 0, |
| 611 | outdoor: false |
| 612 | }), |
| 613 | [BlockType.doorway]: Object.freeze({ |
| 614 | id: BlockType.doorway, |
| 615 | key: "doorway", |
| 616 | displayName: "Doorway", |
| 617 | passable: true, |
| 618 | blocksLight: false, |
| 619 | lightRangeTiles: 0, |
| 620 | frames: 1, |
| 621 | framesPerRow: 1, |
| 622 | animationSpeed: 0, |
| 623 | outdoor: false, |
| 624 | /** Visual variants under `blocks/doorway/`. */ |
| 625 | doorway: true, |
| 626 | defaultState: "door" |
| 627 | }), |
| 628 | [BlockType.herbPlant]: Object.freeze({ |
| 629 | id: BlockType.herbPlant, |
| 630 | key: "herb", |
| 631 | displayName: "Herb", |
| 632 | passable: true, |
| 633 | blocksLight: false, |
| 634 | lightRangeTiles: 0, |
| 635 | frames: 1, |
| 636 | framesPerRow: 1, |
| 637 | animationSpeed: 0, |
| 638 | outdoor: true, |
| 639 | gatherable: true, |
| 640 | /** Sprites live under `assets/herbs/` (shared with items), not `blocks/herb/`. */ |
| 641 | assetFolder: "herbs", |
| 642 | plantGather: Object.freeze({ |
| 643 | kind: "herb", |
| 644 | requiresClippers: true, |
| 645 | skillId: "herbalism" |
| 646 | }) |
| 647 | }) |
| 648 | }); |
| 649 | |
| 650 | /** Grounds and real blocks the editor may place (excludes legacy/hidden entries). */ |
| 651 | export function listPlaceableGrounds () |
| 652 | { |
| 653 | return Object.values(GROUND_DEFINITIONS); |
| 654 | } |
| 655 | |
| 656 | export function listPlaceableBlocks () |
| 657 | { |
| 658 | return Object.values(BLOCK_DEFINITIONS).filter((def) => !def.editorHidden); |
| 659 | } |
| 660 | |
| 661 | /** Display name for an ore boulder state (`copper-ore` → "Copper ore boulder"). */ |
| 662 | export function oreBoulderDisplayName (state) |
| 663 | { |
| 664 | const material = materialFromOreBoulderState(state); |
| 665 | if (!material) |
| 666 | { return null; } |
| 667 | const label = MATERIAL_DISPLAY_NAME[material] ?? material; |
| 668 | if (material === "coal") |
| 669 | { return "Coal boulder"; } |
| 670 | if (isGemstoneMaterial(material)) |
| 671 | { return `${label} boulder`; } |
| 672 | return `${label} ore boulder`; |
| 673 | } |
| 674 | |
| 675 | /** |
| 676 | * Hover / UI label for a gatherable resource node. |
| 677 | * Ore boulders and chopable trees; fishing / herbs can extend this later. |
| 678 | * Returns null when the block is not an active resource node. |
| 679 | */ |
| 680 | export function resourceNodeDisplayName (block) |
| 681 | { |
| 682 | if (!block) |
| 683 | { return null; } |
| 684 | if (block.typeId === BlockType.fishingSpot && block.state !== "exhausted") |
| 685 | { return "Fishing spot"; } |
| 686 | if (block.typeId === BlockType.boulder) |
| 687 | { return oreBoulderDisplayName(block.state); } |
| 688 | if (isChopableTreeBlock(block)) |
| 689 | { |
| 690 | const def = BLOCK_DEFINITIONS[block.typeId]; |
| 691 | return def?.displayName ?? "Tree"; |
| 692 | } |
| 693 | if (block.typeId === BlockType.flower) |
| 694 | { |
| 695 | const color = FLOWER_COLOR_DISPLAY[block.state]; |
| 696 | return color ? `${color} flower` : "Flower"; |
| 697 | } |
| 698 | if (block.typeId === BlockType.cottonPlant) |
| 699 | { return "Cotton plant"; } |
| 700 | if (block.typeId === BlockType.flaxPlant) |
| 701 | { return "Flax plant"; } |
| 702 | if (block.typeId === BlockType.silkCocoon) |
| 703 | { return "Silk cocoon"; } |
| 704 | if (block.typeId === BlockType.herbPlant) |
| 705 | { |
| 706 | const herb = herbDefinition(block.state); |
| 707 | return herb ? herb.displayName : "Herb"; |
| 708 | } |
| 709 | return null; |
| 710 | } |
| 711 | |
| 712 | /** Wood tier for a tree block type, or null. */ |
| 713 | export function woodTierForTreeBlock (typeId) |
| 714 | { |
| 715 | const def = BLOCK_DEFINITIONS[typeId]; |
| 716 | return def?.woodTier ?? null; |
| 717 | } |
| 718 | |
| 719 | /** True when this block is a standing (non-stump) gatherable tree. */ |
| 720 | export function isChopableTreeBlock (block) |
| 721 | { |
| 722 | if (!block || woodTierForTreeBlock(block.typeId) == null) |
| 723 | { return false; } |
| 724 | return !isSeasonalStumpState(block.state); |
| 725 | } |
| 726 | |
| 727 | /** Plant gather config from block def, or null. */ |
| 728 | export function plantGatherForBlock (block) |
| 729 | { |
| 730 | if (!block) |
| 731 | { return null; } |
| 732 | const def = BLOCK_DEFINITIONS[block.typeId]; |
| 733 | return def?.plantGather ?? null; |
| 734 | } |
| 735 | |
| 736 | export function isPickablePlantBlock (block) |
| 737 | { |
| 738 | return !!plantGatherForBlock(block); |
| 739 | } |
| 740 | |
| 741 | /** |
| 742 | * Blocks baked into chunk atlas rows. Gather nodes and pickables stay as per-tile |
| 743 | * sprites so chunkDelta can hide or restyle them without rebaking the row. |
| 744 | */ |
| 745 | export function isChunkAtlasBakedBlock (block) |
| 746 | { |
| 747 | if (!block) |
| 748 | { return false; } |
| 749 | const entry = normalizeBlock(block); |
| 750 | if (!entry) |
| 751 | { return false; } |
| 752 | const def = BLOCK_DEFINITIONS[entry.typeId]; |
| 753 | if (!def || def.editorHidden) |
| 754 | { return false; } |
| 755 | if (def.perTileBlock) |
| 756 | { return false; } |
| 757 | if (resourceNodeDisplayName(entry)) |
| 758 | { return false; } |
| 759 | if (isPickablePlantBlock(entry)) |
| 760 | { return false; } |
| 761 | return true; |
| 762 | } |
| 763 | |
| 764 | /** |
| 765 | * Editor palette cards: one entry per placeable, with boulder expanded into |
| 766 | * plain rock + each ore/coal variant (shared BlockType, distinct state). |
| 767 | * Flowers are a single card; colour is rolled when painting (and on respawn). |
| 768 | */ |
| 769 | export function listPlaceableBlockPaletteEntries (catalog = null) |
| 770 | { |
| 771 | const entries = []; |
| 772 | for (const def of listPlaceableBlocks()) |
| 773 | { |
| 774 | if (def.id === BlockType.boulder) |
| 775 | { |
| 776 | entries.push({ |
| 777 | typeId: def.id, |
| 778 | state: "boulder", |
| 779 | key: def.key, |
| 780 | displayName: "Boulder", |
| 781 | spriteName: spriteImageName("block", def.key, "boulder") |
| 782 | }); |
| 783 | for (const material of ORE_BEARING_MATERIALS) |
| 784 | { |
| 785 | const state = oreBoulderState(material); |
| 786 | entries.push({ |
| 787 | typeId: def.id, |
| 788 | state, |
| 789 | key: def.key, |
| 790 | displayName: oreBoulderDisplayName(state) ?? state, |
| 791 | spriteName: spriteImageName("block", def.key, state) |
| 792 | }); |
| 793 | } |
| 794 | continue; |
| 795 | } |
| 796 | if (def.id === BlockType.flower) |
| 797 | { |
| 798 | const state = flowerBlockState(FLOWER_COLOR_ORDER[0]); |
| 799 | entries.push({ |
| 800 | typeId: def.id, |
| 801 | state, |
| 802 | key: def.key, |
| 803 | displayName: "Flower", |
| 804 | spriteName: spriteImageName("block", def.key, state) |
| 805 | }); |
| 806 | continue; |
| 807 | } |
| 808 | if (def.id === BlockType.herbPlant) |
| 809 | { |
| 810 | for (const herbId of HERB_ORDER) |
| 811 | { |
| 812 | const herb = HERB_DEFINITIONS[herbId]; |
| 813 | entries.push({ |
| 814 | typeId: def.id, |
| 815 | state: herbId, |
| 816 | key: def.key, |
| 817 | displayName: herb?.displayName ?? herbId, |
| 818 | spriteName: spriteImageName("block", def.key, herbId) |
| 819 | }); |
| 820 | } |
| 821 | continue; |
| 822 | } |
| 823 | if (def.neighborConnect) |
| 824 | { |
| 825 | if (definitionUsesMaterialNeighborConnect(def)) |
| 826 | { |
| 827 | for (const material of WOOD_TIER_ORDER) |
| 828 | { |
| 829 | const state = composeNeighborConnectState(def, material, 0); |
| 830 | const label = MATERIAL_DISPLAY_NAME[material] ?? material; |
| 831 | const noun = String(def.displayName ?? def.key).toLowerCase(); |
| 832 | entries.push({ |
| 833 | typeId: def.id, |
| 834 | state, |
| 835 | key: def.key, |
| 836 | displayName: `${label} ${noun}`, |
| 837 | spriteName: spriteImageName("block", def.key, state) |
| 838 | }); |
| 839 | } |
| 840 | continue; |
| 841 | } |
| 842 | entries.push({ |
| 843 | typeId: def.id, |
| 844 | state: definitionUsesNamedNeighborConnect(def) ? def.key : "0", |
| 845 | key: def.key, |
| 846 | displayName: def.displayName, |
| 847 | spriteName: spriteImageName( |
| 848 | "block", |
| 849 | def.key, |
| 850 | definitionUsesNamedNeighborConnect(def) ? def.key : "0" |
| 851 | ) |
| 852 | }); |
| 853 | continue; |
| 854 | } |
| 855 | const state = defaultStateForType(catalog, "block", def.key); |
| 856 | entries.push({ |
| 857 | typeId: def.id, |
| 858 | state, |
| 859 | key: def.key, |
| 860 | displayName: def.displayName, |
| 861 | spriteName: state |
| 862 | ? spriteImageName("block", def.key, state) |
| 863 | : spriteImageName("block", def.key, def.key) |
| 864 | }); |
| 865 | } |
| 866 | return entries; |
| 867 | } |
| 868 | |
| 869 | export function groundDefinition (typeId) |
| 870 | { |
| 871 | return GROUND_DEFINITIONS[typeId] ?? null; |
| 872 | } |
| 873 | |
| 874 | export function blockDefinition (typeId) |
| 875 | { |
| 876 | return BLOCK_DEFINITIONS[typeId] ?? null; |
| 877 | } |
| 878 | |
| 879 | export function isGroundPassable (typeId) |
| 880 | { |
| 881 | const def = groundDefinition(typeId); |
| 882 | if (!def) |
| 883 | { return true; } |
| 884 | return def.passable !== false; |
| 885 | } |
| 886 | |
| 887 | export function isWaterGround (typeId) |
| 888 | { |
| 889 | return !!groundDefinition(typeId)?.water; |
| 890 | } |
| 891 | |
| 892 | export function isWadeGround (typeId) |
| 893 | { |
| 894 | return !!groundDefinition(typeId)?.wades; |
| 895 | } |
| 896 | |
| 897 | /** |
| 898 | * Liquid water for foam / wade (shallow water freezes in winter and is solid ice). |
| 899 | * Deep water stays liquid year-round. |
| 900 | */ |
| 901 | export function isLiquidWaterGround (typeId, seasonId = null) |
| 902 | { |
| 903 | if (!isWaterGround(typeId)) |
| 904 | { return false; } |
| 905 | if (typeId === GroundType.water && seasonId === SeasonId.winter) |
| 906 | { return false; } |
| 907 | return true; |
| 908 | } |
| 909 | |
| 910 | /** Wade clip/foam only on liquid shallow water (not winter ice). */ |
| 911 | export function isWadeGroundInSeason (typeId, seasonId = null) |
| 912 | { |
| 913 | return isWadeGround(typeId) && isLiquidWaterGround(typeId, seasonId); |
| 914 | } |
| 915 | |
| 916 | export function isBlockPassable (typeId) |
| 917 | { |
| 918 | if (typeId == null) |
| 919 | { return true; } |
| 920 | |
| 921 | const def = blockDefinition(typeId); |
| 922 | return def ? def.passable : false; |
| 923 | } |
| 924 | |
| 925 | /** |
| 926 | * Whether a block stops ranged attack / spell line of sight. |
| 927 | * `blocksRangedAttacks`: explicit override; `craftingStationId` defaults to clear; |
| 928 | * otherwise impassable blocks block and passable blocks do not. |
| 929 | */ |
| 930 | export function blockBlocksRangedAttacks (typeId) |
| 931 | { |
| 932 | if (typeId == null) |
| 933 | { return false; } |
| 934 | const def = blockDefinition(typeId); |
| 935 | if (!def) |
| 936 | { return true; } |
| 937 | if (def.blocksRangedAttacks === false) |
| 938 | { return false; } |
| 939 | if (def.blocksRangedAttacks === true) |
| 940 | { return true; } |
| 941 | if (def.craftingStationId) |
| 942 | { return false; } |
| 943 | return def.passable === false; |
| 944 | } |
| 945 | |
| 946 | /** |
| 947 | * Light ray occlusion for a block tile. |
| 948 | * - `clear` (0): no effect (default for passable; set `blocksLight: false` for furniture) |
| 949 | * - `partial` (1): ray continues; each such tile adds +1 to falloff distance (2× cost) |
| 950 | * - `solid` (2): ray stops (default for impassable; set `blocksLight: true` explicitly) |
| 951 | */ |
| 952 | export const LightOcclusion = Object.freeze({ |
| 953 | clear: 0, |
| 954 | partial: 1, |
| 955 | solid: 2 |
| 956 | }); |
| 957 | |
| 958 | /** |
| 959 | * Resolve light occlusion for a block tile (type + visual state). |
| 960 | * Stumps are a runtime/editor state override: no occlusion even on tree types. |
| 961 | */ |
| 962 | export function blockLightOcclusionForBlock (block) |
| 963 | { |
| 964 | if (!block) |
| 965 | { return LightOcclusion.clear; } |
| 966 | if (isSeasonalStumpState(block.state)) |
| 967 | { return LightOcclusion.clear; } |
| 968 | return blockLightOcclusion(block.typeId ?? null); |
| 969 | } |
| 970 | |
| 971 | /** |
| 972 | * Resolve light occlusion for a block type id. |
| 973 | * `blocksLight`: `true` | `false` | `"partial"`; omitted → solid iff `!passable`. |
| 974 | * `blocksRangedAttacks`: `true` | `false`; omitted → false when `craftingStationId` is set, |
| 975 | * otherwise blocks iff `!passable` (furniture/stations may block movement but not magic/ranged). |
| 976 | * Prefer {@link blockLightOcclusionForBlock} when block state is known. |
| 977 | */ |
| 978 | export function blockLightOcclusion (typeId) |
| 979 | { |
| 980 | if (typeId == null) |
| 981 | { return LightOcclusion.clear; } |
| 982 | const def = blockDefinition(typeId); |
| 983 | if (!def) |
| 984 | { return LightOcclusion.solid; } |
| 985 | if (def.blocksLight === "partial") |
| 986 | { return LightOcclusion.partial; } |
| 987 | if (def.blocksLight === false) |
| 988 | { return LightOcclusion.clear; } |
| 989 | if (def.blocksLight === true) |
| 990 | { return LightOcclusion.solid; } |
| 991 | return def.passable === false ? LightOcclusion.solid : LightOcclusion.clear; |
| 992 | } |
| 993 | |
| 994 | /** True when a block fully stops light rays (not partial canopy). */ |
| 995 | export function isBlockOccludingLight (typeId) |
| 996 | { |
| 997 | return blockLightOcclusion(typeId) === LightOcclusion.solid; |
| 998 | } |
| 999 | |
| 1000 | export function blockLightRange (typeId) |
| 1001 | { |
| 1002 | const def = blockDefinition(typeId); |
| 1003 | return def ? def.lightRangeTiles : 0; |
| 1004 | } |
| 1005 | |
| 1006 | export function normalizeGround (value, fallbackTypeId = GroundType.grass) |
| 1007 | { |
| 1008 | if (typeof value === "number") |
| 1009 | { return { typeId: value, state: null }; } |
| 1010 | if (value && Number.isInteger(value.typeId)) |
| 1011 | { return { typeId: value.typeId, state: value.state ?? null }; } |
| 1012 | return { typeId: fallbackTypeId, state: null }; |
| 1013 | } |
| 1014 | |
| 1015 | export function normalizeBlock (value) |
| 1016 | { |
| 1017 | if (!value || !Number.isInteger(value.typeId)) |
| 1018 | { return null; } |
| 1019 | let state = value.state ?? null; |
| 1020 | const def = BLOCK_DEFINITIONS[value.typeId]; |
| 1021 | if (def && definitionUsesNamedNeighborConnect(def) && state != null) |
| 1022 | { |
| 1023 | const mask = parseNeighborConnectMaskFromState(state, def); |
| 1024 | state = composeNeighborConnectState(def, state, mask); |
| 1025 | } |
| 1026 | return { typeId: value.typeId, state, config: value.config ?? null }; |
| 1027 | } |
| 1028 | |
| 1029 | export function setBlockVisualState (block, state) |
| 1030 | { |
| 1031 | if (!block) |
| 1032 | { return null; } |
| 1033 | block.state = state ?? null; |
| 1034 | return block; |
| 1035 | } |