forked from bahrmichael/factorio-tycoon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.lua
More file actions
59 lines (55 loc) · 1.56 KB
/
debug.lua
File metadata and controls
59 lines (55 loc) · 1.56 KB
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
local Queue = require "queue"
local function log(message)
if global.tycoon_enable_debug_logging == true then
game.write_file("debug.log", message .. "\n", true)
end
end
local function logRoadEnds(roadEnds)
if roadEnds == nil then
return
end
local printable = ''
for value in Queue.iterate(roadEnds) do
printable = printable .. " " .. value.coordinates.y .. "/" .. value.coordinates.x
end
log(printable)
end
local function logGrid(grid, logFn)
local hasCustomLogging = true
if logFn == nil then
logFn = log
hasCustomLogging = false
end
if global.tycoon_enable_debug_logging or hasCustomLogging then
if not hasCustomLogging then
logFn('-- grid --')
end
local s = #grid
for y = 1, s, 1 do
local printRow = string.format("%3d: ", y)
local row = grid[y]
for x = 1, s, 1 do
local cell = row[x]
if cell.type == "unused" then
printRow = printRow .. ". "
elseif cell.type == "building" then
printRow = printRow .. "H "
elseif cell.type == "road" then
printRow = printRow .. "R "
else
printRow = printRow .. "_ "
end
end
logFn(printRow)
end
if not hasCustomLogging then
logFn('-- grid --')
end
end
end
local DEBUG = {
log = log,
logGrid = logGrid,
logRoadEnds = logRoadEnds
}
return DEBUG