diff --git a/CHANGELOG.md b/CHANGELOG.md index f54258b..af5eb02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,13 +4,14 @@ All notable changes to [ChaiLove](https://github.com/RobLoach/ChaiLove) will be The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## 0.28.1 - Unreleased +## 0.29.0 - Unreleased ### Fixes - Fixed `/libretro/saves` mounting ### Features - Added `string::trim()` - Added `string::split()` +- Adds loading of `conf.chai` for the `conf()` callback ## 0.28.0 - 2018-10-07 ### Features diff --git a/examples/benchmark/conf.chai b/examples/benchmark/conf.chai new file mode 100644 index 0000000..fb2e787 --- /dev/null +++ b/examples/benchmark/conf.chai @@ -0,0 +1,8 @@ +/** + * ChaiLove callback; Configure the application. + */ +def conf(t) { + t.window.width = 720 + t.window.height = 680 + t.console = true +} diff --git a/examples/benchmark/main.chai b/examples/benchmark/main.chai index 697fd6d..b7e899e 100644 --- a/examples/benchmark/main.chai +++ b/examples/benchmark/main.chai @@ -7,15 +7,6 @@ global sprites = List() global img global music -/** - * ChaiLove callback; Configure the application. - */ -def conf(t) { - t.window.width = 720 - t.window.height = 680 - t.console = true -} - /** * ChaiLove callback; Load the application. */ @@ -94,8 +85,8 @@ class Sprite { def Sprite() { this.x = love.math.random(love.graphics.getWidth()) * 1.0f this.y = love.math.random(love.graphics.getHeight()) * 1.0f - this.xspeed = love.math.random(10) * 50.0f - this.yspeed = love.math.random(10) * 50.0f + this.xspeed = love.math.random(-10, 10) * 50 + this.yspeed = love.math.random(-10, 10) * 50 } def draw() { @@ -124,32 +115,3 @@ class Sprite { } } }; - -def loadstate(data) { - print("Load State") - print(data) - var info = from_json(data) - var num = info["number"] - - // Do something with the loaded number. - sprites.clear() - for (var i = 0; i < num; ++i) { - sprites.push_back(Sprite()) - } - - // The state loaded correctly, so return true. - return true -} - -def savestate() { - // Retrieve the number to save. - var num = sprites.size() - - // Construct the JSON data. - var data = ["number": num] - print("Save State") - print(to_json(data)) - - // Tell the system to save the JSON data. - return to_json(data) -} diff --git a/examples/pong/conf.chai b/examples/pong/conf.chai new file mode 100644 index 0000000..a335539 --- /dev/null +++ b/examples/pong/conf.chai @@ -0,0 +1,9 @@ +/** + * ChaiLove callback; Configure the application. + */ +def conf(t) { + t.window.width = 640 + t.window.height = 480 + //t.modules.sound = false + t.console = true +} diff --git a/examples/pong/main.chai b/examples/pong/main.chai index e810b7a..6932796 100644 --- a/examples/pong/main.chai +++ b/examples/pong/main.chai @@ -5,16 +5,6 @@ global players = [] global pongSound global ball -/** - * ChaiLove callback; Configure the application. - */ -def conf(t) { - t.window.width = 640 - t.window.height = 480 - //t.modules.sound = false - t.console = true -} - /** * ChaiLove callback; Load the application. */ @@ -29,7 +19,6 @@ def load() { Player(false, 80.0f, love.graphics.getHeight() / 2.0f), Player(true, love.graphics.getWidth() - 80.0f, love.graphics.getHeight() / 2.0f) ] - } /** diff --git a/src/libretro.cpp b/src/libretro.cpp index 3dc4f05..67de394 100644 --- a/src/libretro.cpp +++ b/src/libretro.cpp @@ -225,8 +225,8 @@ void retro_set_controller_port_device(unsigned port, unsigned device) { * libretro callback; Return the amount of bytes required to save a state. */ size_t retro_serialize_size(void) { - // Save states will be 5 kilobytes. - return 5000; + // Save states will be 8 KB. + return 8192; } /** diff --git a/src/love/script.cpp b/src/love/script.cpp index 3be280b..9576853 100644 --- a/src/love/script.cpp +++ b/src/love/script.cpp @@ -58,7 +58,7 @@ bool script::loadModule(const std::string& moduleName) { bool script::loadModuleRequire(const std::string& moduleName) { // Check if the module has already been loaded. - std::string filename = replaceString(moduleName, ".", "/"); + std::string filename = replaceString(replaceString(moduleName, ".chai", ""), ".", "/"); if (std::find(m_requiremodules.begin(), m_requiremodules.end(), filename) != m_requiremodules.end()) { return true; } @@ -438,12 +438,13 @@ script::script(const std::string& file) { // Load the main.chai file. ::filesystem::path p(file.c_str()); std::string extension(p.extension()); + loadModuleRequire("conf"); if (extension == "chailove" || extension == "chaigame") { - mainLoaded = loadModule("main.chai"); + mainLoaded = loadModuleRequire("main"); } else { // Otherwise, load the actual file. std::string filename(p.filename()); - mainLoaded = loadModule(filename); + mainLoaded = loadModuleRequire(filename); } } diff --git a/test/unittests/conf.chai b/test/unittests/conf.chai new file mode 100644 index 0000000..0d7f7dd --- /dev/null +++ b/test/unittests/conf.chai @@ -0,0 +1,8 @@ +global confTestLoaded = false + +def conf(t) { + t.console = true + t.window.width = 640 + t.window.height = 500 + confTestLoaded = true +} diff --git a/test/unittests/main.chai b/test/unittests/main.chai index f215f3f..ded5cf1 100644 --- a/test/unittests/main.chai +++ b/test/unittests/main.chai @@ -1,11 +1,5 @@ global failure = "" -def conf(t) { - t.console = true - t.window.width = 640 - t.window.height = 500 -} - def load() { print("\n================================\n") print("ChaiLove: Unit Testing Framework\n") diff --git a/test/unittests/system.chai b/test/unittests/system.chai index 89dec45..26d7c2b 100644 --- a/test/unittests/system.chai +++ b/test/unittests/system.chai @@ -42,6 +42,14 @@ assert_equal(trimSubject.trim(), "Hello World!", "string::trim()") var splitTest = "Hello|How|Are|You" var splitResult = splitTest.split("|") assert_equal(splitResult[1], "How", "string::split()") -splitTest = "Rob, John, Loach" +splitTest = "Hello, World, Time" splitResult = splitTest.split(", ") -assert_equal(splitResult[1], "John", " - commas") +assert_equal(splitResult[1], "World", " - commas") + +// conf.chai +var objs = get_objects() +var confTestLoadedExists = objs["confTestLoaded"].get_type_info().bare_equal(bool_type) +assert(confTestLoadedExists, "conf.chai is loaded") +if (confTestLoadedExists) { + assert(confTestLoaded, "conf() called") +}