How dmitrii-sokolov/ksp-gravity-calculator works
Project’s Major Components
a. Data/Asset Repository:
• Assets (and its subdirectories): Contains all in-game parts (Engines, Decouplers, Fuel Tanks, Technologies) as well as sprites, UI prefabs, and WebGL templates.
• These assets provide the raw data (game objects, engine/fuel definitions, technology progressions) that the tool uses for computations and user display.
b. Core Calculation Logic:
• Scripts/Core, Scripts/Assemblies, and Scripts/Parts contain the main logic. This is where interfaces (like IEngineAssembly) and classes (LiquidEngineAssembly, SolidFuelEngine, etc.) determine how fuel consumption, engine performance, and deltaV are computed.
• The Iterators modules (LiquidIterator, LiquidSolidIterator) indicate systematic traversal or computation across engine setups.
c. User Interface (UI) Module:
• Scripts/UI and prefabs under Assets/UI define the user-facing elements. They include custom drawers (EngineDrawer, TechDrawer, MainUI, etc.) that render the output of the computations.
• In addition, Editor scripts exist (in Scripts/Editor) to enhance the development or customization experience.
d. Helpers & Utilities:
• Scripts/Helpers provide annotations (like LabelAttribute) and locale-specific helpers ensuring the tool is user friendly and easily extensible.
e. Integration & Build Configuration:
• The Unity-specific project folders (ProjectSettings, Packages, WebGLTemplates) ensure that project configuration and build pipelines are correctly maintained (for example, enabling browser-based deployments through the WebGL settings).
Interactions and Data Flow
a. User Input → UI Module:
• Users interact with the tool via UI elements (buttons, input fields) presented by UI prefabs.
b. UI Module → Core Calculation Logic:
• The UI communicates user selections (part assemblies, fuel tanks, engine combinations) to the core scripts which perform deltaV and efficiency calculations.
c. Core Calculation Logic ↔ Data/Asset Repository:
• The computation logic retrieves necessary data (e.g., engine specifications, fuel types, decoupler characteristics) from the data assets.
d. Output Rendering & Feedback:
• The results of the computations are passed back to the UI Module, which updates the display (like views for technologies, engine performance, deltaV stats).
Architectural Patterns and Design Principles
a. Separation of Concerns:
• The project clearly separates resource management (Assets folder), computation/assembly logic (Scripts/Assemblies, Scripts/Core, Scripts/Parts), and the presentation layer (Scripts/UI).
• You might illustrate these as isolated “modules” with defined responsibilities.
b. MVC or Similar Patterns:
• The UI acts as the “View,” the core calculation scripts play the role of the “Controller,” and the Data/Asset repository serves as the “Model.”
• This pattern explicitly if desired.
c. Modularity:
• The presence of iterators, a helpers folder, and separate assemblies indicates modular design. Label these modules to show how they can be independently maintained or extended.
d. Unity-Specific Structure:
• Unity concepts such as Prefabs, ScriptableObjects (asset files), and scene management (likely driven by Assets/Main.unity).
Suggested Components
• User Interface (UI) Module:
– UI Prefabs (Assembly.prefab, Engine.prefab, etc.)
– UI Scripts (MainUI, EngineDrawer, etc.)
• Calculation Engine Module:
– Core Scripts (fuel/deltaV calculations in Scripts/Core and Scripts/Assemblies)
– Part Assemblies (LiquidEngineAssembly, SolidFuelEngine, etc.)
– Iterators (LiquidIterator, LiquidSolidIterator)
• Data Assets Repository:
– Engine, Decoupler, Fuel Tank, and Technology assets (under Assets/Parts and Assets/Technologies)
– Sprites used for visual representation
• Configuration & Build Settings:
– Unity project settings, Editor preferences, and WebGL templates for browser deployment (Assets/WebGLTemplates)