v3.7.1: Weather keywords, character stat editing fix, scroll bug fix, avatar layout
- Improved weather generation: Added hard templates for weather keywords to ensure LLM generates valid weather patterns that match dynamic effects - Fixed character stat editing bug: Now properly handles array format stats from LLM (values no longer revert on blur) - Fixed scroll/viewport bug: Mobile-only scrollIntoView prevents page jumping on desktop when editing fields - Changed Present Characters avatar display: Avatar now aligned with name in header row, fields take full width below - Updated descriptions and labels
This commit is contained in:
@@ -794,12 +794,17 @@ export function setupMobileKeyboardHandling() {
|
||||
/**
|
||||
* Handles focus on contenteditable fields to ensure they're visible when keyboard appears.
|
||||
* Uses smooth scrolling to bring focused field into view with proper padding.
|
||||
* Only applies on mobile viewports where virtual keyboard can obscure content.
|
||||
*/
|
||||
export function setupContentEditableScrolling() {
|
||||
const $panel = $('#rpg-companion-panel');
|
||||
|
||||
// Use event delegation for all contenteditable fields
|
||||
$panel.on('focusin', '[contenteditable="true"]', function(e) {
|
||||
// Only apply scrolling behavior on mobile (where virtual keyboard appears)
|
||||
const isMobile = window.innerWidth <= 1000;
|
||||
if (!isMobile) return;
|
||||
|
||||
const $field = $(this);
|
||||
|
||||
// Small delay to let keyboard animate in
|
||||
|
||||
@@ -107,7 +107,8 @@ function getCurrentTime() {
|
||||
|
||||
// Patterns for specific weather conditions (order matters - combined effects first)
|
||||
// Grouped by languages for easy editing
|
||||
const WEATHER_PATTERNS_BY_LANGUAGE = {
|
||||
// EXPORTED: Used by jsonPromptHelpers.js to provide valid weather keywords to LLM
|
||||
export const WEATHER_PATTERNS_BY_LANGUAGE = {
|
||||
en: [
|
||||
{ id: "blizzard", patterns: [ "blizzard" ] }, // Snow + Wind
|
||||
{ id: "storm", patterns: [ "storm", "thunder", "lightning" ] }, // Rain + Lightning
|
||||
@@ -130,6 +131,63 @@ const WEATHER_PATTERNS_BY_LANGUAGE = {
|
||||
],
|
||||
}
|
||||
|
||||
/**
|
||||
* Get valid weather keywords for LLM prompt injection.
|
||||
* Returns weather patterns for specified language or all languages.
|
||||
* This ensures LLM generates responses that exactly match our expected patterns.
|
||||
*
|
||||
* @param {string} [language] - Language code (e.g., 'en', 'ru'). If not specified, returns all languages.
|
||||
* @returns {Object} Object with weather type IDs as keys and arrays of valid keywords as values
|
||||
* @example
|
||||
* // Returns: { blizzard: ["blizzard"], storm: ["storm", "thunder", "lightning"], ... }
|
||||
* getWeatherKeywordsForPrompt('en');
|
||||
*/
|
||||
export function getWeatherKeywordsForPrompt(language) {
|
||||
const result = {};
|
||||
|
||||
// Get patterns for specified language or merge all languages
|
||||
const languagesToProcess = language && WEATHER_PATTERNS_BY_LANGUAGE[language]
|
||||
? { [language]: WEATHER_PATTERNS_BY_LANGUAGE[language] }
|
||||
: WEATHER_PATTERNS_BY_LANGUAGE;
|
||||
|
||||
for (const [lang, patterns] of Object.entries(languagesToProcess)) {
|
||||
for (const { id, patterns: keywords } of patterns) {
|
||||
if (!result[id]) {
|
||||
result[id] = [];
|
||||
}
|
||||
// Add keywords, avoiding duplicates
|
||||
for (const keyword of keywords) {
|
||||
if (!result[id].includes(keyword)) {
|
||||
result[id].push(keyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get weather keywords as a formatted string for LLM instructions.
|
||||
* Provides a clear template showing valid weather forecast values.
|
||||
*
|
||||
* @param {string} [language] - Language code. If not specified, uses all available patterns.
|
||||
* @returns {string} Formatted string for prompt injection
|
||||
* @example
|
||||
* // Returns: 'Valid forecast values: "blizzard", "storm", "thunder", "lightning", "wind", ...'
|
||||
* getWeatherKeywordsAsPromptString('en');
|
||||
*/
|
||||
export function getWeatherKeywordsAsPromptString(language) {
|
||||
const keywords = getWeatherKeywordsForPrompt(language);
|
||||
const allKeywords = [];
|
||||
|
||||
for (const patterns of Object.values(keywords)) {
|
||||
allKeywords.push(...patterns);
|
||||
}
|
||||
|
||||
return `Valid forecast values (use one of these exactly): ${allKeywords.map(k => `"${k}"`).join(', ')}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse weather text to determine effect type
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user