-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-weather.js
More file actions
191 lines (166 loc) · 6.48 KB
/
Copy pathsimple-weather.js
File metadata and controls
191 lines (166 loc) · 6.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/**
* Integration Example: Simple Weather
*
* This example shows how to integrate the Errors and Echoes Registration API
* with the Simple Weather module for enhanced error reporting.
*/
// Wait for both modules to be ready
Hooks.once('ready', () => {
// Check if Errors and Echoes is available
if (!window.ErrorsAndEchoesAPI) {
console.warn('Simple Weather: Errors and Echoes API not available');
return;
}
try {
// Register with enhanced error reporting
window.ErrorsAndEchoesAPI.register({
moduleId: 'foundry-simple-weather',
// Context provider - adds weather and scene information
contextProvider: () => {
const context = {};
// Add current weather information
if (game.modules.get('foundry-simple-weather')?.active) {
try {
// Check if Simple Weather API is available
if (window.SimpleWeather) {
const currentWeather = window.SimpleWeather.getCurrentWeather();
if (currentWeather) {
context.currentWeather = {
type: currentWeather.type || 'unknown',
intensity: currentWeather.intensity || 'normal',
temperature: currentWeather.temperature || null,
hasEffects: currentWeather.effects?.length > 0 || false
};
}
// Add weather generation settings
context.weatherGeneration = {
autoGenerate: window.SimpleWeather.getSettings?.().autoGenerate || false,
climateType: window.SimpleWeather.getSettings?.().climate || 'temperate',
seasonalEffects: window.SimpleWeather.getSettings?.().useSeasons || false
};
}
// Add scene-specific weather data
if (game.scenes?.active) {
const scene = game.scenes.active;
const sceneWeather = scene.getFlag('foundry-simple-weather', 'weather');
if (sceneWeather) {
context.sceneWeatherOverride = true;
context.sceneWeatherType = sceneWeather.type;
}
}
} catch (e) {
context.weatherAPIError = e.message;
}
}
// Add calendar integration status (for weather generation)
const calendarModules = [
'foundryvtt-simple-calendar',
'about-time',
'smalltime'
];
context.calendarIntegration = {
available: calendarModules.some(id => game.modules.get(id)?.active),
activeCalendar: calendarModules.find(id => game.modules.get(id)?.active) || 'none'
};
// Add system information
context.gameSystem = game.system.id;
context.foundryVersion = game.version;
return context;
},
// Error filter - focus on weather-related errors
errorFilter: (error) => {
const stack = error.stack || '';
const message = error.message || '';
// Always report errors directly from Simple Weather
if (stack.includes('foundry-simple-weather') ||
stack.includes('simple-weather') ||
message.includes('weather') ||
message.includes('SimpleWeather')) {
return false; // Don't filter (report this error)
}
// Report errors related to weather effects or canvas layers
if (message.includes('WeatherEffects') ||
message.includes('weather-effect') ||
stack.includes('WeatherLayer') ||
stack.includes('SpecialEffectsLayer')) {
return false; // Don't filter
}
// Report calendar integration errors that might affect weather
if ((message.includes('calendar') || message.includes('time')) &&
(stack.includes('foundry-simple-weather') ||
message.includes('weather'))) {
return false; // Don't filter
}
// Filter out errors from other audio/visual modules unless they mention weather
const avModules = [
'dice-so-nice', 'animated-spell-effects', 'jb2a',
'token-magic-fx', 'sequencer'
];
for (const module of avModules) {
if (stack.includes(module) && !message.includes('weather')) {
return true; // Filter out
}
}
// Default: filter out unless clearly related
return !message.toLowerCase().includes('weather');
}
});
console.log('Simple Weather: Successfully registered with Errors and Echoes');
} catch (error) {
console.error('Simple Weather: Failed to register with Errors and Echoes:', error);
}
});
// Example: Manual error reporting for weather-specific scenarios
window.SimpleWeatherErrorReporting = {
/**
* Report a weather generation error
*/
reportWeatherGenError: (error, climate, season) => {
if (window.ErrorsAndEchoesAPI?.reportError) {
window.ErrorsAndEchoesAPI.reportError(error, {
category: 'weather-generation',
climate: climate,
season: season,
timestamp: new Date().toISOString()
});
}
},
/**
* Report a weather effect rendering error
*/
reportEffectError: (error, weatherType, effectName) => {
if (window.ErrorsAndEchoesAPI?.reportError) {
window.ErrorsAndEchoesAPI.reportError(error, {
category: 'weather-effects',
weatherType: weatherType,
effectName: effectName,
canvasSize: {
width: canvas.dimensions.width,
height: canvas.dimensions.height
},
timestamp: new Date().toISOString()
});
}
},
/**
* Report a calendar integration error
*/
reportCalendarError: (error, calendarModule, operation) => {
if (window.ErrorsAndEchoesAPI?.reportError) {
window.ErrorsAndEchoesAPI.reportError(error, {
category: 'calendar-integration',
calendarModule: calendarModule,
operation: operation,
timestamp: new Date().toISOString()
});
}
}
};
// Example: Hook into weather events for automatic error reporting
Hooks.on('simpleWeatherChange', (weatherData) => {
console.log('Simple Weather: Weather changed, enhanced error reporting active for effects');
});
Hooks.on('canvasReady', () => {
// Weather effects are often initialized when canvas is ready
console.log('Simple Weather: Canvas ready, monitoring for weather effect errors');
});