diff --git a/camera.lua b/camera.lua index 3fafcfa..3a40eda 100644 --- a/camera.lua +++ b/camera.lua @@ -17,7 +17,7 @@ end function Camera.Translate( x, y ) x = x or 0 y = y or 0 - return Camera.Set( Camera.x + x, Camera.y + y, Camera.w, Camera.h) + return Camera.Set( math.max(-180, math.min(360, Camera.x + x)), math.min(100, Camera.y + y), Camera.w, Camera.h) end --In world coordinates: top left corner at x, y, extent of w, h. diff --git a/cities.lua b/cities.lua index 1892cfd..7543ede 100644 --- a/cities.lua +++ b/cities.lua @@ -1,5 +1,5 @@ --Load and save the fixed width plaintext data used by DEFCON. -local t = {} +local t = { visible = true, active = false} local io = io local math = math local table = table @@ -14,17 +14,18 @@ local caps = {} t.selectedCity = nil function t.draw() - lg.points( points ) + if t.visible then lg.points( points ) end end function t.drawSelected( r ) + if not t.visible then return end local c = t.selectedCity if not c then return end lg.circle( "fill", c.x, c.y, r ) end function t.drawCapitals() - lg.points( caps ) + if t.visible then lg.points( caps ) end end function t.selectNearestCity(x, y) diff --git a/lines.lua b/lines.lua index 6f17096..e61c044 100644 --- a/lines.lua +++ b/lines.lua @@ -4,7 +4,7 @@ local lfs = love.filesystem local lg = love.graphics function t.load( filename ) - local polys = {} + local polys = { visible = true } local poly = {} local n = 0 local k = 1 @@ -29,9 +29,22 @@ end function t.save( lines, filename ) +end + +function t.newPolygon( x, y ) + +end + +function t.addToCurrentPolygon( x, y ) + +end + +function t.deletePolygon( ) + end function t.draw( lines ) + if not lines.visible then return end for _, poly in ipairs( lines ) do lg.line( poly ) end diff --git a/main.lua b/main.lua index 04ef67a..d362e8d 100644 --- a/main.lua +++ b/main.lua @@ -48,6 +48,11 @@ function love.draw() love.graphics.rectangle( "line", love.graphics.getWidth() / 2, h, love.graphics.getWidth() / 2, 30 ) if map.cities.selectedCity then local c = map.cities.selectedCity + love.graphics.setColor( 0.2, 0.1, 0.1, 0.5 ) + love.graphics.rectangle( "fill", 0, 0, 150 ,100 ) + love.graphics.setColor( 1, 1, 1, 1 ) + love.graphics.rectangle( "line", 0, 0, 150 ,100 ) + love.graphics.setColor( 1.2, 1.1, 1.1, 1.5 ) love.graphics.print( ("NAME: %s\nX: %3.2f\nY: %3.2f\nPOP: %d\nCAPITAL: %s\nCOUNTRY: %s"):format(c.name, c.x, c.y, c.pop, tostring(c.capital), c.country), 0, 0 ) end end @@ -62,6 +67,11 @@ end function love.mousepressed( x, y, button, istouch, presses ) local wx, wy = Camera.GetWorldCoordinate( x, y ) + if button == 1 then + map.cities.lockSelection() + else + map.cities.unlockSelection() + end print( ("MOUSE\tx %f\ty %f\twx %f\twy %f"):format(x, y, wx, wy) ) end @@ -74,5 +84,14 @@ function love.keypressed(key) -- To open a file or folder, "file://" must be prepended to the path. love.system.openURL("file://"..love.filesystem.getSaveDirectory()) end + if key == "1" then + map.coastlines.visible = not map.coastlines.visible + end + if key == "2" then + map.coastlinesLow.visible = not map.coastlinesLow.visible + end + if key == "3" then + map.international.visible = not map.international.visible + end wasKeyPressed = true end diff --git a/map.lua b/map.lua index c483f55..ce26152 100644 --- a/map.lua +++ b/map.lua @@ -39,6 +39,7 @@ function map.draw() lg.replaceTransform( Camera.tf ) do --points + lg.setColor( 1, 0, 0, 0.5 ) lg.setPointSize( 0.5 * Camera.zoom ) map.cities.draw() @@ -79,8 +80,8 @@ function map.save() end -function map.setVisible() - +function map.hover(x, y) + end return map