mirror of
https://github.com/libretro/libretro-chailove.git
synced 2024-11-23 16:09:59 +00:00
commit
4f5d2bbb29
@ -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
|
||||
|
8
examples/benchmark/conf.chai
Normal file
8
examples/benchmark/conf.chai
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* ChaiLove callback; Configure the application.
|
||||
*/
|
||||
def conf(t) {
|
||||
t.window.width = 720
|
||||
t.window.height = 680
|
||||
t.console = true
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
9
examples/pong/conf.chai
Normal file
9
examples/pong/conf.chai
Normal file
@ -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
|
||||
}
|
@ -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)
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
8
test/unittests/conf.chai
Normal file
8
test/unittests/conf.chai
Normal file
@ -0,0 +1,8 @@
|
||||
global confTestLoaded = false
|
||||
|
||||
def conf(t) {
|
||||
t.console = true
|
||||
t.window.width = 640
|
||||
t.window.height = 500
|
||||
confTestLoaded = true
|
||||
}
|
@ -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")
|
||||
|
@ -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")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user