@adatechnology/game-weather

中文文档
0.3.15发布于 2026/11/08MITTypeScriptES Module构建来源已验证近 30 天下载 2579

Pure, seeded weather for games: states (clear to typhoon), climates with a Markov scheduler in game time, fronts from the west, lightning with thunder delay, ground wetness, gameplay effects, heat index and the day-night formula. Knows nothing about any g

原始使用文档
文档目录7 节
  1. Install
  2. Usage
  3. Registry: add, patch, remove
  4. Determinism
  5. API
  6. Português
  7. Bridges

@adatechnology/game-weather

Pure, seeded weather for games: states from clear to typhoon, climates that move between them in game time, lightning with the thunder delay, ground wetness, what the weather means for sight, hearing and footsteps, the heat index and the day-night formula, and the bridges that push it to the fluid film, the interactables, the vegetation, the effects world, the environment bus and the sound. No three.js and no game content; renderers read it. Depends on game-contracts and game-audio (the rain, wind and thunder recipes); works in the browser and in Node.

The numbers come from the teams' pages (each state lists its sources): the rain, fog and lightning of the VFX Workshop, the dry and wet fog and the day of the game, the wind and fog of the Art Scene, the rain rules of the Vale Cinzento gallery. Cyclone, typhoon and extreme heat have no team source and are physics presets (and off in the temperate climate).

  • The normal world comes first. Every climate starts clear; nothing is tied to an outbreak.
  • States (WEATHER_STATES): clear, overcast, light_rain, heavy_rain, storm, fog, windy, cyclone, typhoon, extreme_heat.
  • Climates (CLIMATES): temperate (mostly clear and overcast, no extremes, the default) and tropical (extremes rare and enabled). A seeded Markov chain in game time: each state lasts 2 to 6 game hours, a change blends over 10 game minutes and the front arrives from the west.
  • Lightning has its own seeded stream (the server sends the seed, every client sees the same strikes): the first strike 2 to 4 s after a storm begins, then every 3.5 to 6 s, the Workshop's double flash, thunder distance / 343 seconds later.
  • Wetness rises with the rain and is dry 180 s after it stops (faster in extreme heat).
  • Effects: visibility, sightScale (weather times the game's 1 - 0.4 × night), hearingScale, footstepScale, heatIndexC (NOAA Rothfusz), heatStress (0..1 on the 27, 32, 41 and 54 °C bands), lightningReveal, dryingScale, debrisPush.
  • Day and night: the game's formula (daylight), a 20-minute day by default (timeScale 72).

Install

pnpm add @adatechnology/game-weather

Browser without a bundler (the global is GameWeather):

<script src="https://unpkg.com/@adatechnology/game-weather/dist/index.global.js"></script>
<script>
  const weather = GameWeather.createWeather({ seed: 7 })
</script>

Usage

import { createWeather } from '@adatechnology/game-weather'

const weather = createWeather({ seed: 7, climate: 'tropical' }) // starts clear, 8:00, a 20-minute day
weather.on('strike', (strike) => flash(strike.bearing))
weather.on('thunder', (strike) => playThunder(strike.distance))
weather.on('transition', ({ from, to }) => log(`${from} -> ${to}`))

// every frame, with real seconds
weather.advance(dt)
const sample = weather.sample()
sample.rain // mm/h, blended between states
sample.windX // m/s
sample.nightFactor // 0 day, 1 night
sample.groundWetness // 0..1
sample.effects.hearingScale // multiply a listener's radius by this
sample.front // { direction: [1, 0], progress } — the curtain moves along +x

weather.force('storm', 10) // blend to a storm over 10 real seconds
weather.timeline(72) // what a fresh world does in 72 game hours (plain JSON, a golden)

Registry: add, patch, remove

import { createWeather, WEATHER_STATES } from '@adatechnology/game-weather'

const weather = createWeather({
  states: [{ ...WEATHER_STATES[2]!, id: 'drizzle', sources: ['my game'], rain: 0.5, drops: 300 }],
  patch: { states: { storm: { rain: 90, lightning: { interval: [2, 4] } } }, climates: { temperate: { dwellHours: [1, 3] } } },
  remove: { states: ['fog'] }, // nothing schedules it any more
})
weather.registry.patchState('heavy_rain', { visibility: 100 }) // later, with the same verbs

Determinism

The schedule and the lightning draw from separate seeded streams (streamSeed(seed, 'schedule' | 'lightning')), so strikes never move the schedule and the result does not depend on the size of the steps advance is called with. createTimeline steps one game minute at a time and is checked against goldens on Node 22 and 24.

API

Everything is exported from the package root; see src/*.ts for the doc comments. Units: metres, seconds, mm/h, degrees Celsius; wind in m/s.

Português

Clima puro e determinístico por semente: estados de céu limpo a tufão, climas que passam de um estado a outro em tempo de jogo, relâmpago com o atraso do trovão, solo molhado, o que o tempo muda para visão, audição e passos, índice de calor e a fórmula de dia e noite do jogo. Sem three.js, sem som, sem conteúdo de jogo: quem desenha e quem toca lê daqui. Cada estado traz sources com a origem dos números (Oficina de VFX, jogo, Cena de Arte, Galeria do Vale Cinzento); ciclone, tufão e calor intenso não têm fonte de time e são predefinições físicas, desligadas no clima temperate.

  • O mundo normal vem primeiro: todo clima começa em clear.
  • O estado dura de 2 a 6 horas de jogo, a mudança se mistura em 10 minutos de jogo e a frente chega de oeste.
  • Relâmpago com fluxo próprio de semente (o servidor manda a semente e todos veem o mesmo clarão); trovão distância / 343 s depois.
  • O solo seca 180 s depois que a chuva para; effects entrega sightScale, hearingScale, footstepScale, índice de calor e estresse de calor.
  • Catálogo por registro: acrescente, troque (patch) ou tire estados e climas sem mexer no núcleo.

Bridges

createWeatherBridges(targets, options) pushes one weather to whatever you give it. Every target is optional and an interface of its own, so the weather imports none of the packages it drives:

import { createWeatherBridges } from '@adatechnology/game-weather'

const bridges = createWeatherBridges({
  film: room.film, // game-fluids-three FilmBridge: setWeather({ rain, drying }), wash()
  interactables: world, // game-interactables: water.setRain(mm/h), setWind(x, z)
  vegetation, // game-vegetation: setWind({ direction, strength, gust })
  vfx: vfxWorld, // game-vfx: setWind([x, 0, z])
  environment: host.environment, // the EnvironmentBus
  audio: host.audio, // rain and wind loops, thunder
})
bridges.bind(weather)
// every frame, after weather.advance(dt)
bridges.update(dt)

The rules are numbers you can change (filmRainFullAt, washFrom, washBelow, washEvery, windFull): light rain (2.5 mm/h) stops the drying and does not wash; heavy rain (15 mm/h) and stronger washes the fresh stain (less than half dry) once a second; extreme heat dries twice as fast; the vegetation's strength is min(1, speed / 20).

Sound: WEATHER_BANK holds rain_loop and wind_loop (art scene), rain_hiss_game (game) and thunder. createWeatherSound sets the rain loop from 0.035 (light rain) to 0.06 (heavy), the wind loop at 0.05 in the breeze and in proportion to the speed, and plays the thunder at the strike's bearing when it arrives (distance / 343 s after the flash). options.sound changes the style (art_scene or game), the levels and the listener.

The picture is @adatechnology/game-weather-three. The bench takes it as visual (a WeatherVisualFactory: layers(locale) before the room lends anything, then create({ host, locale, weather }) returning { update(dt), setLayer(id, on), dispose() }); with a visual the bench leaves the scene fog to it: createWeatherTestModule({ visual: createWeatherVisual({ vfx: room.vfx }) }).

版本与发布记录

@adatechnology/game-weather 共发布 29 个版本,首次发布于 2026/10/24;过去 12 个月发布了 29 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.15latest2026/11/08今天
0.3.142026/11/07今天
0.3.132026/11/07今天
0.3.122026/11/07今天
0.3.112026/11/07今天
0.3.102026/11/07今天

关于 @adatechnology/game-weather 的常见问题

@adatechnology/game-weather 是什么?

Pure, seeded weather for games: states (clear to typhoon), climates with a Markov scheduler in game time, fronts from the west, lightning with thunder delay, ground wetness, gameplay effects, heat index and the day-night formula. Knows nothing about any g

如何安装 @adatechnology/game-weather?

在项目目录运行 npm install @adatechnology/game-weather,或使用 pnpm add / yarn add / bun add。

@adatechnology/game-weather 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adatechnology/game-weather 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@adatechnology/game-weather 可以商用吗?

@adatechnology/game-weather 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adatechnology/game-weather 的下载量有多少?

根据 npm 官方下载统计,@adatechnology/game-weather 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,579 次,日均约 86 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adatechnology/game-weather 还在维护吗?

最新版本 0.3.15 发布于 2026/11/08(今天);至今共发布 29 个版本,其中过去 12 个月发布了 29 个;首次发布于 2026/10/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。