How codeonaraft/krpg works
Main Components
• Editor Module: Located in the “editor” folder, it contains its own build and configuration files, UI components (such as menus, dialogs, properties windows, etc.), and resources (styles and configuration resources).
• Game Module: Found in the “game” folder, this contains the core gameplay logic including the main game loop (game/src/main.zig), game-specific configurations, maps, objects (barrels, bread rolls, etc.), and game resources (scene files and object definitions).
• Shared Module: All common functionality, types, managers, and utility functions reside in the “shared” folder. This module includes various managers (GameManager, ObjectsManager), definitions for game objects, utility functions (such as for string and vector operations), and core types and interfaces used by both the editor and game.
Architecturally-Relevant File Structures
• The directory separation clearly distinguishes between the game runtime, the editor, and the common shared code. This is an indicator of modular design.
• Each module has its own build scripts (build.zig and accompanying configuration files) indicating independent build processes, while still relying on shared code.
• The presence of UI components inside the editor’s “src/ui” directory (with dialog and menu sub-folders) informs that the editor likely uses a custom UI framework possibly built on raylib (as the README mentions the Game Library raylib).
• Resources such as maps, objects, and scene files in the game module indicate that the game engine is structured to support asset loading and gameplay management using these resource files.
Relationships and Interaction
• The Game Module and Editor Module both interact with the Shared Module. They likely share core game logic, utility functions, data types, and managers (e.g., GameManager, ObjectsManager).
• The Editor is intended to help create or modify game content, meaning there are bi-directional interactions: the editor sends data/configurations to update game state/assets and might read or write configurations defined in the shared module.
• The game runtime utilizes external libraries, notably raylib, to handle rendering, user input, and audio.
Architectural Patterns/Design Principles
• Modular Architecture: Separation of game, editor, and shared libraries for better maintainability and future extension.
• MVC tendencies in the editor: There is a distinction between UI components (views) and underlying logic, indicated by separate UI files and menus/dialogs.
• Layered Structure: At a high level, the application has layers for presentation (editor UI and game rendering), business logic (managers, scene management, object manipulation), and data/configuration (resources and map files).
a. Components:
• Game Editor: Includes UI subcomponents (Menus, Dialogs, Properties, Scene Windows) and resources (styles, configuration).
• Game Runtime: Encompassing main game loop, resource management (maps, game objects like barrels and NPCs), and scene management.
• Shared Library: The core logic layer with managers, types (Basic types, GameObjects, UI types), utility functions (strings, vector math), and interfaces.
• External Services/Libraries: For example, raylib is used for rendering and input.
b. Data Flow and Interactions:
• Connections between Game and Shared modules, indicating shared managers, types, and utility functions.
• Annotations to show how resources are loaded by the game runtime from resources directories.
c. Architectural Patterns:
• Modular separation.
• Independent build/runner paths (“zig build run” in both game and editor) which allows them to be executed individually.
d. Technologies and Frameworks:
• Zig as the implementation language.
• Raylib under External Libraries as it is critical for game rendering and input handling.