1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 08:39:30 +00:00

Add anselme version check in game config, rename version to "game version"

This commit is contained in:
Étienne Fildadut 2021-06-05 17:26:02 +02:00
parent d42c35facd
commit 0e755ea841
2 changed files with 10 additions and 6 deletions

View file

@ -203,8 +203,9 @@ local vm_mt = {
-- will load in path, in order:
-- * config.ans, which will be executed in the "config" namespace and may contains various optional configuration options:
-- * language: string, built-in language file to load
-- * version: any, version information of the game. Can be used to perform eventual migration of save with an old version in the main file.
-- Always included in saved variables.
-- * anselme version: number, version of the anselme language this game was made for
-- * game version: any, version information of the game. Can be used to perform eventual migration of save with an old version in the main file.
-- Always included in saved variables.
-- * main file: string, name (without .ans extension) of a file that will be loaded into the root namespace and ran when starting the game
-- * main file, if defined in config.ans
-- * every other file in the path and subdirectories, using their path as namespace (i.e., contents of path/world1/john.ans will be defined in a function world1.john)
@ -222,12 +223,17 @@ local vm_mt = {
-- get config
self.game = {
language = self:eval("config.language"),
version = self:eval("config.version"),
anselme_version = self:eval("config.anselme version"),
game_version = self:eval("config.game version"),
main_file = self:eval("config.main file"),
main_block = nil
}
-- check language version
if self.game.anselme_version and self.game.anselme_version ~= anselme.versions.language then
return nil, ("trying to load game made for Anselme language %s, but currently using version %s"):format(self.game.anselme_version, anselme.versions.language)
end
-- force merging version into state
local interpreter, err = self:run("config.version")
local interpreter, err = self:run("config.game version")
if not interpreter then return interpreter, err end
interpreter:step()
-- load language

View file

@ -57,5 +57,3 @@ Disadvantages:
* could do something like `$ ()(l::list(?), i::number)::?`, but then can't return nil on not found...
TODO: ensure that most stuff in the state stays consistent after an error was thrown
TODO: way to migrate save files