mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
Implemented CardList
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@23 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -50,9 +50,15 @@ String Package::name() const {
|
||||
else if ( ext == String::npos) return filename.substr(slash+1);
|
||||
else return filename.substr(slash+1, ext-slash-1);
|
||||
}
|
||||
String Package::fullName() const {
|
||||
return name();
|
||||
}
|
||||
const String& Package::absoluteFilename() const {
|
||||
return filename;
|
||||
}
|
||||
InputStreamP Package::openIconFile() {
|
||||
return InputStreamP();
|
||||
}
|
||||
|
||||
|
||||
void Package::open(const String& n) {
|
||||
|
||||
@@ -51,9 +51,14 @@ class Package {
|
||||
bool needSaveAs() const;
|
||||
/// Determines the short name of this package: the filename without path or extension
|
||||
String name() const;
|
||||
/// Return the full name of this package, by default equal to name()
|
||||
virtual String fullName() const;
|
||||
/// Return the absolute filename of this file
|
||||
const String& absoluteFilename() const;
|
||||
|
||||
/// Get an input stream for the package icon, if there is any
|
||||
virtual InputStreamP openIconFile();
|
||||
|
||||
/// Open a package, should only be called when the package is constructed using the default constructor!
|
||||
/// @pre open not called before [TODO]
|
||||
void open(const String& package);
|
||||
|
||||
@@ -8,11 +8,12 @@
|
||||
|
||||
#include <util/io/package_manager.hpp>
|
||||
#include <util/error.hpp>
|
||||
#include <data/game.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : PackageManager
|
||||
|
||||
String program_dir() {
|
||||
return _("."); //TODO
|
||||
return wxGetCwd(); //TODO
|
||||
}
|
||||
|
||||
PackageManager packages;
|
||||
@@ -36,6 +37,33 @@ PackageManager::PackageManager() {
|
||||
data_directory += _("/data");
|
||||
}
|
||||
|
||||
PackagedP PackageManager::openAny(const String& name) {
|
||||
wxFileName fn(data_directory + _("/") + name);
|
||||
fn.Normalize();
|
||||
String filename = fn.GetFullPath();
|
||||
// Is this package already loaded?
|
||||
PackagedP& p = loaded_packages[filename];
|
||||
if (p) {
|
||||
return p;
|
||||
} else {
|
||||
// load with the right type, based on extension
|
||||
if (fn.GetExt() == _("mse-game")) p = new_shared<Game>();
|
||||
// else if (fn.GetExt() == _("mse-style")) p = new_shared<CardStyle>();
|
||||
// else if (fn.GetExt() == _("mse-locale")) p = new_shared<Locale>();
|
||||
// else if (fn.GetExt() == _("mse-include")) p = new_shared<IncludePackage>();
|
||||
// else if (fn.GetExt() == _("mse-symbol-font")) p = new_shared<SymbolFont>();
|
||||
else {
|
||||
throw PackageError(_("Unrecognized package type: ") + fn.GetExt());
|
||||
}
|
||||
p->open(filename);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
String PackageManager::findFirst(const String& pattern) {
|
||||
return wxFindFirstFile(data_directory + _("/") + pattern, 0);
|
||||
}
|
||||
|
||||
void PackageManager::destroy() {
|
||||
loaded_packages.clear();
|
||||
}
|
||||
@@ -44,9 +44,14 @@ class PackageManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// Open a package with the specified name
|
||||
/// the type of package is determined by its extension!
|
||||
PackagedP openAnyPackage(const String& filename);
|
||||
/// Open a package with the specified name, the type of package is determined by its extension!
|
||||
PackagedP openAny(const String& name);
|
||||
|
||||
/// Find a package whos name matches a pattern
|
||||
/** Find more using wxFindNextFile().
|
||||
* If no package is found returns an empty string.
|
||||
*/
|
||||
String findFirst(const String& pattern);
|
||||
|
||||
/// Empty the list of packages.
|
||||
/** This function MUST be called before the program terminates, otherwise
|
||||
|
||||
Reference in New Issue
Block a user