poster/break.lua

by hugeblank
648 days agolua
COPY
1
-- break.lua by hugeblank, Feb 2023
2
-- A shitty little program for shitty little people
3
-- who are too lazy to write their own tool to break
4
-- apart .2dja files.
5
-- Usage:
6
-- break <file>.2dja
7
if #({...}) == 0 then
8
    print("break <file>.2dja")
9
    return
10
end
11
local input = fs.combine(shell.dir(), ...)
12
local f = fs.open(input, "r")
13
local posters = textutils.unserializeJSON(f.readAll())
14
f.close()
15

16
local name = posters.title
17
local x, y = 0, 0
18
for i, poster in pairs(posters.pages) do
19
    if x%posters.width == 0 then
20
        y = y+1
21
    end
22
    x = (x%posters.width)+1
23
    
24
    poster.label = name.." "..x.." "..y
25
    local p = fs.open(fs.combine(shell.dir(), name..i..".2dj"), "w")
26
    p.write(textutils.serialiseJSON(poster))
27
    p.close()
28
end