Repository navigation
Expand file tree
/
Copy pathmain.lua
More file actions
158 lines (116 loc) · 3.17 KB
/
Copy pathmain.lua
File metadata and controls
158 lines (116 loc) · 3.17 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
local hump_camera = require "aux/hump_camera"
local success, info = dofile("build/merger.lua")
--local matrix, info = dofile("build/merger.lua")
local worldImage, worldCanvas
local scale = 1
local camera
local zoom = 1
local window_width = 1300
local window_height = 700
function love.load()
love.keyboard.setKeyRepeat( true )
love.system.setClipboardText(info.source)
print("Copied to clipboard")
love.graphics.setDefaultFilter("nearest", "nearest", 1)
if success and info.preview and info.result then
local matrix = info.result.field
local height = #matrix
local width = #matrix[1]
scale = math.min(window_width / width, window_height / height)
worldImage = love.image.newImageData(width, height)
worldCanvas = love.graphics.newCanvas(width, height)
local r, g, b
local color
local tc = {}
local conv = function(hex)
local r = math.floor(hex / 0x10000)
local g = math.floor((hex%0x10000) / 0x100)
local b = hex % 0x100
return {r=r, g=g, b=b}
end
for id, block in next, info.result.blockMeta do
if type(id) == "number" then
tc[id] = conv(block.color)
end
end
local ta = {}
local col_cand
local xa, ya
for y=1, height do
for x=1, width do
color = tc[ matrix[y][x] ] or {r=255, g=255, b=255}
r, g, b = (color.r/255), (color.g/255), (color.b/255)
worldImage:setPixel(x-1, y-1, r, g, b, 1)
end
end
love.window.setMode(width*scale, height*scale)
window_width = width*scale
window_height = height*scale
camera = hump_camera(window_width/2, window_height/2)
do
local f = io.open("world.png", "wb")
f:write(worldImage:encode("png"):getString())
f:close()
end
worldImage = love.graphics.newImage(worldImage)
worldCanvas:renderTo(function()
love.graphics.draw(worldImage, 0, 0, 0, 1.0, 1.0)
end)
end
end
function love.update()
if love.keyboard.isDown("escape") then
love.event.quit()
end
if not success or not info or not info.preview then
love.event.quit()
return
end
end
function love.draw()
if worldCanvas then
camera:attach()
love.graphics.draw(worldCanvas, 0, 0, 0, scale, scale)
camera:detach()
end
end
function love.wheelmoved(x, y)
zoom = zoom + y
camera:zoomTo(2^zoom)
if y > 0 then
local mx, my = love.mouse.getPosition()
mx, my = camera:worldCoords(mx, my)
camera:lookAt(mx, my)
end
end
local do_move = false
function love.mousepressed(x, y, button, istouch, presses)
do_move = true
end
function love.mousereleased(x, y, button, istouch, presses)
do_move = false
end
function love.mousemoved(x, y, dx, dy, istouch)
if do_move then
camera:move(-dx/(2^zoom), -dy/(2^zoom))
end
end
function love.keypressed(key, scancode, isrepeat)
local dr = 5--1/zoom
if key == "left" then
camera:move(-dr, 0)
end
if key == "right" then
camera:move(dr, 0)
end
if key == "up" then
camera:move(0, -dr)
end
if key == "down" then
camera:move(0, dr)
end
if key == "c" then
camera:lookAt(window_width/2, window_height/2)
camera:zoomTo(1)
end
end