Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
DataManager Class Reference

#include <DataManager.h>

Classes

struct  LevelPreloadResult
 
struct  PreloadStats
 
struct  TilesetInfo
 

Public Member Functions

 DataManager ()
 
virtual ~DataManager ()
 
void Initialize ()
 
void Shutdown ()
 
bool PreloadTexture (const std::string &id, const std::string &path, ResourceCategory category=ResourceCategory::System)
 
bool PreloadSprite (const std::string &id, const std::string &path, ResourceCategory category=ResourceCategory::GameEntity)
 
SpriteGetTexture (const std::string &id) const
 
SpriteGetSprite (const std::string &id, const std::string &path, ResourceCategory category=ResourceCategory::GameEntity)
 
bool GetSprite_data (const std::string &id, const std::string &path, VisualSprite_data &outData)
 
bool GetSpriteEditor_data (const std::string &id, const std::string &path, VisualEditor_data &outData)
 
bool ReleaseResource (const std::string &id)
 
void UnloadAll ()
 
bool HasResource (const std::string &id) const
 
std::vector< std::string > ListResourcesByType (ResourceType type) const
 
std::vector< std::string > ListResourcesByCategory (ResourceCategory category) const
 
bool SaveJSONForObject (const std::string &videogameName, const std::string &objectName, const std::string &jsonContent) const
 
bool LoadJSONForObject (const std::string &videogameName, const std::string &objectName, std::string &outJson) const
 
bool SaveTextFile (const std::string &filepath, const std::string &content) const
 
bool LoadTextFile (const std::string &filepath, std::string &outContent) const
 
bool EnsureDirectoryExists (const std::string &dirpath) const
 
bool PreloadSystemResources (const std::string &configFilePath)
 
PreloadStats PreloadTextures (const std::vector< std::string > &paths, ResourceCategory category=ResourceCategory::Level, bool enableFallbackScan=true)
 
PreloadStats PreloadSprites (const std::vector< std::string > &paths, ResourceCategory category=ResourceCategory::GameEntity, bool enableFallbackScan=true)
 
PreloadStats PreloadAudioFiles (const std::vector< std::string > &paths, bool enableFallbackScan=true)
 
PreloadStats PreloadTilesets (const std::vector< TilesetInfo > &tilesets, bool enableFallbackScan=true)
 
std::string FindResourceRecursive (const std::string &filename, const std::string &rootDir="GameData") const
 
std::string ResolveFilePath (const std::string &relativePath) const
 
std::vector< std::string > GetBehaviorTreeFiles (const std::string &directory="./Gamedata") const
 Lists all .bt.json behavior tree files in a directory.
 
std::string SelectBehaviorTreeFile (const std::string &currentPath="") const
 Opens a file browser dialog for selecting a behavior tree file.
 
std::string OpenFilePickerModal (Olympe::FilePickerType fileType, const std::string &currentPath="")
 Opens a centralized file picker modal for the specified file type.
 
void RenderFilePickerModal ()
 Renders the file picker modal if one is open.
 
bool IsFilePickerModalOpen () const
 Checks if the file picker modal is currently visible.
 
void CloseFilePickerModal ()
 Closes the file picker modal without user selection.
 
std::string GetSelectedFileFromModal () const
 Retrieves the selected file from the file picker modal.
 
void OpenSaveFilePickerModal (Olympe::SaveFileType fileType, const std::string &directory, const std::string &suggestedFilename="")
 Opens the Save As file picker modal.
 
void RenderSaveFilePickerModal ()
 Renders the Save As file picker modal UI.
 
bool IsSaveFilePickerModalOpen () const
 Checks if the Save As file picker modal is currently visible.
 
void CloseSaveFilePickerModal ()
 Closes the Save As file picker modal.
 
std::string GetSelectedSaveFile () const
 Retrieves the selected file from the Save As modal.
 

Static Public Member Functions

static DataManagerGetInstance ()
 
static DataManagerGet ()
 
static std::string BuildGameDataPath (const std::string &videogameName, const std::string &objectName)
 

