Skip to content

Commit

Permalink
Per scene FX disable
Browse files Browse the repository at this point in the history
Resolves #63
  • Loading branch information
dovrosenberg authored Aug 26, 2024
1 parent b34f531 commit 1e1e115
Show file tree
Hide file tree
Showing 17 changed files with 351 additions and 200 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## v1.14.0 - Per scene weather FX
#### Support for Simple Calendar v2.4.18
![](https://img.shields.io/badge/release%20date-August%2026%2C%202024-blue)
![GitHub release](https://img.shields.io/github/downloads-pre/dovrosenberg/foundry-simple-weather/v1.14.0/module.zip)

* Ability to have FX settings apply on a scene-by-scene basis: no more toggling manually when you change between indoor/outdoor scenes!
* Changed chat messages to be global instead of whispers to everyone.


## v1.13.5 - Updated German
#### Support for Simple Calendar v2.4.18
![](https://img.shields.io/badge/release%20date-June%2021%2C%202024-blue)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ The attachment to the calendar when the calendar is in compact mode is highly de
### Missing box (when attached to non-compact Simple Calendar)
Sometimes when you have another Simple Calendar side tab open and you try to switch to the weather tab, it will close the other tab but not show the weather. The workaround is just to hit the weather button again.

## Frequently asked questions

- **Why doesn't the weather update when I change the date in Simple Calendar**? The weather updates are tied to the main Foundry calendar (so they can be triggered by any module that modifies the date). Make sure that the Simple Calendar calendar you are using is updating the game world time (under "General Setings" for the calendar).

## Problems?

If you believe you found a bug or would like to post a feature request, head over to the module's [Github repo](https://github.com/dovrosenberg/foundry-simple-weather) and [open a new issue](https://github.com/dovrosenberg/foundry-simple-weather/issues/new/choose).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "simple-weather",
"title": "Foundry VTT Simple Weather",
"version": "1.13.5",
"version": "1.14.0",
"description": "Add dynamic weather to your FoundryVTT world (on top of Simple Calendar). Note: not affiliated with creators of Simple Calendar.",
"repository": {
"type": "git",
Expand Down
16 changes: 10 additions & 6 deletions src/applications/CustomMessageSettingsApplication.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { weatherDescriptions } from '@/weather/weatherMap';
import { moduleSettings, SettingKeys } from '@/settings/ModuleSettings';
import { moduleSettings, ModuleSettingKeys } from '@/settings/ModuleSettings';
import moduleJson from '@module';
import { localize } from '@/utils/game';

const NUM_CLIMATES = 3;
const NUM_HUMIDITY = 3;
const NUM_WEATHER = 37;

export class CustomMessageSettingsApplication extends FormApplication {
private _flattenedDescriptions = [] as {
climate: string,
Expand Down Expand Up @@ -59,7 +63,7 @@ export class CustomMessageSettingsApplication extends FormApplication {

public async getData(): Promise<any> {
// load any current values
const currentText = moduleSettings.get(SettingKeys.customChatMessages);
const currentText = moduleSettings.get(ModuleSettingKeys.customChatMessages);

for (let i=0; i<this._flattenedDescriptions.length; i++) {
this._flattenedDescriptions[i].currentText = currentText[this._flattenedDescriptions[i].climateId][this._flattenedDescriptions[i].humidityId][this._flattenedDescriptions[i].descriptionId];
Expand All @@ -72,16 +76,16 @@ export class CustomMessageSettingsApplication extends FormApplication {

public async _updateObject(_event, formData: Record<string, string>): Promise<void> {
// bundle up into settings object
const chatMessages: string[][][] = new Array(Object.keys(Climate).length/2)
const chatMessages: string[][][] = new Array(NUM_CLIMATES)
.fill('')
.map(() => new Array(Object.keys(Humidity).length/2)
.map(() => new Array(NUM_HUMIDITY)
.fill('')
.map(() => new Array(37).fill('')));
.map(() => new Array(NUM_WEATHER).fill('')));

for (let i=0; i<this._flattenedDescriptions.length; i++) {
chatMessages[this._flattenedDescriptions[i].climateId][this._flattenedDescriptions[i].humidityId][this._flattenedDescriptions[i].descriptionId] = formData['v-'+i];
}

await moduleSettings.set(SettingKeys.customChatMessages, chatMessages);
await moduleSettings.set(ModuleSettingKeys.customChatMessages, chatMessages);
}
}
78 changes: 39 additions & 39 deletions src/applications/WeatherApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { WindowDrag } from '@/window/windowDrag';
import { WeatherData } from '@/weather/WeatherData';
import { seasonSelections, biomeSelections, Climate, climateSelections, Humidity, humiditySelections, Season, biomeMappings } from '@/weather/climateData';
import { manualSelections, weatherDescriptions } from '@/weather/weatherMap';
import { SettingKeys } from '@/settings/ModuleSettings';
import { ModuleSettingKeys } from '@/settings/ModuleSettings';
import { isClientGM } from '@/utils/game';
import { generate, outputWeather, createManual, createSpecificWeather } from '@/weather/weatherGenerator';
import { moduleSettings } from '@/settings/ModuleSettings';
Expand Down Expand Up @@ -58,24 +58,24 @@ class WeatherApplication extends Application {
log(false, 'WeatherApplication construction');

// set the initial display
this._displayOptions = moduleSettings.get(SettingKeys.displayOptions) || { dateBox: false, weatherBox: true, biomeBar: true, seasonBar: true }
this._displayOptions = moduleSettings.get(ModuleSettingKeys.displayOptions) || { dateBox: false, weatherBox: true, biomeBar: true, seasonBar: true }

// get attached mode
this._attachedMode = moduleSettings.get(SettingKeys.attachToCalendar) || false;
this._attachedMode = moduleSettings.get(ModuleSettingKeys.attachToCalendar) || false;
this._attachmodeHidden = true;
this._compactMode = false;

// assume no SC unless told otherwise
this._simpleCalendarInstalled = false;

// get whether the manual pause is on
this._manualPause = moduleSettings.get(SettingKeys.manualPause || false);
this._manualPause = moduleSettings.get(ModuleSettingKeys.manualPause || false);

// don't show it until ready() has been called
this._currentlyHidden = true;

// get default position or set default
this._windowPosition = moduleSettings.get(SettingKeys.windowPosition) || { left: 100, bottom: 300 }
this._windowPosition = moduleSettings.get(ModuleSettingKeys.windowPosition) || { left: 100, bottom: 300 }

this.setWeather();
}
Expand Down Expand Up @@ -116,7 +116,7 @@ class WeatherApplication extends Application {
formattedDate: this._currentWeather?.date ? this._currentWeather.date.day + '/' + this._currentWeather.date.month + '/' + this._currentWeather.date.year : '',
formattedTime: this._currentWeather?.date?.display ? this._currentWeather.date.display.time : '',
weekday: this._currentWeather?.date ? this._currentWeather.date.weekdays[this._currentWeather.date.dayOfTheWeek] : '',
currentTemperature: this._currentWeather ? this._currentWeather.getTemperature(moduleSettings.get(SettingKeys.useCelsius)) : '',
currentTemperature: this._currentWeather ? this._currentWeather.getTemperature(moduleSettings.get(ModuleSettingKeys.useCelsius)) : '',
currentDescription: this._currentWeather ? this._currentWeather.getDescription() : '',
currentSeasonClass: this.currentSeasonClass(),
biomeSelections: biomeSelections,
Expand All @@ -132,13 +132,13 @@ class WeatherApplication extends Application {
hideFXToggle: !weatherEffects.useFX,
manualPause: this._manualPause,
fxActive: weatherEffects.fxActive,
useCelsius: moduleSettings.get(SettingKeys.useCelsius),
useCelsius: moduleSettings.get(ModuleSettingKeys.useCelsius),
attachedMode: this._attachedMode,
showAttached: this._attachedMode && !this._attachmodeHidden,
SCContainerClasses: !this._attachedMode ? '' : `${SC_CLASS_FOR_TAB_WRAPPER} sc-right ${SC_CLASS_FOR_TAB_EXTENDED}`,
windowPosition: this._attachedMode ? { bottom: 0, left: 0 } : this._windowPosition,
containerPosition: this._attachedMode ? 'relative' : 'fixed',
hideDialog: (this._attachedMode && this._attachmodeHidden) || this._currentlyHidden || !(isClientGM() || moduleSettings.get(SettingKeys.dialogDisplay)), // hide dialog - don't show anything
hideDialog: (this._attachedMode && this._attachmodeHidden) || this._currentlyHidden || !(isClientGM() || moduleSettings.get(ModuleSettingKeys.dialogDisplay)), // hide dialog - don't show anything
};
//log(false, data);

Expand All @@ -151,7 +151,7 @@ class WeatherApplication extends Application {
this._windowPosition = newPosition;

// save
moduleSettings.set(SettingKeys.windowPosition, this._windowPosition);
moduleSettings.set(ModuleSettingKeys.windowPosition, this._windowPosition);

this.render();
}
Expand Down Expand Up @@ -287,7 +287,7 @@ class WeatherApplication extends Application {
private setWindowPosition(position: WindowPosition): void {
this._windowPosition = position;

moduleSettings.set(SettingKeys.windowPosition, position);
moduleSettings.set(ModuleSettingKeys.windowPosition, position);

this.render();
}
Expand Down Expand Up @@ -316,7 +316,7 @@ class WeatherApplication extends Application {
// don't update the setting because a) no need... will update if anything changes anyway, and b)
// this may be called before the calendar is loaded so we don't want to overwrite it (it will
// get requeried later)
//moduleSettings.set(SettingKeys.seasonSync, false);
//moduleSettings.set(ModuleSettingKeys.seasonSync, false);
}
}

Expand All @@ -327,19 +327,19 @@ class WeatherApplication extends Application {
if (isClientGM()) {
// load the values from settings if missing
if (this._currentClimate == undefined)
this._currentClimate = moduleSettings.get(SettingKeys.climate);
this._currentClimate = moduleSettings.get(ModuleSettingKeys.climate);

if (this._currentHumidity == undefined)
this._currentHumidity = moduleSettings.get(SettingKeys.humidity);
this._currentHumidity = moduleSettings.get(ModuleSettingKeys.humidity);

if (this._currentSeason == undefined)
this._currentSeason = moduleSettings.get(SettingKeys.season);
this._currentSeason = moduleSettings.get(ModuleSettingKeys.season);

if (this._currentSeasonSync == undefined)
this._currentSeasonSync = moduleSettings.get(SettingKeys.seasonSync);
this._currentSeasonSync = moduleSettings.get(ModuleSettingKeys.seasonSync);

if (this._currentBiome == undefined)
this._currentBiome = moduleSettings.get(SettingKeys.biome);
this._currentBiome = moduleSettings.get(ModuleSettingKeys.biome);
}

weatherEffects.ready(this._currentWeather);
Expand All @@ -355,16 +355,16 @@ simple-weather DEBUG OUTPUT
_______________________________________
isGM: ${isClientGM()}
displayOptions: ${JSON.stringify(this._displayOptions, null, 2)}
dialogDisplay: ${moduleSettings.get(SettingKeys.dialogDisplay)}
dialogDisplay: ${moduleSettings.get(ModuleSettingKeys.dialogDisplay)}
calendarPresent: ${this._calendarPresent}
manualPause: ${this._manualPause}
currentClimate: ${this._currentClimate}
currentHumidity: ${this._currentHumidity}
currentBiome: ${this._currentBiome}
currentSeason: ${this._currentSeason}
currentSeasonSync: ${this._currentSeasonSync}
WeatherEffects.fxActive = ${moduleSettings.get(SettingKeys.fxActive)}
WeatherEffects.useFX = ${moduleSettings.get(SettingKeys.useFX)}
WeatherEffects.fxActive: ${weatherEffects.fxActive}
WeatherEffects.useFX: ${moduleSettings.get(ModuleSettingKeys.useFX)}
getData: ${JSON.stringify(await this.getData(), null, 2)}
_______________________________________
`;
Expand All @@ -381,7 +381,7 @@ _______________________________________
}

// save
moduleSettings.set(SettingKeys.displayOptions, this._displayOptions);
moduleSettings.set(ModuleSettingKeys.displayOptions, this._displayOptions);

this.render();
}
Expand All @@ -394,7 +394,7 @@ _______________________________________

if (this.hasDateChanged(currentDate)) {
if (isClientGM()) {
if (moduleSettings.get(SettingKeys.storeInSCNotes)) {
if (moduleSettings.get(ModuleSettingKeys.storeInSCNotes)) {
// if we're using notes from SC (and have a valid note) pull that weather
const notes = SimpleCalendar.api.getNotesForDay(currentDate.year, currentDate.month, currentDate.day);
let foundWeatherNote = false;
Expand Down Expand Up @@ -452,7 +452,7 @@ _______________________________________
// called from outside, to load the last weather from the settings
// also called by player clients when GM updates the settings
public setWeather(): void {
const weatherData = moduleSettings.get(SettingKeys.lastWeatherData);
const weatherData = moduleSettings.get(ModuleSettingKeys.lastWeatherData);

if (weatherData) {
log(false, 'Using saved weather data');
Expand Down Expand Up @@ -525,20 +525,20 @@ _______________________________________
private activateWeather(weatherData: WeatherData): void {
if (isClientGM()) {
// Output to chat if enabled
if (moduleSettings.get(SettingKeys.outputWeatherToChat)) {
if (moduleSettings.get(ModuleSettingKeys.outputWeatherToChat)) {
outputWeather(weatherData);
}

// activate special effects
weatherEffects.activateFX(weatherData);

// if we're saving to the calendar, do that
if (moduleSettings.get(SettingKeys.storeInSCNotes)) {
if (moduleSettings.get(ModuleSettingKeys.storeInSCNotes)) {
void this.saveWeatherToCalendarNote(weatherData);
}

// save
moduleSettings.set(SettingKeys.lastWeatherData, this._currentWeather);
moduleSettings.set(ModuleSettingKeys.lastWeatherData, this._currentWeather);
}
}

Expand Down Expand Up @@ -566,7 +566,7 @@ _______________________________________
}

// add a new one
const noteContent = `Todays weather: ${weatherData.getTemperature(moduleSettings.get(SettingKeys.useCelsius))} - ${weatherData.getDescription() }`;
const noteContent = `Todays weather: ${weatherData.getTemperature(moduleSettings.get(ModuleSettingKeys.useCelsius))} - ${weatherData.getDescription() }`;
const theDate = { year: weatherData.date.year, month: weatherData.date.month, day: weatherData.date.day};

// create the note and store the weather detail as a flag
Expand Down Expand Up @@ -636,7 +636,7 @@ _______________________________________
public regenerateWeather() {
if (isClientGM()) {
this.generateWeather(this._currentWeather?.date || null);
moduleSettings.set(SettingKeys.lastWeatherData, this._currentWeather);
moduleSettings.set(ModuleSettingKeys.lastWeatherData, this._currentWeather);
this.render();
}
}
Expand All @@ -652,8 +652,8 @@ _______________________________________
this._currentSeason = Number(target.value);
}

moduleSettings.set(SettingKeys.seasonSync, this._currentSeasonSync);
moduleSettings.set(SettingKeys.season, this._currentSeason);
moduleSettings.set(ModuleSettingKeys.seasonSync, this._currentSeasonSync);
moduleSettings.set(ModuleSettingKeys.season, this._currentSeason);

// render to update the icon
this.render();
Expand All @@ -663,24 +663,24 @@ _______________________________________
// save the value - we don't regenerate because we might be changing other settings, too, and don't want to trigger a bunch of chat messages
const target = event.originalEvent?.target as HTMLSelectElement;
this._currentClimate = Number(target.value)
moduleSettings.set(SettingKeys.climate, this._currentClimate);
moduleSettings.set(ModuleSettingKeys.climate, this._currentClimate);

// set biome to blank because we adjusted manually
jQuery(document).find('#swr-biome-selection').val('');
this._currentBiome = '';
moduleSettings.set(SettingKeys.biome, '');
moduleSettings.set(ModuleSettingKeys.biome, '');
};

private onHumiditySelectChange = (event): void => {
// save the value - we don't regenerate because we might be changing other settings, too, and don't want to trigger a bunch of chat messages
const target = event.originalEvent?.target as HTMLSelectElement;
this._currentHumidity = Number(target.value);
moduleSettings.set(SettingKeys.humidity, this._currentHumidity);
moduleSettings.set(ModuleSettingKeys.humidity, this._currentHumidity);

// set biome to blank because we adjusted manually
jQuery(document).find('#swr-biome-selection').val('');
this._currentBiome = '';
moduleSettings.set(SettingKeys.biome, '');
moduleSettings.set(ModuleSettingKeys.biome, '');
};

private onBiomeSelectChange = (event): void => {
Expand All @@ -694,21 +694,21 @@ _______________________________________
if (biomeMapping) {
// save the value - we don't regenerate because we might be changing other settings, too, and don't want to trigger a bunch of chat messages
this._currentBiome = target.value
moduleSettings.set(SettingKeys.biome, this._currentBiome);
moduleSettings.set(ModuleSettingKeys.biome, this._currentBiome);

// update the other selects
const climate = document.getElementById('swr-climate-selection') as HTMLSelectElement | null;
if (climate) {
climate.value = String(biomeMapping.climate);
this._currentClimate = biomeMapping.climate;
moduleSettings.set(SettingKeys.climate, biomeMapping.climate);
moduleSettings.set(ModuleSettingKeys.climate, biomeMapping.climate);
}

const humidity = document.getElementById('swr-humidity-selection') as HTMLSelectElement | null;
if (humidity) {
humidity.value = String(biomeMapping.humidity);
this._currentHumidity = biomeMapping.humidity;
moduleSettings.set(SettingKeys.humidity, biomeMapping.humidity);
moduleSettings.set(ModuleSettingKeys.humidity, biomeMapping.humidity);
}
}
};
Expand All @@ -720,7 +720,7 @@ _______________________________________
public manualPauseToggle() {
if (isClientGM()) {
this._manualPause = !this._manualPause;
moduleSettings.set(SettingKeys.manualPause, this._manualPause);
moduleSettings.set(ModuleSettingKeys.manualPause, this._manualPause);

// if we're turning it on, hide the weather bars
if (this._manualPause) {
Expand Down Expand Up @@ -759,7 +759,7 @@ _______________________________________

public toggleFX() {
if (isClientGM()) {
weatherEffects.fxActive = !weatherEffects.fxActive;
weatherEffects.setFxActive(!weatherEffects.fxActive);
this.render();
}
}
Expand Down Expand Up @@ -790,7 +790,7 @@ _______________________________________
return;
}

if (moduleSettings.get(SettingKeys.useCelsius))
if (moduleSettings.get(ModuleSettingKeys.useCelsius))
temp = Math.round((temp*9/5)+32);

this.setManualWeather(this._currentWeather?.date || null, temp, Number(select.value));
Expand Down
Loading

0 comments on commit 1e1e115

Please sign in to comment.