-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_model.lua
67 lines (51 loc) · 1.61 KB
/
test_model.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
local term = term
local args = { ... }
--- Load a model from its textual description.
-- @param text The textual definition of the model
-- @param name (Optional) The name of the model, useful for debugging
-- @return The loaded model
local function parse_model( text, name )
local fn, err = loadstring( text, name or "model" )
if not fn then
error( "Failed to parse model " .. tostring( name ) .. ": " .. err, 2 )
end
local ok, model = pcall( fn )
if not ok then
error( "Failed to load model " .. tostring( name ) .. ": " .. model, 2 )
end
model.width = #model.background[ 1 ]
model.height = #model.background
return model
end
--- Draw a model at the specified coordinates.
-- @param x description
-- @param y description
-- @param model description
-- @return nil
local function draw_model( x, y, model )
for i = 1, model.height do
term.setCursorPos( x, y + i )
term.blit( model.characters[ i ], model.foreground[ i ], model.background[ i ] )
end
end
term.clear()
---[[
local f = io.open( args[ 1 ], "r" )
local contents = f:read( "*a" )
f:close()
draw_model( 2, 2, parse_model( contents ) )
--]]
--[[
local pistol = io.open( "/assets/pistol.mdl", "r" )
local pistol_contents = pistol:read( "*a" )
pistol:close()
local scope = io.open( "/assets/scope.mdl", "r" )
local scope_contents = scope:read( "*a" )
scope:close()
pistol = parse_model( pistol_contents, "pistol" )
scope = parse_model( scope_contents, "scope" )
local x, y = 2, 5
draw_model( x, y, pistol )
draw_model( x + pistol.slots.sight.x - scope.mount_point.x, y + pistol.slots.sight.y - scope.mount_point.y, scope )
--]]
term.setCursorPos( 1, 1 )