Skip to content

Instantly share code, notes, and snippets.

@lostsnow
Last active May 4, 2018 05:27
Show Gist options
  • Save lostsnow/fbfb22b950fda04503d7804326c52dd0 to your computer and use it in GitHub Desktop.
Save lostsnow/fbfb22b950fda04503d7804326c52dd0 to your computer and use it in GitHub Desktop.
Delta T Plugin: Force Zoom Level
// ==UserScript==
// @id delta-t-force-zoom-level@lostsnow
// @name Delta T Plugin: Force Zoom Level
// @category Tweaks
// @version 0.4.0
// @namespace https://github.com/lostsnow/delta-t-force-zoom-level
// @author lostsnow
// @description Force Zoom Level.
// @updateURL https://gist.github.com/lostsnow/fbfb22b950fda04503d7804326c52dd0/raw/delta-t-force-zoom-level.user.js
// @downloadURL https://gist.github.com/lostsnow/fbfb22b950fda04503d7804326c52dd0/raw/delta-t-force-zoom-level.user.js
// @include https://battlemap.deltatgame.com/home*
// @match https://battlemap.deltatgame.com/home*
// @grant none
// ==/UserScript==
(function(w, $, e, z, a, r, n, u, f) {
'use strict';
var L = window.L;
var I = function() {
a.clearTimeout();
r.clearCoreTimeout();
r.clearNeutralCoreTimeout();
n.clearPOITimeout();
n.clearNeutralPOITimeout();
};
var P = function() {
a.clearTimeout();
a.clearFactionTimeout();
};
var restrictLevel = 10;
var originBaseLevelFunc = e.returnBaseLevel,
originZoomLevel = e.returnMap().getZoom();
var setBaseLevelFunc = function() {
if (originZoomLevel < restrictLevel) {
console.log("origin base level");
e.returnBaseLevel = originBaseLevelFunc;
} else {
console.log("force base level");
e.returnBaseLevel = function(){
return 1;
};
}
}
var showBases = function() {
for (var i = 1; i < 5; i++) {
I();
P();
a.showFactionBases({
faction: i,
minLevel: e.returnBaseLevel(),
bounds: e.getMapBounds()
}, "true");
I();
P();
}
}
var mapInit = function() {
e.clearLayerGroup();
e.clearFactionLayerGroup();
e.returnMap().flyTo([39.9788, 116.30226], 9);
};
mapInit();
var onChange = function(t) {
originZoomLevel = e.returnMap().getZoom();
setBaseLevelFunc();
if (originZoomLevel < restrictLevel) {
console.log("origin zoom level (onChange)");
var battleParams = {
ownBaseDetails: {},
oppoBaseDetails: {},
takeMetoBattle: !0
};
e.clearLayerGroup();
u.resetFilter();
I();
P();
var o = originZoomLevel;
0 == f.getSliderStatus() && f.setSlider(o);
var r = e.returnBaseLevel(o);
!0 === battleParams.takeMetoBattle && a.showBases({
minLevel: r,
bounds: e.getMapBounds()
});
var l = $("#faction-wise-filter").val();
"0" !== l && (P(), a.showFactionBases({
faction: l,
minLevel: r,
bounds: e.getMapBounds()
}, "true"));
z.showCoresPOIs(o)
I();
P();
return false;
}
$("#core-check-container").removeClass("filter-disabled");
$("#poi-check-container").removeClass("filter-disabled");
u.setLevelFilter(0);
console.log("force zoom level (onChange)");
filterCallback();
};
e.returnMap().off("zoomend").on("zoomend", onChange);
e.returnMap().off("dragend").on("dragend", onChange);
var filterCallback = function() {
var t = [];
var levelData = u.returnLevel(),
healthData = u.returnHealth();
t = u.returnStructures();
var o = $("#faction-wise-filter").val();
if (0 === t.length) {
$("#filter-group-btns").addClass("filter-disabled");
showBases();
} else {
$("#filter-group-btns").removeClass("filter-disabled");
e.clearLayerGroup();
e.clearHighlightLayer();
}
$.each(t, function(t, l) {
if ("base" === l) {
for (var i = 1; i < 5; i++) {
I();
P();
a.showFactionBases({
faction: i,
minLevel: levelData.minLevel,
maxLevel: levelData.maxLevel,
minHealth: healthData.minHealth,
maxHealth: healthData.maxHealth,
bounds: e.getMapBounds()
}, "true");
I();
P();
}
} else if ("core" === l) {
I();
P();
r.showCores({
minLevel: levelData.minLevel,
maxLevel: levelData.maxLevel,
minHealth: healthData.minHealth,
maxHealth: healthData.maxHealth,
bounds: e.getMapBounds()
});
I();
P();
} else if ("poi" === l) {
I();
P();
n.showPOIs({
minLevel: levelData.minLevel,
maxLevel: levelData.maxLevel,
minHealth: healthData.minHealth,
maxHealth: healthData.maxHealth,
bounds: e.getMapBounds()
});
I();
P();
}
});
};
$("#apply-filter-btn").unbind("click").on("click", filterCallback);
})(window, jQuery, mapController, mainController, baseListController, coreListController, POIListController,
filterController, zoomSliderController);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment