2023-08-26 21:05:48 +00:00
|
|
|
--Manage the AI nodes used by DEFCON.
|
|
|
|
local t = {}
|
|
|
|
local bmp = require 'bmp'
|
|
|
|
local lg = assert( love.graphics )
|
2023-08-28 23:12:43 +00:00
|
|
|
local print = print
|
2023-08-26 21:05:48 +00:00
|
|
|
|
|
|
|
function t.load( filename )
|
|
|
|
local img, imgd = bmp.load( filename )
|
|
|
|
local nodes = {
|
|
|
|
visible = true,
|
|
|
|
att = {},
|
2023-08-28 23:12:43 +00:00
|
|
|
ptsAtt = {},
|
2023-08-26 21:05:48 +00:00
|
|
|
def = {},
|
2023-08-28 23:12:43 +00:00
|
|
|
ptsDef = {},
|
2023-08-26 21:05:48 +00:00
|
|
|
img = img,
|
|
|
|
imgd = imgd }
|
2023-08-28 23:12:43 +00:00
|
|
|
|
|
|
|
print( "=== Loading AI Markers: ===" )
|
|
|
|
for x = 0, 511 do
|
|
|
|
for y = 0, 284 do
|
|
|
|
local r, g = imgd:getPixel( x, 284 - y )
|
|
|
|
if r > 0.5 or g > 0.5 then
|
|
|
|
local long = x * (360 / imgd:getWidth()) - 180
|
|
|
|
local lat = y * (200 / img:getHeight()) - 100
|
|
|
|
local set = (r > 0.5) and nodes.att or nodes.def
|
|
|
|
set[#set + 1] = {x = long, y = lat}
|
|
|
|
print( #set, long, lat )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
do
|
|
|
|
local k = 1
|
|
|
|
for i, point in ipairs( nodes.att ) do
|
|
|
|
nodes.ptsAtt[k], nodes.ptsAtt[k + 1] = point.x, point.y
|
|
|
|
k = k + 2
|
|
|
|
end
|
|
|
|
|
|
|
|
k = 1
|
|
|
|
for j, point in ipairs( nodes.def ) do
|
|
|
|
nodes.ptsDef[k], nodes.ptsDef[k + 1] = point.x, point.y
|
|
|
|
k = k + 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable( nodes, {__index = t } )
|
2023-08-26 21:05:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function t.draw( nodes )
|
2023-08-28 23:12:43 +00:00
|
|
|
lg.setColor( 1, 0, 0, 0.5 )
|
|
|
|
lg.points( nodes.ptsAtt )
|
|
|
|
lg.setColor( 0, 1, 0, 0.5 )
|
|
|
|
lg.points( nodes.ptsDef )
|
2023-08-26 21:05:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function t.save( nodes, filename )
|
2023-08-28 23:12:43 +00:00
|
|
|
|
2023-08-26 21:05:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return t
|