Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
L0laapk3 committed Jan 21, 2020
2 parents 98cfdb8 + 7ca6bbd commit abd56f4
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 19 deletions.
10 changes: 9 additions & 1 deletion API_ExampleMod_0.0.1/factoriomaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-- this function is to be ran on script.on_init and on script.on_load.
local function handle_factoriomaps()
if remote.interfaces.factoriomaps then
script.on_event(remote.call("factoriomaps", "get_start_capture_event"), function()
script.on_event(remote.call("factoriomaps", "get_start_capture_event_id"), function()

-- note that this event only gets called when it starts capturing the world, so speed optimalisation of the code in this function is not important.

Expand Down Expand Up @@ -52,6 +52,14 @@ local function handle_factoriomaps()
remote.call("factoriomaps", "surface_set_hidden", "Factory floor 1", true)
remote.call("factoriomaps", "surface_set_hidden", "Factory floor 2", true)
remote.call("factoriomaps", "surface_set_hidden", "Factory floor 3", true)




-- surface_set_default: Sets the default surface. This will error if this is called by multiple mods,
-- You should be really careful with using this, it is unlikely that you need this unless you are a scenario.
-- Further, this will have no effect if an existing timeline is being appended.
-- remote.call("factoriomaps", "surface_set_default", "nauvis")
end


Expand Down
36 changes: 35 additions & 1 deletion api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ fm.API.hiddenSurfaces = {}

local ERRORPRETEXT = "\n\nFACTORIOMAPS HAS DETECTED AN INVALID USAGE OF THE FACTORIOMAPS API BY ANOTHER MOD.\nTHIS IS LIKELY NOT A PROBLEM WITH FACTORIOMAPS, BUT WITH THE OTHER MOD.\n\n"


local function NYI()
error("This API call is not yet implemented due to lack of demand. If you are looking at using this function, contact me! I will gladly implement it.")
end




-- resolve surface to surface object
local function resolveSurface(surface, default, errorText)
errorText = errorText or ""
if surface ~= nil then
Expand Down Expand Up @@ -187,6 +196,9 @@ remote.add_interface("factoriomaps", {
get_start_capture_event_id = function()
return fm.API.startEvent
end,



link_box_point = function(options)
local from, fromSurface = parseLocation(options, "from", true, true)
local to, toSurface = parseLocation(options, "to", false, true, fromSurface)
Expand All @@ -205,6 +217,9 @@ remote.add_interface("factoriomaps", {

addLink("link_renderbox_area", from, fromSurface, to, toSurface)
end,



surface_set_hidden = function(surface, isHidden)
surface = resolveSurface(surface)
if isHidden == true or isHidden == nil then
Expand All @@ -224,6 +239,25 @@ remote.add_interface("factoriomaps", {
else
error(ERRORPRETEXT .. "invalid isHidden parameter\n")
end
end,
surface_set_default = function(surface)
surface = resolveSurface(surface)
if fm.autorun.mapInfo.defaultSurface ~= nil and fm.autorun.mapInfo.defaultSurface ~= surface.name then
error(ERRORPRETEXT .. "The default surface was set multiple times: '" .. fm.autorun.mapInfo.defaultSurface .. "', '" .. surface.name .. "'.\n")
end
fm.autorun.mapInfo.defaultSurface = surface.name
end,
surface_set_startpoint = function(options)
NYI();
end,



legend_link_point = function(directory, subdirectory, text)
NYI();
end,
legend_link_area = function(directory, subdirectory, text)
NYI();
end
})

Expand All @@ -232,6 +266,6 @@ remote.add_interface("factoriomaps", {
function fm.API.pull()
script.raise_event(fm.API.startEvent, {})

remote.remove_interface("factoriomaps")
--remote.remove_interface("factoriomaps")
end

9 changes: 7 additions & 2 deletions auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,14 @@ def refZoom():

if len(icons) == 1:
if src is not None:
copy(src, dest)
img = Image.open(src)
w, h = img.size
img = img.crop((0, 0, h, h))
img.save(dest)
else:
newImg = Image.open(src).convert("RGBA")
newImg = Image.open(src)
w, h = newImg.size
newImg = newImg.crop((0, 0, h, h)).convert("RGBA")
if len(iconColor) > 1:
newImg = ImageChops.multiply(newImg, Image.new("RGBA", newImg.size, color=tuple(map(lambda s: int(round(float(s))), iconColor[1].split("%")))))
if i == 0:
Expand Down
4 changes: 2 additions & 2 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ script.on_event(defines.events.on_tick, function(event)
end
end

fm.API.pull()

if fm.autorun.surfaces == nil then
fm.autorun.surfaces = { "nauvis" }
fm.autorun.surfaces = { fm.autorun.mapInfo.defaultSurface or "nauvis" }
else
for index, surfaceName in pairs(fm.autorun.surfaces) do
if player.surface.name == surfaceName then -- move surface the player is on to first
Expand All @@ -107,7 +108,6 @@ script.on_event(defines.events.on_tick, function(event)
end
end

fm.API.pull()
fm.API.activeLinks = {}
local newSurfaces = {true} -- discover all surfaces linked to from the original surface list or any new surfaces found by this process.
while #newSurfaces > 0 do
Expand Down
2 changes: 2 additions & 0 deletions generateMap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ function fm.generateMap(data)
-- build range
for chunk in fm.currentSurface.get_chunks() do
if fm.currentSurface.is_chunk_generated(chunk) then
log(chunk.x .. " " .. chunk.y)
for _, force in pairs(game.forces) do
if #force.players > 0 and force.is_chunk_charted(fm.currentSurface, chunk) then
log("charted by " .. force.name)
forceStats[force.name] = forceStats[force.name] + 1
imageStats.charted = imageStats.charted + 1
for gridX = chunk.x * tilesPerChunk / gridPixelSize, (chunk.x + 1) * tilesPerChunk / gridPixelSize - 1 do
Expand Down
4 changes: 2 additions & 2 deletions info.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "L0laapk3_FactorioMaps",
"version": "3.5.3",
"version": "3.5.5",
"title": "FactorioMaps",
"author": "L0laapk3",
"contact": "https://github.com/L0laapk3/",
"homepage": "https://git.io/factoriomaps",
"description": "Generate timelapses of your base to view in browsers!",
"license": "CC BY-NC-SA 4.0",
"factorio_version": "0.17",
"factorio_version": "0.18",
"dependencies": []
}
8 changes: 4 additions & 4 deletions updateLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@


urlList = (
"https://cdn.jsdelivr.net/npm/leaflet@1.4.0/dist/leaflet.css",
"https://cdn.jsdelivr.net/npm/leaflet@1.4.0/dist/leaflet-src.min.js",
"https://cdn.jsdelivr.net/npm/leaflet@1.6.0/dist/leaflet.css",
"https://cdn.jsdelivr.net/npm/leaflet@1.6.0/dist/leaflet-src.min.js",
"https://cdn.jsdelivr.net/npm/[email protected]/Control.FullScreen.css",
"https://cdn.jsdelivr.net/npm/[email protected]/Control.FullScreen.min.js",
"https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js",
"https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js",
"https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css",
"https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js",
"https://cdn.jsdelivr.net/gh/L0laapk3/Leaflet.OpacityControls@2/Control.Opacity.css",
Expand All @@ -20,7 +20,7 @@
"https://factorio.com/static/img/favicon.ico",
)

CURRENTVERSION = 3
CURRENTVERSION = 4



Expand Down
5 changes: 3 additions & 2 deletions updates.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"3.3.2": "Many bugfixes.",
"3.4.0": ["Separated map tags to surface and snapshot level", "Thumbnail generation of the map"],
"3.5.0": ["!Added API for integration with i.a. Factorissimo", "Better dependency management", "Several bugfixes"],
"3.5.1": "Removed dependency on package that isnt being updated anymore.",
"3.5.1": "Removed dependency on package that isnt being updated anymore",
"3.5.2": "Added support for unicode characters",
"3.5.3": "Bugfixes"
"3.5.3": "Bugfixes",
"3.5.4": "Extended API"
}
11 changes: 6 additions & 5 deletions web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,10 @@ if (countAvailableSaves > 0 || mapInfo.links && mapInfo.links.save) {
document.getElementById("buttonAnchor").appendChild(btn);
}

const defaultSurface = mapInfo.defaultSurface || "nauvis";
let nightOpacity = 0;
const someSurfaces = mapInfo.maps[mapInfo.maps.length-1].surfaces;
let currentSurface = "nauvis" in someSurfaces ? "nauvis" : Object.keys(someSurfaces).sort()[0]
let currentSurface = defaultSurface in someSurfaces ? defaultSurface : Object.keys(someSurfaces).sort()[0]
let loadLayer = someSurfaces[currentSurface].layers;
let timestamp = (loadLayer.day || loadLayer.night).path;

Expand Down Expand Up @@ -597,10 +598,10 @@ if (layersByTimestamp.length > 1 && true) {
}


// nauvis ontop, other than that natural sort.
let surfaceKeys = Object.keys(layers).filter(s => s != "nauvis").sort(naturalSort);
if (Object.keys(layers).some(s => s == "nauvis"))
surfaceKeys.unshift("nauvis")
// default surface ontop, other than that natural sort.
let surfaceKeys = Object.keys(layers).filter(s => s != defaultSurface).sort(naturalSort);
if (Object.keys(layers).some(s => s == defaultSurface))
surfaceKeys.unshift(defaultSurface)

if (surfaceKeys.length > 1) {
surfaceSlider = new L.Control.layerRadioSelector({
Expand Down

0 comments on commit abd56f4

Please sign in to comment.