Skip to content

Commit fc48c02

Browse files
author
Credomane Evonguard
authored
Merge pull request #10 from credomane/fixissues
fixes issues #4, #6, #7, #8 and #9.
2 parents b2763b6 + 256e491 commit fc48c02

File tree

13 files changed

+227
-121
lines changed

13 files changed

+227
-121
lines changed

README.md

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
# Factorio Maps
2-
32
This [Factorio](http://www.factorio.com/) mod makes a Google Map of your factory! You can view the map locally or upload it to a web server.
43

5-
# How to Use
6-
7-
Step One. Open Factorio and open the "Mod" menu
8-
9-
Step Two. Search for the "Google Maps Factorio Style" mod.
10-
11-
Step Three. Install the mod.
4+
# How to Install
5+
1. Open Factorio and open the "Mod" menu
6+
1. Search for and install the "Google Maps Factorio Style" mod.
127

13-
Step Four. Open your save and open the Factorio menu in the upper left-hand side.
14-
15-
Step Five. Configure setting and make your map.
16-
17-
Setp Six. Open the Factorio save directory and find the FactorioMaps folder.
18-
19-
Step Seven. Open the index.html and follow the following steps.
20-
21-
For local use, don't change anything. For server (making it available on a website) use, get a Google Maps API key (get one here: https://developers.google.com/maps/documentation/javascript/get-api-key), paste your key in the line below this one where it says "INSERTAPIKEY", uncomment the line below and two lines down delete the second <!-- and the first -->
22-
23-
Step Eight. Use map!
8+
# How to Use
9+
1. Open your save then click the FactorioMaps button in the upper left-hand side.
10+
1. Configure settings
11+
* If planning to upload to a server add the Google API key to the new MOD Settings menu of Factorio.
12+
* Obtain a key from: https://developers.google.com/maps/documentation/javascript/get-api-key
13+
1. Generate your map.
14+
1. Open the Factorio script-output directory and open the FactorioMaps folder.
15+
1. Upload your map to a server or use it locally!
16+
17+
# Known Limitations
18+
Factorio Mods can not take screenshots on a headless server. This is an unfortunate limitation of Factorio itself.

fm/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local config_defaults = {
66
altInfo = false,
77
folderName = "TempNameChangeMe!",
88
customSize = false,
9+
extraZoomIn = false,
910
topLeftX = -1000,
1011
topLeftY = -1000,
1112
bottomRightX = 1000,

fm/generateIndex.lua

Lines changed: 69 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,32 @@ function fm.generateIndex(data)
22
-- generate index.html
33
local pathName = "FactorioMaps/" .. data.folderName .. "/index.html"
44

5+
local googleKey = ""
6+
if (data.googleKey ~= nil) and (data.googleKey ~= "") then
7+
googleKey = "?key=" .. data.googleKey
8+
end
9+
510
local indexText = [[
611
<!DOCTYPE html>
712
<html>
813
<head>
14+
<title>Factorio Maps</title>
15+
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
916
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
1017
<style type="text/css">
1118
html { height: 100% }
1219
body { height: 100%; margin: 0px; padding: 0px }
13-
#map_canvas { height: 100%; z-index: 0;}
14-
#gmnoprint {width: auto;}
20+
#map_canvas { height: 100%; z-index: 0; }
21+
#gmnoprint { width: auto; }
1522
</style>
16-
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
17-
<title>Factorio Maps</title>
18-
<!-- For local use, don't change anything. For server (making it available on a website) use, get a Google Maps API key (get one here: https://developers.google.com/maps/documentation/javascript/get-api-key), paste your key in the line below this one where it says "INSERTAPIKEY", uncomment the line below and two lines down delete the second <!-- and the first -->
19-
<!-- <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=INSERTAPIKEY"></script> -->
20-
<!-- --> <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js"></script> <!-- -->
23+
<!--
24+
For local use, don't change anything.
25+
For server use (making it available on a website):
26+
1. Get a Google Maps API key from https://developers.google.com/maps/documentation/javascript/get-api-key
27+
2. Add ?key=INSERTAPIKEY to the end of the below script URL
28+
3. Finally replace INSERTAPIKEY with the API key you obtained in step #1.
29+
-->
30+
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js]] .. googleKey .. [["></script>
2131
<script>
2232
function CustomMapType() {}
2333
@@ -52,26 +62,61 @@ CustomMapType.prototype.getTile = function(coord, zoom, ownerDocument) {
5262
return div;
5363
};
5464
55-
//(-180 + math.ceil(-1*tonumber(txtTopLeftX.text) + tonumber(txtBottomRightX.text))/2)
5665
CustomMapType.prototype.name = "Custom";
5766
CustomMapType.prototype.alt = "Tile Coordinate Map Type";
67+
var CustomMap = new CustomMapType();
68+
69+
// bounds of the desired area
70+
var allowedBounds = new google.maps.LatLngBounds(
71+
//This is confusing so:
72+
new google.maps.LatLng(-85, -179.99), //LatLng(Bottom, Left)
73+
new google.maps.LatLng(85, 179.99) //LatLng(Top,Right)
74+
);
75+
var boundLimits = {
76+
maxLat : allowedBounds.getNorthEast().lat(),
77+
maxLng : allowedBounds.getNorthEast().lng(),
78+
minLat : allowedBounds.getSouthWest().lat(),
79+
minLng : allowedBounds.getSouthWest().lng()
80+
};
81+
5882
var map;
59-
var CustomMapType = new CustomMapType();
83+
84+
function update_map() {
85+
checkBounds();
86+
update_url();
87+
}
88+
89+
// If the map position is out of range, move it back
90+
function checkBounds() {
91+
center = map.getCenter();
92+
if (allowedBounds.contains(center)) {
93+
// still within valid bounds, so save the last valid position
94+
lastValidCenter = map.getCenter();
95+
return;
96+
}
97+
newLat = lastValidCenter.lat();
98+
newLng = lastValidCenter.lng();
99+
if(center.lng() > boundLimits.minLng && center.lng() < boundLimits.maxLng){
100+
newLng = center.lng();
101+
}
102+
if(center.lat() > boundLimits.minLat && center.lat() < boundLimits.maxLat){
103+
newLat = center.lat();
104+
}
105+
map.panTo(new google.maps.LatLng(newLat, newLng));
106+
}
60107
61108
function update_url() {
62109
var center = map.getCenter();
63110
var zoom = map.getZoom();
64111
var href = location.href;
65112
66113
href = href.split("#")[0] || href;
67-
href = encodeURI(href);
68114
window.location.replace(href + '#' + center.lat().toFixed(2) + ',' + center.lng().toFixed(2) + ',' + zoom);
69115
}
70116
71117
function hash_changed() {
72118
var urlbits = window.location.hash.split('#');
73-
if(urlbits[1])
74-
{
119+
if(urlbits[1]) {
75120
locationbits = urlbits[1].split(',');
76121
map.setCenter({lat: parseFloat(locationbits[0]), lng: parseFloat(locationbits[1])});
77122
map.setZoom(parseInt(locationbits[2]));
@@ -82,35 +127,37 @@ if ("onhashchange" in window) {
82127
window.onhashchange = hash_changed
83128
}
84129
85-
function initialize() {
130+
function load() {
86131
var mapOptions = {
87132
zoom: ]].. (data.index.minZoomLevel) ..[[,
88133
// minZoom: ]]..(data.index.minZoomLevel) ..[[,
89134
// maxZoom: ]].. (data.index.maxZoomLevel == 1 and (data.index.maxZoomLevel - 1) or data.index.maxZoomLevel) ..[[,
90135
isPng: false,
91136
mapTypeControl: false,
92137
streetViewControl: false,
93-
center: new google.maps.LatLng(]].. 0 ..",".. 0 ..[[ ),
138+
center: new google.maps.LatLng(]].. 0 ..",".. 0 ..[[),
94139
mapTypeControlOptions: {
95140
mapTypeIds: ['custom', google.maps.MapTypeId.ROADMAP],
96141
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
97142
}
98143
};
99144
map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
100-
map.mapTypes.set('custom',CustomMapType);
145+
map.mapTypes.set('custom',CustomMap);
101146
map.setMapTypeId('custom');
102147
148+
lastValidCenter = map.getCenter();
149+
103150
hash_changed()
104151
105-
map.addListener('center_changed', update_url);
106-
map.addListener('zoom_changed', update_url);
152+
map.addListener('center_changed', update_map);
153+
map.addListener('zoom_changed', update_map);
107154
108155
109156
// addmarker();
110157
// addoutline();
111158
}
112159
113-
function addmarker(){
160+
function addmarker() {
114161
var marker = new google.maps.Marker({
115162
position: new google.maps.LatLng(85,-180),
116163
map: map,
@@ -125,8 +172,7 @@ function addmarker(){
125172
});
126173
}
127174
128-
function addoutline()
129-
{
175+
function addoutline() {
130176
var flightPlanCoordinates = [
131177
]]
132178

@@ -147,10 +193,11 @@ function addoutline()
147193
}
148194
</script>
149195
</head>
150-
<body onload="initialize()">
196+
<body onload="load()">
151197
<div id="map_canvas" style="background: #1B2D33;"></div>
152198
</body>
153-
</html>]]
199+
</html>
200+
]]
154201

155202
game.write_file(pathName, indexText)
156203

fm/generateMap.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function fm.generateMap(data)
3333
tmpCounter = tmpCounter + 1
3434
end
3535

36-
if maxZoomLevel > 0 then maxZoomLevel = maxZoomLevel - 1 end
36+
if maxZoomLevel > 0 and data.extraZoomIn ~= true then maxZoomLevel = maxZoomLevel - 1 end
3737
if maxZoomLevel < minZoomLevel then maxZoomLevel = minZoomLevel end
3838

3939
--Setup the results table for feeding into generateIndex
@@ -45,7 +45,12 @@ function fm.generateMap(data)
4545
data.index.gridPixelSize = gridPixelSize
4646

4747
--Temp variables used in loops
48-
local currentZoomLevel = 1 / 2 ^ (maxZoomLevel + 1 - minZoomLevel) -- counter for measuring zoom, 1/1, 1/2,1/4,1/8 etc
48+
local currentZoomLevel = 0;
49+
if data.extraZoomIn ~= true then
50+
currentZoomLevel = 1 / 2 ^ (maxZoomLevel + 1 - minZoomLevel) -- counter for measuring zoom, 1/1, 1/2,1/4,1/8 etc
51+
else
52+
currentZoomLevel = 1 / 2 ^ (maxZoomLevel - minZoomLevel) -- counter for measuring zoom, 1/1, 1/2,1/4,1/8 etc
53+
end
4954
local extension = ""
5055
local pathText = ""
5156
local positionText = ""

fm/guiEventHandlers.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function fm.gui.registerAllHandlers()
1919
Gui.on_checked_state_changed("FactorioMaps_altInfo", fm.gui.actions.altInfo)
2020
Gui.on_checked_state_changed("FactorioMaps_radio_gridSize_", fm.gui.actions.gridSizeRadio)
2121
Gui.on_checked_state_changed("FactorioMaps_radio_extension_", fm.gui.actions.extensionRadio)
22+
Gui.on_checked_state_changed("FactorioMaps_extraZoomIn", fm.gui.actions.extraZoomIn)
2223

2324
Gui.on_text_changed("FactorioMaps_folderName", fm.gui.actions.folderName)
2425
Gui.on_text_changed("FactorioMaps_topLeftX", fm.gui.actions.topLeftX)
@@ -193,7 +194,6 @@ function fm.gui.actions.generate(event)
193194
return
194195
end
195196

196-
197197
data.topLeft = {
198198
x = fm.cfg.get("topLeftX"),
199199
y = fm.cfg.get("topLeftY")
@@ -209,9 +209,13 @@ function fm.gui.actions.generate(event)
209209
data.extension = fm.cfg.get("extension")
210210
data.dayOnly = fm.cfg.get("dayOnly")
211211
data.altInfo = fm.cfg.get("altInfo")
212+
data.extraZoomIn = fm.cfg.get("extraZoomIn")
212213
data.surfaceName = player.surface.name
213214
data.player_index = player.index
214215

216+
local psettings = settings.get_player_settings(player)
217+
data.googleKey = settings.player["FM_GoogleAPIKey"].value
218+
215219
fm.generateMap(data)
216220
fm.generateIndex(data)
217221
end
@@ -261,6 +265,10 @@ function fm.gui.actions.extensionRadio(event)
261265
fm.cfg.set("extension", num)
262266
end
263267

268+
function fm.gui.actions.extraZoomIn(event)
269+
fm.cfg.set("extraZoomIn", event.state)
270+
end
271+
264272
function fm.gui.actions.viewReturn(event)
265273
fm.viewer(event, {x=fm.cfg.get("topLeftX"), y=fm.cfg.get("topLeftY")}, true)
266274
end

fm/guiLayout.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ function fm.gui.showRightPane(player_index_or_name)
195195
fm.gui.radio.extensionSelect(fm.cfg.get("extension"))
196196

197197
local middleFlow3 = rightPane.add({type = "flow", name = "middleFlow3", direction = "horizontal"})
198+
198199
local bottomFlow = rightPane.add({type = "flow", name = "bottomFlow", direction = "horizontal"})
200+
bottomFlow.add({type = "checkbox", name = "FactorioMaps_extraZoomIn", state = fm.cfg.get("extraZoomIn"), caption = {"label-extraZoomIn"}, tooltip = {"tooltip-extraZoomIn"}})
201+
199202
rightPane.add({type = "label", name = "label_currentPlayerCoords", caption = {"label-current-player-coords", "nauvis", 0, 0}, tooltip = {"tooltip-current-player-coords"}})
200203
end
201204

fm/migrations.lua

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11

22
fm.migrations = {}
33

4-
function fm.migrations.doUpdate(oldVersion, newVersion)
5-
Game.print_all("[FactorioMaps] Updater: Version changed from " .. oldVersion .. " to " .. newVersion .. ".")
4+
function fm.migrations.doUpdate(oldVersionString, newVersionString)
5+
Game.print_all("[FactorioMaps] Updater: Version changed from " .. oldVersionString .. " to " .. newVersionString .. ".")
6+
7+
local oldVersionTmp = oldVersionString.split(".")
8+
local newVersionTmp = newVersionString.split(".")
9+
10+
--Gives a buffer of 1000 for each section of Factorio's "simver" (Major.Minor.Build)
11+
local oldVersion = oldVersionTmp[1] * 1000000 + oldVersionTmp[2] * 1000 + oldVersionTmp[3]
12+
local newVersion = newVersionTmp[1] * 1000000 + newVersionTmp[2] * 1000 + newVersionTmp[3]
613

714
if oldVersion > newVersion then
815
Game.print_all("[FactorioMaps] Updater: Version downgrade detected. I can't believe you've done this.")
16+
Game.print_all("[FactorioMaps] Updater: I don't have handlers for downgrades so things might break. :(")
917
return
1018
end
1119

12-
if oldVersion < "0.7.0" then
20+
if oldVersion < 7000 then
21+
Game.print_all("[FactorioMaps] Updater: Migrating to 0.7.0...")
1322
fm.migrations.to_0_7_0()
1423
end
1524

16-
if oldVersion < "0.7.1" then
25+
if oldVersion < 7001 then
26+
Game.print_all("[FactorioMaps] Updater: Migrating to 0.7.1...")
1727
fm.migrations.to_0_7_1()
1828
end
1929

30+
if oldVersion < 15001 then
31+
Game.print_all("[FactorioMaps] Updater: Migrating to 0.15.1...")
32+
fm.migrations.to_0_15_1()
33+
end
34+
2035
end
2136

2237
------------------------------------------------------------------------------------------------------
@@ -52,3 +67,8 @@ end
5267
function fm.migrations.to_0_7_1()
5368
fm.gui.showAllMainButton()
5469
end
70+
71+
--Add in the new config extraZoomIn.
72+
function fm.migrations.to_0_15_1()
73+
fm.config.applyDefaults(false)
74+
end

fm/remote.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,4 @@ function fm.remote.reset_player(player_name_or_index)
1111
player_data.remote_viewer = nil
1212
end
1313

14-
--Testing migrations.
15-
--TODO: DELETE ME
16-
function fm.remote.migrate()
17-
fm.migrations.to_0_7_0()
18-
end
19-
2014
remote.add_interface("fm", fm.remote)

fm/viewer.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function fm.viewer(event, coords, goBack)
5151

5252
-- make us a viewer and put us in it
5353
local viewer = player.surface.create_entity({name="FactorioMaps_remote-viewer", position=coords, force=player.force})
54+
viewer.destructible = false
5455
player.character = viewer
5556

5657
-- don't leave an old one behind

info.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "FactorioMaps",
3-
"version": "0.7.2",
3+
"version": "0.15.1",
44
"title": "Google Maps Factorio style",
55
"author": "jeroon, credomane",
66
"contact": "https://github.com/credomane/",
77
"homepage": "https://github.com/credomane/FactorioMods_FactorioMaps",
88
"description": "Create a Google Maps-like map of your Factorio game",
99
"license": "Free for all",
10-
"factorio_version": "0.14",
10+
"factorio_version": "0.15",
1111
"dependencies": []
1212
}

0 commit comments

Comments
 (0)