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