Skip to content
Snippets Groups Projects
Commit f6ee1320 authored by dg's avatar dg
Browse files

modules are remotely instalable

git-svn-id: http://svn.net-core.org/repos/t-engine4@428 51575b47-30f0-44d4-a5cc-537603b46e54
parent 023a0240
No related branches found
No related tags found
No related merge requests found
......@@ -9,16 +9,25 @@ module(..., package.seeall, class.make)
function _M:listModules()
local ms = {}
fs.mount(engine.homepath, "/")
-- print("Search Path: ") for k,e in ipairs(fs.getSearchPath()) do print("*",k,e) end
for i, short_name in ipairs(fs.list("/modules/")) do
--print("!!", short_name)
local dir = "/modules/"..short_name
if fs.exists(dir.."/init.lua") then
local mod = self:loadDefinition(dir)
table.insert(ms, mod)
if mod then
table.insert(ms, mod)
ms[mod.short_name] = mod
end
elseif short_name:find(".team$") then
fs.mount(fs.getRealPath(dir), "/testload", false);
if fs.exists("/testload/init.lua") then
fs.mount(fs.getRealPath(dir), "/testload", false)
if fs.exists("/testload/mod/init.lua") then
local mod = self:loadDefinition("/testload", dir)
table.insert(ms, mod)
if mod then
table.insert(ms, mod)
ms[mod.short_name] = mod
end
end
fs.umount(fs.getRealPath(dir))
end
......@@ -30,14 +39,14 @@ function _M:listModules()
else return a.name < b.name
end
end)
fs.umount(engine.homepath)
-- fs.umount(engine.homepath)
return ms
end
--- Get a module definition from the module init.lua file
function _M:loadDefinition(dir, team)
local mod_def = loadfile(dir.."/init.lua")
local mod_def = loadfile(team and (dir.."/mod/init.lua") or (dir.."/init.lua"))
if mod_def then
-- Call the file body inside its own private environment
local mod = {}
......@@ -46,6 +55,12 @@ function _M:loadDefinition(dir, team)
if not mod.long_name or not mod.name or not mod.short_name or not mod.version or not mod.starter then return end
-- Test engine version
if mod.engine[1] * 1000000 + mod.engine[2] * 1000 + mod.engine[3] > engine.version[1] * 1000000 + engine.version[2] * 1000 + engine.version[3] then
print("Module mismatch engine version", mod.short_name, mod.engine[1] * 1000000 + mod.engine[2] * 1000 + mod.engine[3], engine.version[1] * 1000000 + engine.version[2] * 1000 + engine.version[3])
return
end
-- Make a function to activate it
mod.load = function()
core.display.setWindowTitle(mod.long_name)
......@@ -53,12 +68,11 @@ function _M:loadDefinition(dir, team)
if not team then
fs.mount(fs.getRealPath(dir), "/mod", false)
fs.mount(fs.getRealPath(dir).."/data/", "/data", false)
if fs.exists(dir.."/engine") then fs.mount(fs.getRealPath(dir).."/engine/", "/engine", false) end
else
fs.mount(engine.homepath, "/")
local src = fs.getRealPath(team)
fs.umount(engine.homepath)
fs.mount(src, "/", false)
fs.mount(src, "/mod", false)
end
return require(mod.starter)
end
......@@ -70,13 +84,13 @@ end
--- List all available savefiles
-- Static
function _M:listSavefiles()
fs.mount(engine.homepath, "/tmp/listsaves")
-- fs.mount(engine.homepath, "/tmp/listsaves")
local mods = self:listModules()
for _, mod in ipairs(mods) do
local lss = {}
for i, short_name in ipairs(fs.list("/tmp/listsaves/"..mod.short_name.."/save/")) do
local dir = "/tmp/listsaves/"..mod.short_name.."/save/"..short_name
for i, short_name in ipairs(fs.list("/"..mod.short_name.."/save/")) do
local dir = "/"..mod.short_name.."/save/"..short_name
if fs.exists(dir.."/game.teag") then
local def = self:loadSavefileDescription(dir)
if def then
......@@ -91,7 +105,7 @@ function _M:listSavefiles()
end)
end
fs.umount(engine.homepath)
-- fs.umount(engine.homepath)
return mods
end
......
......@@ -8,7 +8,8 @@ function _M:init(title, url, on_finish)
self.received = 0
self.on_finish = on_finish
engine.Dialog.init(self, title or "Downloading...", 400, 50)
local font = core.display.newFont("/data/font/Vera.ttf", 12)
engine.Dialog.init(self, title or "Downloading...", math.max(400, font:size("From: "..url) + 10), 75, nil, nil, nil, font)
self:keyCommands({
},{
......@@ -36,7 +37,8 @@ function _M:drawDialog(s)
end
end
s:drawString(self.font, "Received: "..self.received, 2, 2, 255, 255, 255)
s:drawString(self.font, "From: "..self.url, 2, 2, 255, 255, 255)
s:drawString(self.font, "Received: "..self.received, 2, 25, 255, 255, 255)
end
function _M:startDownload()
......
......@@ -12,6 +12,9 @@ require "engine.Savefile"
require "engine.Tiles"
engine.Tiles.prefix = "/data/gfx/"
-- Engine Version
engine.version = {1,0,0}
-- Setup the user directory
engine.homepath = fs.getUserPath()..fs.getPathSeparator()..fs.getHomePath()..fs.getPathSeparator().."4.0"
fs.setWritePath(fs.getUserPath())
......
......@@ -57,7 +57,7 @@ function _M:commandLineArgs(args)
end
if req_mod then
local mod = Module:loadDefinition("/modules/"..req_mod)
local mod = self.mod_list[req_mod]
if mod then
local M = mod.load()
_G.game = M.new()
......@@ -99,12 +99,14 @@ function _M:selectStepMain()
self:selectStepLoad()
end,
},
--[[
{
name = "Install a game module",
fct = function()
self:selectStepInstall()
end,
},
]]
{
name = "Exit",
fct = function()
......@@ -199,18 +201,40 @@ end
function _M:selectStepInstall()
local linda, th = Module:loadRemoteList()
local dllist = linda:receive("moduleslist")
local rawdllist = linda:receive("moduleslist")
th:join()
local dllist = {}
for i, mod in ipairs(rawdllist) do
if not self.mod_list[mod.short_name] then
dllist[#dllist+1] = mod
else
local lmod = self.mod_list[mod.short_name]
if mod.version[1] * 1000000 + mod.version[2] * 1000 + mod.version[3] > lmod.version[1] * 1000000 + lmod.version[2] * 1000 + lmod.version[3] then
dllist[#dllist+1] = mod
end
end
end
local display_module = Dialog.new("", self.w * 0.73, self.h, self.w * 0.26, 0, 255)
for i, mod in ipairs(dllist) do
mod.fct = function()
local d = DownloadDialog.new("Downloading: "..mod.long_name, mod.download, function(self, data)
local d = DownloadDialog.new("Downloading: "..mod.long_name, mod.download, function(di, data)
fs.mkdir("/modules")
local f = fs.open("/modules/"..mod.short_name..".team", "w")
for i, v in ipairs(data) do f:write(v) end
f:close()
-- Relist modules and savefiles
self.mod_list = Module:listModules()
self.save_list = Module:listSavefiles()
if self.mod_list[mod.short_name] then
Dialog:simplePopup("Success!", "Your new game is now installed, you can play!", function() self:unregisterDialog(display_module) self:selectStepMain() end)
else
Dialog:simplePopup("Error!", "The downloaded game does not seem to respond to the test. Please contact contact@te4.org")
end
end)
self:registerDialog(d)
d:startDownload()
......
......@@ -8,7 +8,7 @@ function _M:init(runmod)
engine.Dialog.init(self, "Enter your character's name?", 300, 100)
self.runmod = runmod
self.name = ""
self:keyCommands{
self:keyCommands({
_RETURN = function()
if self.name:len() >= 3 then
game:unregisterDialog(self)
......@@ -38,7 +38,11 @@ function _M:init(runmod)
self.changed = true
end
end,
}
},{
EXIT = function()
game:unregisterDialog(self)
end
})
end
function _M:drawDialog(s, w, h)
......
......@@ -1405,6 +1405,26 @@ static int lua_fs_get_path_separator(lua_State *L)
return 1;
}
static int lua_fs_get_search_path(lua_State *L)
{
char **rc = PHYSFS_getSearchPath();
char **i;
int nb = 1;
lua_newtable(L);
for (i = rc; *i != NULL; i++)
{
lua_pushnumber(L, nb);
lua_pushstring(L, *i);
lua_settable(L, -3);
nb++;
}
PHYSFS_freeList(rc);
return 1;
}
static const struct luaL_reg fslib[] =
{
{"open", lua_fs_open},
......@@ -1419,6 +1439,7 @@ static const struct luaL_reg fslib[] =
{"getRealPath", lua_fs_get_real_path},
{"getUserPath", lua_fs_get_user_path},
{"getHomePath", lua_fs_get_home_path},
{"getSearchPath", lua_fs_get_search_path},
{"mount", lua_fs_mount},
{"umount", lua_fs_umount},
{NULL, NULL},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment