Unverified Commit 496bdc6b authored by RobLoach's avatar RobLoach
Browse files

Add newFileData

parent 602d6b59
......@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Live updating of core options
- Mounts `/libretro/core` as the directory where the core was loaded from
- Adds `love.filesystem.getSaveDirectory()`
- Adds `love.filesystem.newFileData(contents, name)`
### Fixes
- Fixed loading ChaiLove without active content
......
......@@ -16,6 +16,10 @@ FileData::FileData(const std::string& filepath) : m_filepath(filepath) {
// Nothing.
}
FileData::FileData(const std::string& contents, const std::string& name) : m_contents(contents), m_filepath(name) {
// Nothing.
}
int FileData::getSize() {
ChaiLove* app = ChaiLove::getInstance();
return app->filesystem.getSize(m_filepath);
......@@ -26,8 +30,11 @@ std::string FileData::getFilename() {
}
std::string FileData::getString() {
if (!m_contents.empty()) {
return m_contents;
}
ChaiLove* app = ChaiLove::getInstance();
return app->filesystem.read(m_filepath);
return m_contents = app->filesystem.read(m_filepath);
}
std::string FileData::getExtension() {
......
......@@ -20,6 +20,13 @@ class FileData {
* @param filepath Path to the file.
*/
FileData(const std::string& filepath);
/**
* Creates a new FileData from the given data and filename.
*
* @param contents The data for the file.
* @param name The filename of the file.
*/
FileData(const std::string& contents, const std::string& name);
/**
* The size of the Data in bytes.
......@@ -42,6 +49,7 @@ class FileData {
std::string getExtension();
std::string m_filepath;
std::string m_contents;
};
} // namespace FileSystem
......
......@@ -376,6 +376,11 @@ FileData filesystem::newFileData(const std::string& filepath) {
return f;
}
FileData filesystem::newFileData(const std::string& contents, const std::string& name) {
FileData f(contents, name);
return f;
}
std::string filesystem::getSaveDirectory() {
return "/libretro/saves";
}
......
......@@ -100,6 +100,18 @@ class filesystem {
*/
FileData newFileData(const std::string& filepath);
/**
* Creates a new FileData object.
*
* @param contents The contents fof the file.
* @param name The name of the file.
*
* @return Your new FileData.
*
* @see love::Types::FileSystem::FileData
*/
FileData newFileData(const std::string& contents, const std::string& name);
/**
* Unmounts a zip file or folder previously mounted with love.filesystem.mount.
*
......
......@@ -294,7 +294,8 @@ script::script(const std::string& file) {
chai.add(fun(&filesystem::exists), "exists");
chai.add(fun(&filesystem::getSaveDirectory), "getSaveDirectory");
chai.add(fun(&filesystem::getInfo), "getInfo");
chai.add(fun(&filesystem::newFileData), "newFileData");
chai.add(fun<FileData, filesystem, const std::string&>(&filesystem::newFileData), "newFileData");
chai.add(fun<FileData, filesystem, const std::string&, const std::string&>(&filesystem::newFileData), "newFileData");
chai.add(fun(&filesystem::getDirectoryItems), "getDirectoryItems");
chai.add(fun<bool, filesystem, const std::string&, const std::string&>(&filesystem::mount), "mount");
chai.add(fun<int, filesystem, const std::string&>(&filesystem::getSize), "getSize");
......
......@@ -55,6 +55,8 @@ assert_equal(loadedFileData.getFilename(), "filesystem.chai", " .getFilename(
var fileDataContents = loadedFileData.getString()
var fileDataFind = fileDataContents.find("// newFileData()")
assert_greater(fileDataFind, 50, " .getString()")
var newFileData = love.filesystem.newFileData("Hello World!", "helloworld.txt")
assert_equal(newFileData.getString(), "Hello World!", " newFileData.getString()")
// getSaveDirectory()
assert_equal(love.filesystem.getSaveDirectory(), "/libretro/saves", "love.filesystem.getSaveDirectory()")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment