diff options
author | David Walter Seikel | 2014-06-01 18:42:37 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-06-01 18:42:37 +1000 |
commit | f0cce6bd0e7bfafcaf91df0dccd16f43cba1ea4b (patch) | |
tree | fcb1688da21eca15a7334e04dfd1cb029450d2db /lib | |
parent | TODO++ (diff) | |
download | SledjHamr-f0cce6bd0e7bfafcaf91df0dccd16f43cba1ea4b.zip SledjHamr-f0cce6bd0e7bfafcaf91df0dccd16f43cba1ea4b.tar.gz SledjHamr-f0cce6bd0e7bfafcaf91df0dccd16f43cba1ea4b.tar.bz2 SledjHamr-f0cce6bd0e7bfafcaf91df0dccd16f43cba1ea4b.tar.xz |
Get the from disk sim loading to work.
Still an odd problem with sonic that doesn't make sense.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/scenriLua.lua | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/scenriLua.lua b/lib/scenriLua.lua new file mode 100644 index 0000000..1b9f010 --- /dev/null +++ b/lib/scenriLua.lua | |||
@@ -0,0 +1,62 @@ | |||
1 | --[[ scenriLua - In world objects as skang Things. | ||
2 | |||
3 | TODO - Yes I know this breaks our design goals, | ||
4 | but it's the easy way to quickly whip up in world object loading. | ||
5 | Later a C + eet version will be written to fit our design, | ||
6 | and this Lua based version will be kept. | ||
7 | The system should "compile" Lua based files to eet as well. | ||
8 | For now Lua based files is easier to debug. | ||
9 | |||
10 | ]] | ||
11 | |||
12 | do | ||
13 | local skang = require 'skang' | ||
14 | -- This module has no default skin, it creates no windows. | ||
15 | local _M = skang.moduleBegin('scenriLua', nil, 'Copyright 2014 David Seikel', '0.1', '2014-06-01 13:23:00') | ||
16 | |||
17 | MeshType = {} | ||
18 | TextureType = {} | ||
19 | |||
20 | loadSim = function(sim) | ||
21 | local file = sim .. '/index.omg' | ||
22 | print('Loading sim from file ' .. file) | ||
23 | |||
24 | -- TODO - Stuffs should be local, but externally loaded functions can't access locals it seems. | ||
25 | Stuffs = {} | ||
26 | local simData, err = loadfile(file) | ||
27 | |||
28 | if simData then | ||
29 | setfenv(simData, getfenv(1)) | ||
30 | simData() | ||
31 | if Stuffs.details and Stuffs.details.stuffs then | ||
32 | local simStuffs = Stuffs | ||
33 | |||
34 | for k, v in pairs(simStuffs.details.stuffs) do | ||
35 | file = sim .. '/' .. v.fileName | ||
36 | print('Rezzing ' .. file) | ||
37 | simData, err = loadfile(file) | ||
38 | if simData then | ||
39 | setfenv(simData, getfenv(1)) | ||
40 | simData() | ||
41 | if Stuffs.details and Stuffs.details.Mesh then | ||
42 | local eStuffs = addStuffs(Stuffs.uuid, Stuffs.name, Stuffs.description, | ||
43 | Stuffs.owner, v.fileName, MeshType[Stuffs.details.Mesh.kind], | ||
44 | v.pos[1], v.pos[2], v.pos[3], v.rot[1], v.rot[2], v.rot[3], v.rot[4]) | ||
45 | if eStuffs then | ||
46 | addMaterial(eStuffs, -1, TextureType[Stuffs.details.Mesh.materials[0].kind ], Stuffs.details.Mesh.materials[0].texture) | ||
47 | stuffsSetup(eStuffs, Stuffs.fake) | ||
48 | end | ||
49 | end | ||
50 | elseif 'cannot open ' ~= string.sub(err, 1, 12) then | ||
51 | print("ERROR - " .. err) | ||
52 | end | ||
53 | end | ||
54 | end | ||
55 | elseif 'cannot open ' ~= string.sub(err, 1, 12) then | ||
56 | print("ERROR - " .. err) | ||
57 | end | ||
58 | end | ||
59 | skang.thingasm('loadSim', 'Load a sim.', loadSim, 'string') | ||
60 | |||
61 | skang.moduleEnd(_M) | ||
62 | end | ||