How newbikscube/chatbotrpg works
Project type and purpose
• This is a standalone, desktop “thick‐client” application written in Python using PyQt5 for its GUI.
• Its purpose is to provide an interactive text‐based RPG engine: a UI front end for chat, world editing, rule and character management, and an AI-backed game logic core that persists data as JSON files.
File structure
• Top-level assets:
• Demo.zip (sample game data)
• config.json (API keys, settings)
• sounds/ (UI and game sound effects)
• START.bat (Windows launcher)
• src/ – main application code:
• chatBotRPG.py – entry point: initializes the app, loads config, and starts the main window.
• config.py – loads and exposes configuration (API keys, model settings).
• core/ – “controller” and “model” logic for UI behaviors (splitters, tab management, stylesheets), game flow (splash, intro, game over), inference, memory, rule triggers, and utilities.
• editor_panel/ – UI for game‐building tools: world editor (canvas, toolbars), actor/inventory/rules/time managers, etc.
• player_panel/ – UI for the player’s view: chat window, world map, right splitter controls.
• generate/ – modules to procedurally generate actors, settings, summaries, and random lists.
• rules/ – the rules engine: loading/applying rules, evaluating conditions, triggering screen effects and timer‐based rules.
• scribe/ – the built-in AI assistant module for helping creators via agent_chat.
• There is no centralized database – data persistence is via JSON files in /data/ (unpacked from Demo.zip).
README for technical insights
• Confirms PyQt5 UI, JSON-based persistence, OpenRouter.ai (and other LLM) integration.
• Emphasizes modular game-building toolkits: Worlds, Time Passage, Character Management, Rules Engine, Keywords Matching, Inventory, Random Lists, Scribe.
• Notes that game state is stored in /data/<game_name>/… and snapshots in /saves/.
Main components
a. Frontend (UI Layer)
• ChatWindow (core/chatBotRPG)
• EditorPanel (editor_panel/*)
• PlayerPanel (player_panel/*)
• SoundPlayer (sounds/*.mp3)
b. Application Logic (Controller Layer)
• Core Engine (core/*): splitters, tab manager, UI widgets, game_intro, move_character, process_keywords, memory.
• Rules Engine (rules/*): apply_rules, rule_evaluator, timer_rules_manager.
• Generation Modules (generate/*): generate_actor, generate_setting, generate_summary, random lists.
• Scribe Agent (scribe/agent_chat.py): helper AI agent for game creation.
c. Data Persistence (Model Layer)
• JSON file store in /data/ and /saves/ (represented as a “document store”).
• Config Store (config.json).
d. External Services
• LLM API (OpenRouter.ai, Google GenAI, etc.) – invoked by core.character_inference and scribe.
• File System (Demo.zip unpack, sounds folder).
e. Runtime orchestrator
• chatBotRPG.py ties together UI, core, rules, generate, and scribe, handling event loop and high-level flows.
Relationships and interactions
• User interacts with UI (ChatWindow, EditorPanel, PlayerPanel).
• UI events → Core Engine controllers (process user input, trigger splitters, update UI).
• Core Engine → Rules Engine for conditional logic and game‐over triggers.
• Core Engine / Rules Engine → LLM Inference (via character_inference or make_inference) with prompts from process_keywords.
• Generation Modules may be invoked by EditorPanel or Scribe to produce new world/actor/rule content, then stored as JSON.
• All state changes → persisted to JSON files; saves are folder snapshots.
• UI sound events → SoundPlayer reads from sounds/ folder.
• Scribe Agent can call LLM, return suggestions, integrated into EditorPanel UI.
Architectural patterns and design principles
• MVC/MVP style separation:
• View: PyQt5 UI panels
• Controller: core/* modules orchestrating events, rules, and inference
• Model: JSON persistence, in-memory game state in memory.py
• Modular plugin-like structure: editor_panel, player_panel, generate, rules, scribe appear as well-defined packages.
• Clear separation of concerns: UI styling (apply_stylesheet), UI layout (splitters), game logic (core and rules), generation, persistence, external calls.
Elements
• Clear labels:
• ChatWindow, EditorPanel, PlayerPanel
• CoreEngine, RulesEngine, GenerationModules, ScribeAgent
• JSON Data Store, Config Store, Sound Resources
• External LLM Service
• UI → CoreEngine (user actions)
• CoreEngine → RulesEngine (evaluate conditions)
• CoreEngine/RulesEngine → LLM API (inference calls)
• GenerationModules → JSON Store (write new game files)
• UI → SoundPlayer → sounds/*.mp3
• Blue rectangles for UI components
• Green rectangles for business logic modules
• Yellow parallelogram for external service (LLM API)
• Rounded rectangles for utility modules (config, sound).