Private Member Functions

std::string FindResourceRecursive_Unix (const std::string &filename, const std::string &rootDir) const
 

Private Attributes

std::string name
 
std::mutex m_mutex_
 
std::unordered_map< std::string, std::shared_ptr< Resource > > m_resources_
 
bool m_enableFallbackScan = true
 
std::unique_ptr< Olympe::FilePickerModalm_filePickerModal
 
std::unique_ptr< Olympe::SaveFilePickerModalm_saveFilePickerModal
 

Detailed Description

Definition at line 83 of file DataManager.h.

Constructor & Destructor Documentation

◆ DataManager()

DataManager::DataManager ( )

Definition at line 43 of file DataManager.cpp.

References name, and SYSTEM_LOG.

◆ ~DataManager()

DataManager::~DataManager ( )
virtual

Definition at line 49 of file DataManager.cpp.

References SYSTEM_LOG, and UnloadAll().

+ Here is the call graph for this function:

Member Function Documentation

◆ BuildGameDataPath()

std::string DataManager::BuildGameDataPath ( const std::string &  videogameName,
const std::string &  objectName 
)
static

Definition at line 301 of file DataManager.cpp.

References GetComponentTypeID_Static().

Referenced by LoadJSONForObject(), and SaveJSONForObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CloseFilePickerModal()

void DataManager::CloseFilePickerModal ( )

Closes the file picker modal without user selection.

Definition at line 999 of file DataManager.cpp.

References m_filePickerModal.

◆ CloseSaveFilePickerModal()

void DataManager::CloseSaveFilePickerModal ( )

Closes the Save As file picker modal.

Definition at line 1049 of file DataManager.cpp.

References m_saveFilePickerModal.

◆ EnsureDirectoryExists()

bool DataManager::EnsureDirectoryExists ( const std::string &  dirpath) const

Definition at line 354 of file DataManager.cpp.

References GetComponentTypeID_Static(), and SYSTEM_LOG.

Referenced by SaveTextFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FindResourceRecursive()

std::string DataManager::FindResourceRecursive ( const std::string &  filename,
const std::string &  rootDir = "GameData" 
) const

Definition at line 689 of file DataManager.cpp.

References FindResourceRecursive_Unix(), and GetComponentTypeID_Static().

Referenced by World::InstantiatePass1_VisualLayers(), TilesetManager::LoadTilesets(), PreloadSprites(), PreloadTextures(), PreloadTilesets(), and ResolveFilePath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FindResourceRecursive_Unix()

std::string DataManager::FindResourceRecursive_Unix ( const std::string &  filename,
const std::string &  rootDir 
) const
private

Definition at line 744 of file DataManager.cpp.

References FindResourceRecursive_Unix(), GetComponentTypeID_Static(), and name.

Referenced by FindResourceRecursive(), and FindResourceRecursive_Unix().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Get()

static DataManager & DataManager::Get ( )
inlinestatic

◆ GetBehaviorTreeFiles()

std::vector< std::string > DataManager::GetBehaviorTreeFiles ( const std::string &  directory = "./Gamedata") const

Lists all .bt.json behavior tree files in a directory.

Parameters
directoryDirectory to search (e.g., "Gamedata/BehaviorTree")
Returns
Vector of .bt.json filenames found in directory

Definition at line 864 of file DataManager.cpp.

References GetComponentTypeID_Static(), and SYSTEM_LOG.

Referenced by SelectBehaviorTreeFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetInstance()

DataManager & DataManager::GetInstance ( )
static

Definition at line 56 of file DataManager.cpp.

References GetComponentTypeID_Static().

Referenced by Get(), and GameEngine::Initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetSelectedFileFromModal()

std::string DataManager::GetSelectedFileFromModal ( ) const

Retrieves the selected file from the file picker modal.

Returns
Selected file path if user confirmed and modal has a selection, empty string otherwise

Call this after IsFilePickerModalOpen() returns false to check if user selected a file.

