aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/scenriLua.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lib/scenriLua.lua')
-rw-r--r--lib/scenriLua.lua74
1 files changed, 52 insertions, 22 deletions
diff --git a/lib/scenriLua.lua b/lib/scenriLua.lua
index 1b9f010..30ff7f0 100644
--- a/lib/scenriLua.lua
+++ b/lib/scenriLua.lua
@@ -19,7 +19,6 @@ do
19 19
20 loadSim = function(sim) 20 loadSim = function(sim)
21 local file = sim .. '/index.omg' 21 local file = sim .. '/index.omg'
22 print('Loading sim from file ' .. file)
23 22
24 -- TODO - Stuffs should be local, but externally loaded functions can't access locals it seems. 23 -- TODO - Stuffs should be local, but externally loaded functions can't access locals it seems.
25 Stuffs = {} 24 Stuffs = {}
@@ -29,34 +28,65 @@ do
29 setfenv(simData, getfenv(1)) 28 setfenv(simData, getfenv(1))
30 simData() 29 simData()
31 if Stuffs.details and Stuffs.details.stuffs then 30 if Stuffs.details and Stuffs.details.stuffs then
32 local simStuffs = Stuffs 31 local count = 0
33 32 -- Lua is useless sometimes.
34 for k, v in pairs(simStuffs.details.stuffs) do 33 for k, v in pairs(Stuffs.details.stuffs) do
35 file = sim .. '/' .. v.fileName 34 count = count + 1
36 print('Rezzing ' .. file) 35 end
37 simData, err = loadfile(file) 36 preallocateStuffs(count)
38 if simData then 37 for k, v in pairs(Stuffs.details.stuffs) do
39 setfenv(simData, getfenv(1)) 38 partFillStuffs(k, v.fileName, v.pos[1], v.pos[2], v.pos[3], v.rot[1], v.rot[2], v.rot[3], v.rot[4])
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 39 end
54 end 40 end
55 elseif 'cannot open ' ~= string.sub(err, 1, 12) then 41 elseif 'cannot open ' ~= string.sub(err, 1, 12) then
56 print("ERROR - " .. err) 42 print("ERROR - " .. err)
57 end 43 end
44 print('Loaded sim from file ' .. file)
58 end 45 end
59 skang.thingasm('loadSim', 'Load a sim.', loadSim, 'string') 46 skang.thingasm('loadSim', 'Load a sim.', loadSim, 'string')
60 47
48 finishLoadStuffs = function(sim, stuffs)
49 local file = sim .. '/' .. stuffs
50 local name = string.sub(stuffs, 1, -5)
51 simData, err = loadfile(file)
52 if simData then
53 setfenv(simData, getfenv(1))
54 simData()
55 if Stuffs.details and Stuffs.details.Mesh then
56 local meshFile = Stuffs.details.Mesh.fileName or stuffs
57 local eStuffs = finishStuffs(Stuffs.uuid, Stuffs.name, name, Stuffs.description, Stuffs.owner, meshFile, MeshType[Stuffs.details.Mesh.kind], Stuffs.fake)
58 if eStuffs then
59 addMaterial(eStuffs, -1, TextureType[Stuffs.details.Mesh.materials[0].kind ], Stuffs.details.Mesh.materials[0].texture)
60 end
61 end
62 elseif 'cannot open ' ~= string.sub(err, 1, 12) then
63 print("ERROR - " .. err)
64 end
65 end
66 skang.thingasm('finishLoadStuffs', 'Finish loading a stuffs.', finishLoadStuffs, 'string,string')
67
68 loadStuffs = function(sim, stuffs)
69 local file = sim .. '/' .. stuffs
70 print('Rezzing ' .. file)
71 simData, err = loadfile(file)
72 if simData then
73 setfenv(simData, getfenv(1))
74 simData()
75 if Stuffs.details and Stuffs.details.Mesh then
76 local meshFile = Stuffs.details.Mesh.fileName or v.fileName
77 local eStuffs = addStuffs(Stuffs.uuid, Stuffs.name, Stuffs.description,
78 Stuffs.owner, v.fileName, MeshType[Stuffs.details.Mesh.kind],
79 v.pos[1], v.pos[2], v.pos[3], v.rot[1], v.rot[2], v.rot[3], v.rot[4])
80 if eStuffs then
81 addMaterial(eStuffs, -1, TextureType[Stuffs.details.Mesh.materials[0].kind ], Stuffs.details.Mesh.materials[0].texture)
82 stuffsSetup(eStuffs, Stuffs.fake)
83 end
84 end
85 elseif 'cannot open ' ~= string.sub(err, 1, 12) then
86 print("ERROR - " .. err)
87 end
88 end
89 skang.thingasm('loadStuffs', 'Load a stuffs.', loadStuffs, 'string')
90
61 skang.moduleEnd(_M) 91 skang.moduleEnd(_M)
62end 92end