summaryrefslogtreecommitdiffhomepage
path: root/Stars45/ContentBundle.cpp
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-02-23 23:13:27 +0100
committerAki <please@ignore.pl>2022-02-23 23:13:27 +0100
commit8b778dda61c45f5d7a4dc416478c42ff4aa1de7f (patch)
tree004ea4bbe7dde92d4632b908de8450cb767549d3 /Stars45/ContentBundle.cpp
parent0052edae47d1e6ae613497c524719eff5838f52a (diff)
downloadstarshatter-8b778dda61c45f5d7a4dc416478c42ff4aa1de7f.zip
starshatter-8b778dda61c45f5d7a4dc416478c42ff4aa1de7f.tar.gz
starshatter-8b778dda61c45f5d7a4dc416478c42ff4aa1de7f.tar.bz2
Moved content management out to ContentBundle
Diffstat (limited to 'Stars45/ContentBundle.cpp')
-rw-r--r--Stars45/ContentBundle.cpp68
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
{