diff options
Diffstat (limited to 'Stars45/ContentBundle.cpp')
-rw-r--r-- | Stars45/ContentBundle.cpp | 68 |
1 files changed, 64 insertions, 4 deletions
diff --git a/Stars45/ContentBundle.cpp b/Stars45/ContentBundle.cpp index 9f09833..534f550 100644 --- a/Stars45/ContentBundle.cpp +++ b/Stars45/ContentBundle.cpp @@ -18,12 +18,23 @@ // +--------------------------------------------------------------------+ +ContentBundle* ContentBundle::GetInstance() +{ + static ContentBundle instance{}; + return &instance; +} + +// +--------------------------------------------------------------------+ + +ContentBundle::ContentBundle() : ContentBundle("content", nullptr) +{ +} + +// +--------------------------------------------------------------------+ + ContentBundle::ContentBundle(const char* bundle, Locale* locale) { - Text file = FindFile(bundle, locale); - if (file.length() > 0) { - LoadBundle(file); - } + Load(bundle, locale); } // +--------------------------------------------------------------------+ @@ -34,6 +45,55 @@ ContentBundle::~ContentBundle() // +--------------------------------------------------------------------+ +bool +ContentBundle::Init() +{ + DataLoader* loader = DataLoader::GetLoader(); + List<Text> bundles; + + loader->SetDataPath("Content/"); + loader->ListFiles("content*", bundles); + + ListIter<Text> iter = bundles; + while (++iter) { + Text* filename = iter.value(); + int n = filename->indexOf('_'); + if (n > 0) { + Locale::ParseLocale(filename->data() + n); // unused? + } + } + + loader->SetDataPath(0); + return true; +} + +// +--------------------------------------------------------------------+ + +void +ContentBundle::UseLocale(Locale* locale) +{ + DataLoader* loader = DataLoader::GetLoader(); + loader->SetDataPath("Content/"); + Load("content", locale); + loader->SetDataPath(nullptr); +} + +// +--------------------------------------------------------------------+ + +void +ContentBundle::Load(const char* bundle, Locale* locale) +{ + if (values.size() > 0) { + values.clear(); + } + Text file = FindFile(bundle, locale); + if (file.length() > 0) { + LoadBundle(file); + } +} + +// +--------------------------------------------------------------------+ + Text ContentBundle::GetText(const char* key) const { |