Chip's Challenge Level Splicer
#1
CCLP4 voting is soon upon us, and I thought I'd share the script I wrote to assemble the voting packs. It is available on PasteBin.

This Python script takes in an text file consisting of one or more lines of the filename of a level set and a level number, separated by a tab. It outputs a new level set consisting of the specified levels. Hopefully someone else will find it useful, and don't hesitate to ask questions about it Happy
You should probably be playing CC2LP1.

Or go to the Chip's Challenge Wiki.
Reply
#2
That's great. Could you provide a simple example of the text files? Slight smile
Reply
#3
Just had a quick look at the code, the syntax should be

Code:
file[tab]number

but the program has several flaws, it doesn't change the level numbers (so the output will not be correct), for the input it doesn't check for empty lines, so it will try to open a file it can't at the end of file if it is, as in most text files, in it's own line, and crash (just insert something like if pair[0]=="": continue in line 15 to avoid it), and it opens all input files multiple times for no apparent reason...

This should work properly:

(in Lua)

Code:
function levels(s)
  local function g(i) return s:byte(i)+s:byte(i+1)*256 end
  local n, p, t = g(5), 7, {}
  for i=1, n do
    local a = g(p)
    table.insert(t,s:sub(p+4, p+a+1))
    p = p+a+2
  end
  return t
end

if #arg~=2 then
  io.stderr:write("Usage: "..arg[0].." input output")
  os.exit(1)
end

local inp = assert(io.open(arg[1], "r"))
local dat = inp:read("*a")
inp:close()

local a = {}
for line in dat:gmatch("[^\r\n]+") do
  local t = {}
  for w in line:gmatch("%S+") do table.insert(t,w) end
  local inp = assert(io.open(table.remove(t,1), "rb"))
  local ls = levels(inp:read("*a"))
  inp:close()
  for _,x in ipairs(t) do table.insert(a,ls[tonumber(x)]) end
end

function b(n) return string.char(n%256,math.floor(n/256)) end
local out = assert(io.open(arg[2], "wb"))
out:write("\xac\xaa\x02\x00"..b(#a))
for i,x in ipairs(a) do out:write(b(#x+2)..b(i)..x) end
out:close()

and you can specify multiple levels per set per line and use arbitrary white space as separator.

Code:
CCLP1.dat 123 2
JoshL5.dat 9
Reply
#4
Yeah, there is minimal error checking in the code since it was mainly for personal use. And I believe a level editor will fix the problem of the incorrect level number headers (though a set will play fine even when these are incorrect). Maybe I'll release an update to the code Smiley

For Miika, here is an example of a ten-level input file (CCZone doesn't support tabs so just imagine the final space is a tab):

Josh-CCLP4.dat 60
IHNN1-CCLP4 mix.dat 41
Josh-CCLP4.dat 195
C1059-CCLP4.dat 60
IHNN1-CCLP4 mix.dat 17
Josh-CCLP4.dat 180
IHNN1-CCLP4 mix.dat 160
ZK4 submissions.dat 23
The Other 100 Tiles.dat 71
C1059-CCLP4.dat 34
You should probably be playing CC2LP1.

Or go to the Chip's Challenge Wiki.
Reply
#5
Quote:but the program has several flaws, it doesn't change the level numbers (so the output will not be correct), for the input it doesn't check for empty lines, so it will try to open a file it can't at the end of file if it is, as in most text files, in it's own line, and crash (just insert something like if pair[0]=="": continue in line 15 to avoid it), and it opens all input files multiple times for no apparent reason...

and you can specify multiple levels per set per line and use arbitrary white space as separator.


Rewrote my script just for kicks. I polished up stuff, the internal level numbers are now correct, input checks for empty lines, and files are only opened/closed once, though this method isn't necessarily more efficient than opening/closing files on a line-by-line basis, especially if you have lots of unique level sets. Added the multiple levels per line option too.

Now that all the CCLP4 packs have been assembled and released, I'd have to say the first script I wrote worked fine Tongue I kept the tab separation between the filename and level numbers, because some level sets have spaces in their names, unfortunately.
You should probably be playing CC2LP1.

Or go to the Chip's Challenge Wiki.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)