Example usage: if (DataManager::Get().IsFilePickerModalOpen() == false && wasOpen) { std::string file = DataManager::Get().GetSelectedFileFromModal(); if (!file.empty()) { // Process selected file } }

Definition at line 1007 of file DataManager.cpp.

References m_filePickerModal.

Referenced by Olympe::BTNodePropertyPanel::RenderSubGraphControls().

+ Here is the caller graph for this function:

◆ GetSelectedSaveFile()

std::string DataManager::GetSelectedSaveFile ( ) const

Retrieves the selected file from the Save As modal.

Returns
Full file path with extension if user confirmed, empty string otherwise

Only valid after IsSaveFilePickerModalOpen() returns false and user confirmed.

Definition at line 1057 of file DataManager.cpp.

References m_saveFilePickerModal.

◆ GetSprite()

Sprite * DataManager::GetSprite ( const std::string &  id,
const std::string &  path,
ResourceCategory  category = ResourceCategory::GameEntity 
)

◆ GetSprite_data()

bool DataManager::GetSprite_data ( const std::string &  id,
const std::string &  path,
VisualSprite_data outData 
)

Definition at line 191 of file DataManager.cpp.

References GameEntity, GetComponentTypeID_Static(), GetSprite(), and SYSTEM_LOG.

+ Here is the call graph for this function:

◆ GetSpriteEditor_data()

bool DataManager::GetSpriteEditor_data ( const std::string &  id,
const std::string &  path,
VisualEditor_data outData 
)

Definition at line 207 of file DataManager.cpp.

References GameEntity, GetComponentTypeID_Static(), GetSprite(), and SYSTEM_LOG.

+ Here is the call graph for this function:

◆ GetTexture()

SDL_Texture * DataManager::GetTexture ( const std::string &  id) const

Definition at line 138 of file DataManager.cpp.

References GetComponentTypeID_Static(), m_mutex_, m_resources_, GameEngine::renderer, renderer, and SYSTEM_LOG.

Referenced by GetSprite(), and OlympeAnimation::AnimationBank::ParseJSON().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasResource()

bool DataManager::HasResource ( const std::string &  id) const

Definition at line 268 of file DataManager.cpp.

References GetComponentTypeID_Static(), m_mutex_, and m_resources_.

+ Here is the call graph for this function:

◆ Initialize()

void DataManager::Initialize ( )

Definition at line 62 of file DataManager.cpp.

References SYSTEM_LOG.

Referenced by SDL_AppInit().

+ Here is the caller graph for this function:

◆ IsFilePickerModalOpen()

bool DataManager::IsFilePickerModalOpen ( ) const

Checks if the file picker modal is currently visible.

Returns
True if modal is open and waiting for user interaction

Definition at line 991 of file DataManager.cpp.

References m_filePickerModal.

Referenced by Olympe::BTNodePropertyPanel::RenderSubGraphControls().

+ Here is the caller graph for this function:

◆ IsSaveFilePickerModalOpen()

bool DataManager::IsSaveFilePickerModalOpen ( ) const

Checks if the Save As file picker modal is currently visible.

Definition at line 1040 of file DataManager.cpp.

References m_saveFilePickerModal.

◆ ListResourcesByCategory()

std::vector< std::string > DataManager::ListResourcesByCategory ( ResourceCategory  category) const

Definition at line 287 of file DataManager.cpp.

References GetComponentTypeID_Static(), m_mutex_, and m_resources_.

+ Here is the call graph for this function:

◆ ListResourcesByType()

std::vector< std::string > DataManager::ListResourcesByType ( ResourceType  type) const

Definition at line 274 of file DataManager.cpp.

References GetComponentTypeID_Static(), m_mutex_, and m_resources_.

+ Here is the call graph for this function:

◆ LoadJSONForObject()

bool DataManager::LoadJSONForObject ( const std::string &  videogameName,
const std::string &  objectName,
std::string &  outJson 
) const

Definition at line 348 of file DataManager.cpp.

References BuildGameDataPath(), GetComponentTypeID_Static(), and LoadTextFile().

+ Here is the call graph for this function:

◆ LoadTextFile()

bool DataManager::LoadTextFile ( const std::string &  filepath,
std::string &  outContent 
) const

Definition at line 330 of file DataManager.cpp.

References GetComponentTypeID_Static().

Referenced by LoadJSONForObject(), and PreloadSystemResources().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OpenFilePickerModal()

std::string DataManager::OpenFilePickerModal ( Olympe::FilePickerType  fileType,
const std::string &  currentPath = "" 
)

Opens a centralized file picker modal for the specified file type.

Parameters
fileTypeType of files to browse (BehaviorTree, SubGraph, Audio, etc.)
currentPathOptional current path to display initially
Returns
Selected file path if user confirmed, empty string if cancelled

This method manages a centralized modal dialog that supports multiple file types. Call this from UI elements that need file selection, then check the return value to see if user made a selection.

Example usage: std::string selected = DataManager::Get().OpenFilePickerModal( Olympe::FilePickerType::BehaviorTree, "./Gamedata" ); if (!selected.empty()) { // User selected a file nodeProperties["subgraphPath"] = selected; }

Definition at line 964 of file DataManager.cpp.

References GetComponentTypeID_Static(), m_filePickerModal, and SYSTEM_LOG.

Referenced by Olympe::BTNodePropertyPanel::RenderSubGraphControls().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OpenSaveFilePickerModal()

void DataManager::OpenSaveFilePickerModal ( Olympe::SaveFileType  fileType,
const std::string &  directory,
const std::string &  suggestedFilename = "" 
)

Opens the Save As file picker modal.

Parameters
fileTypeType of file to save (BehaviorTree, Blueprint, etc.)
directoryStarting directory path
suggestedFilenameSuggested filename without extension

Extension will be auto-appended based on file type. Call RenderSaveFilePickerModal() every frame. After modal closes, check IsSaveFilePickerModalOpen() and GetSelectedSaveFile().

Definition at line 1020 of file DataManager.cpp.

References GetComponentTypeID_Static(), m_saveFilePickerModal, and SYSTEM_LOG.

+ Here is the call graph for this function:

◆ PreloadAudioFiles()

DataManager::PreloadStats DataManager::PreloadAudioFiles ( const std::vector< std::string > &  paths,
bool  enableFallbackScan = true 
)

◆ PreloadSprite()

bool DataManager::PreloadSprite ( const std::string &  id,
const std::string &  path,
ResourceCategory  category = ResourceCategory::GameEntity 
)

Definition at line 133 of file DataManager.cpp.

References PreloadTexture().

Referenced by GetSprite(), _Sprite::Preload(), PreloadSprites(), and PreloadSystemResources().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PreloadSprites()

DataManager::PreloadStats DataManager::PreloadSprites ( const std::vector< std::string > &  paths,
ResourceCategory  category = ResourceCategory::GameEntity,
bool  enableFallbackScan = true 
)

◆ PreloadSystemResources()

bool DataManager::PreloadSystemResources ( const std::string &  configFilePath)

Definition at line 405 of file DataManager.cpp.

References GameEntity, GetComponentTypeID_Static(), Level, LoadTextFile(), PreloadSprite(), PreloadTexture(), System, and SYSTEM_LOG.

Referenced by GameEngine::Initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PreloadTexture()

bool DataManager::PreloadTexture ( const std::string &  id,
const std::string &  path,
ResourceCategory  category = ResourceCategory::System 
)

Definition at line 74 of file DataManager.cpp.

References GetComponentTypeID_Static(), m_mutex_, m_resources_, GameEngine::renderer, renderer, SYSTEM_LOG, and Texture.

Referenced by OlympeAnimation::AnimationBank::ParseJSON(), PreloadSprite(), PreloadSystemResources(), PreloadTextures(), and PreloadTilesets().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PreloadTextures()

DataManager::PreloadStats DataManager::PreloadTextures ( const std::vector< std::string > &  paths,
ResourceCategory  category = ResourceCategory::Level,
bool  enableFallbackScan = true 
)

◆ PreloadTilesets()

DataManager::PreloadStats DataManager::PreloadTilesets ( const std::vector< TilesetInfo > &  tilesets,
bool  enableFallbackScan = true 
)

◆ ReleaseResource()

bool DataManager::ReleaseResource ( const std::string &  id)

Definition at line 222 of file DataManager.cpp.

References GetComponentTypeID_Static(), m_mutex_, m_resources_, and SYSTEM_LOG.

+ Here is the call graph for this function:

◆ RenderFilePickerModal()

void DataManager::RenderFilePickerModal ( )

Renders the file picker modal if one is open.

Call this every frame within the main ImGui rendering loop to display the modal UI. This is automatically called by the editor UI systems that integrate with DataManager.

Definition at line 983 of file DataManager.cpp.

References m_filePickerModal.

Referenced by Olympe::BehaviorTreeRenderer::Render().

+ Here is the caller graph for this function:

◆ RenderSaveFilePickerModal()

void DataManager::RenderSaveFilePickerModal ( )

Renders the Save As file picker modal UI.

Must be called every frame during the main ImGui rendering loop.

Definition at line 1032 of file DataManager.cpp.

References m_saveFilePickerModal.

◆ ResolveFilePath()

std::string DataManager::ResolveFilePath ( const std::string &  relativePath) const

Definition at line 793 of file DataManager.cpp.

References FindResourceRecursive(), GetComponentTypeID_Static(), and SYSTEM_LOG.

Referenced by Olympe::VisualScriptRenderer::ResolvePath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SaveJSONForObject()

bool DataManager::SaveJSONForObject ( const std::string &  videogameName,
const std::string &  objectName,
const std::string &  jsonContent 
) const

Definition at line 342 of file DataManager.cpp.

References BuildGameDataPath(), GetComponentTypeID_Static(), and SaveTextFile().

+ Here is the call graph for this function:

◆ SaveTextFile()

bool DataManager::SaveTextFile ( const std::string &  filepath,
const std::string &  content 
) const

Definition at line 309 of file DataManager.cpp.

References EnsureDirectoryExists(), GetComponentTypeID_Static(), and SYSTEM_LOG.

Referenced by SaveJSONForObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SelectBehaviorTreeFile()

std::string DataManager::SelectBehaviorTreeFile ( const std::string &  currentPath = "") const

Opens a file browser dialog for selecting a behavior tree file.

Parameters
currentPathOptional current path to display initially
Returns
Selected file path (absolute or relative), empty string if cancelled

This is a framework-level service providing reusable file browsing for SubGraph node path selection and other file operations.

Definition at line 921 of file DataManager.cpp.

References GetBehaviorTreeFiles(), GetComponentTypeID_Static(), and SYSTEM_LOG.

+ Here is the call graph for this function:

◆ Shutdown()

void DataManager::Shutdown ( )

Definition at line 68 of file DataManager.cpp.

References SYSTEM_LOG, and UnloadAll().

Referenced by SDL_AppQuit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UnloadAll()

void DataManager::UnloadAll ( )

Definition at line 247 of file DataManager.cpp.

References GetComponentTypeID_Static(), m_mutex_, and m_resources_.

Referenced by Shutdown(), and ~DataManager().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_enableFallbackScan

bool DataManager::m_enableFallbackScan = true
private

Definition at line 353 of file DataManager.h.

Referenced by PreloadSprites(), PreloadTextures(), and PreloadTilesets().

◆ m_filePickerModal

std::unique_ptr<Olympe::FilePickerModal> DataManager::m_filePickerModal
private

◆ m_mutex_

std::mutex DataManager::m_mutex_
mutableprivate

◆ m_resources_

std::unordered_map<std::string, std::shared_ptr<Resource> > DataManager::m_resources_
private

◆ m_saveFilePickerModal

std::unique_ptr<Olympe::SaveFilePickerModal> DataManager::m_saveFilePickerModal
private

◆ name

std::string DataManager::name
private

Definition at line 350 of file DataManager.h.

Referenced by DataManager(), and FindResourceRecursive_Unix().


The documentation for this class was generated from the following files: