197 lines
7.3 KiB
JavaScript
197 lines
7.3 KiB
JavaScript
console.log('RTS-MODE: index.js script loading...');
|
|
|
|
// Test if jQuery is available
|
|
console.log('RTS-MODE: jQuery available:', typeof jQuery !== 'undefined');
|
|
console.log('RTS-MODE: $ available:', typeof $ !== 'undefined');
|
|
|
|
import { renderExtensionTemplateAsync } from '../../extensions.js';
|
|
import { eventSource, event_types } from '../../events.js';
|
|
import { createMapCanvas } from './ui/MapCanvas.js';
|
|
import { createResourcePanel } from './ui/ResourcePanel.js';
|
|
import { rtsUI } from './ui/RTSUIController.js';
|
|
import GameStateManager from './src/GameStateManager.js';
|
|
import { sendTurn } from './src/LLMAdapter.js';
|
|
import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js';
|
|
import { SlashCommand } from '../../slash-commands/SlashCommand.js';
|
|
import { ARGUMENT_TYPE, SlashCommandArgument } from '../../slash-commands/SlashCommandArgument.js';
|
|
import './js/rts-mode.js';
|
|
|
|
console.log('RTS-MODE: All imports successful');
|
|
|
|
const extensionId = 'rts-mode';
|
|
const extensionName = 'RTS Chat Mode';
|
|
|
|
let root;
|
|
let topButton;
|
|
let uiMounted = false;
|
|
|
|
async function addTopBarButton() {
|
|
console.log('RTS Chat Mode: Adding top bar button...');
|
|
if (topButton) {
|
|
console.warn('RTS Chat Mode: Top button already exists, skipping creation.');
|
|
return;
|
|
}
|
|
topButton = $(await renderExtensionTemplateAsync('rts-mode', 'button'));
|
|
$('#top-settings-holder').append(topButton);
|
|
|
|
// Set up direct RTS UI toggle functionality
|
|
topButton.on('click', async (e) => {
|
|
e.stopPropagation();
|
|
console.log('RTS Mode button clicked');
|
|
|
|
try {
|
|
// Toggle between fullscreen RTS UI and normal SillyTavern UI
|
|
if (rtsUI.isActive()) {
|
|
await rtsUI.exitFullscreen();
|
|
// Update button to show we're back to normal mode
|
|
topButton.find('i').removeClass('fa-eye-slash').addClass('fa-chess-board');
|
|
topButton.attr('title', 'Toggle RTS UI').attr('data-i18n', '[title]Toggle RTS UI');
|
|
console.log('RTS UI hidden, returned to SillyTavern interface');
|
|
} else {
|
|
await rtsUI.enterFullscreen();
|
|
// Update button to show we're in fullscreen mode
|
|
topButton.find('i').removeClass('fa-chess-board').addClass('fa-eye-slash');
|
|
topButton.attr('title', 'Hide RTS UI').attr('data-i18n', '[title]Hide RTS UI');
|
|
console.log('RTS UI activated');
|
|
}
|
|
} catch (error) {
|
|
console.error('Error toggling RTS UI:', error);
|
|
}
|
|
});
|
|
}
|
|
|
|
function mountUI() {
|
|
if (!document.getElementById('rts-mode-root')) {
|
|
root = document.createElement('div');
|
|
root.id = 'rts-mode-root';
|
|
document.body.appendChild(root);
|
|
|
|
createMapCanvas(root);
|
|
createResourcePanel(root);
|
|
|
|
console.log('RTS Chat Mode UI mounted.');
|
|
uiMounted = true;
|
|
|
|
// Update button icon to show UI is active
|
|
topButton?.find('i').removeClass('fa-chess-board').addClass('fa-eye-slash');
|
|
topButton?.attr('title', 'Hide RTS UI').attr('data-i18n', '[title]Hide RTS UI');
|
|
}
|
|
}
|
|
|
|
function unmountUI() {
|
|
if (root) {
|
|
root.remove();
|
|
root = null;
|
|
console.log('RTS Chat Mode UI unmounted.');
|
|
uiMounted = false;
|
|
|
|
// Update button icon to show UI is hidden
|
|
topButton?.find('i').removeClass('fa-eye-slash').addClass('fa-chess-board');
|
|
topButton?.attr('title', 'Toggle RTS UI').attr('data-i18n', '[title]Toggle RTS UI');
|
|
}
|
|
}
|
|
|
|
async function onRtsStartCommand() {
|
|
console.log('RTS Start command executed.');
|
|
|
|
const presetSelect = /** @type {HTMLSelectElement} */ (document.getElementById('rts-preset-select'));
|
|
const selectedPreset = presetSelect ? presetSelect.value : '/scripts/extensions/rts-mode/presets/zoo_escape.json';
|
|
await rtsUI.loadPreset(selectedPreset);
|
|
|
|
GameStateManager.reset();
|
|
|
|
// If RTS UI is active, update it
|
|
if (rtsUI.isActive()) {
|
|
rtsUI.updateUI();
|
|
rtsUI.addLogEntry('system', 'Game state reset. New campaign begins!');
|
|
}
|
|
|
|
return 'RTS game has been reset with the selected preset.';
|
|
}
|
|
|
|
function onRtsCmdCommand(args, value) {
|
|
console.log('RTS Command executed with args:', args, 'value:', value);
|
|
if (value) {
|
|
// The UI will now be updated by the 'rts-narrative-update' event listener
|
|
sendTurn(value);
|
|
return `RTS Command executed: ${value}`;
|
|
}
|
|
return 'No command provided';
|
|
}
|
|
|
|
async function onRtsUICommand() {
|
|
console.log('RTS UI toggle command executed.');
|
|
|
|
if (rtsUI.isActive()) {
|
|
await rtsUI.exitFullscreen();
|
|
// Update button state to match
|
|
if (topButton) {
|
|
topButton.find('i').removeClass('fa-eye-slash').addClass('fa-chess-board');
|
|
topButton.attr('title', 'Toggle RTS UI').attr('data-i18n', '[title]Toggle RTS UI');
|
|
}
|
|
return 'RTS UI hidden. Returned to normal SillyTavern interface.';
|
|
} else {
|
|
await rtsUI.enterFullscreen();
|
|
// Update button state to match
|
|
if (topButton) {
|
|
topButton.find('i').removeClass('fa-chess-board').addClass('fa-eye-slash');
|
|
topButton.attr('title', 'Hide RTS UI').attr('data-i18n', '[title]Hide RTS UI');
|
|
}
|
|
return 'RTS UI activated. Use ESC key or /rts-ui to return to normal interface.';
|
|
}
|
|
}
|
|
|
|
jQuery(async function() {
|
|
console.log('RTS Chat Mode: jQuery ready, initializing extension...');
|
|
|
|
await addTopBarButton();
|
|
|
|
// Register slash commands
|
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
|
name: 'rts-start',
|
|
callback: onRtsStartCommand,
|
|
helpString: 'Resets the RTS game state.',
|
|
}));
|
|
|
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
|
name: 'rts-cmd',
|
|
callback: onRtsCmdCommand,
|
|
helpString: 'Sends a command to the RTS game master.',
|
|
unnamedArgumentList: [
|
|
new SlashCommandArgument('command', [ARGUMENT_TYPE.STRING], true),
|
|
],
|
|
}));
|
|
|
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
|
name: 'rts-ui',
|
|
callback: onRtsUICommand,
|
|
aliases: ['rts-toggle', 'rts-fullscreen'],
|
|
helpString: 'Toggles the full-screen RTS interface.',
|
|
}));
|
|
|
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
|
name: 'rts-observe',
|
|
callback: () => onRtsCmdCommand([], 'Look around carefully to assess the situation.'),
|
|
helpString: 'Quick action: Observe the surroundings.',
|
|
}));
|
|
|
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
|
name: 'rts-move',
|
|
callback: () => onRtsCmdCommand([], 'Move to a specific location.'),
|
|
helpString: 'Quick action: Move to another location.',
|
|
}));
|
|
|
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
|
name: 'rts-hide',
|
|
callback: () => onRtsCmdCommand([], 'Find a hiding spot.'),
|
|
helpString: 'Quick action: Find a place to hide.',
|
|
}));
|
|
|
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
|
name: 'rts-interact',
|
|
callback: () => onRtsCmdCommand([], 'Interact with something in the environment.'),
|
|
helpString: 'Quick action: Interact with nearby objects or people.',
|
|
}));
|
|
|
|
console.log('RTS Chat Mode: Extension initialized successfully');
|
|
}); |