Skip to content

Commit

Permalink
Close #4: Show ground units on the map
Browse files Browse the repository at this point in the history
When creating an instance, a new dropdown field allows selection of the
default ground unit visibility between "None", "Allies Only" and "All".

For fine-grained control, visibility can be overridden for each group
by starting the group name with "MPMAP_RED", "MPMAP_BLUE" or "MPMAP_BOTH".
  • Loading branch information
jboecker committed Mar 22, 2014
1 parent 55af36d commit 1ecb331
Show file tree
Hide file tree
Showing 126 changed files with 118 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ subdirectories. They include:
* zip.js (github.com/gildas-lormeau/zip.js, BSD)
* StringView ([see developer.mozilla.org](https://developer.mozilla.org/en-US/Add-ons/Code_snippets/StringView), GPLv3)
* URI.js (http://medialize.github.com/URI.js/, MIT)
* Unit symbols from DCS: World, redistributed with permission from Eagle Dynamics.
59 changes: 38 additions & 21 deletions admintool.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ <h2>What do you want to do?</h2>
<table>
<h3>Select the Misson File to Continue</h3>
<tr><th>Server: </th><td><input type="text" id="server-input"/></td></tr>
<tr>
<th>Show Ground Units: </th>
<td>
<select id="groundunit_visibility">
<option value="none">None</option>
<option value="allies">Allies Only</option>
<option value="all">Show All</option>
</select>
</td>
</tr>
<tr><th>Mission File (.miz): </th><td><input type="file" id="file-input"></td></tr>
</table>
</div>
Expand Down Expand Up @@ -110,6 +120,7 @@ <h2 class="filename-h2"></h2>
<div id="status"></div>
<span id="load_mission_lua" style="display: none;">
function load_mission()
settings = JSON:decode(ipc_get("settings"))
local last_id = 0
local function new_id()
last_id = last_id + 1
Expand Down Expand Up @@ -165,19 +176,30 @@ <h2 class="filename-h2"></h2>
end
if country.vehicle then
for _, group in ipairs(country.vehicle.group) do
if group.name:match("MP_AIRDEFENCE") then
unit_annotations[#unit_annotations+1] = {
["type"] = 'AIRDEFENCE',
["x"] = group.route.points[1].x,
["z"] = group.route.points[1].y,
}
end
if group.name:match("MP_ARMOR") then
unit_annotations[#unit_annotations+1] = {
["type"] = 'ARMOR',
["x"] = group.route.points[1].x,
["z"] = group.route.points[1].y,
}
local group_vis_override = nil
if group.name:match("MPMAP_RED") then group_vis_override = "red" end
if group.name:match("MPMAP_BLUE") then group_vis_override = "blue" end
if group.name:match("MPMAP_BOTH") then group_vis_override = "all" end
if settings.groundunit_visibility ~= "none" or group_vis_override then
local unit_vis = nil
if group_vis_override then
unit_vis = group_vis_override
if unit_vis == "all" then unit_vis = nil end
elseif settings.groundunit_visibility == "allies" then
unit_vis = coalition_name
else
unit_vis = nil
end
for _, unit in ipairs(group.units) do
unit_annotations[#unit_annotations+1] = {
["type"] = "UNIT",
["unittype"] = unit.type,
["coalition"] = coalition_name,
["x"] = unit.x,
["z"] = unit.y,
["visibility"] = unit_vis,
}
end
end
end
end
Expand Down Expand Up @@ -240,14 +262,8 @@ <h2 class="filename-h2"></h2>

-- add unit annotations
for _, ua in pairs(get_unit_annotations()) do
local ann = {
id = new_id(),
type = "UNIT",
unittype = ua.type,
x = ua.x,
z = ua.z
}
data.objects[ann.id] = ann
ua.id = new_id()
data.objects[ua.id] = ua
end

-- add pre-set circle annotations
Expand Down Expand Up @@ -335,6 +351,7 @@ <h2 class="filename-h2"></h2>


data = JSON:decode(ipc_get("data"))
settings = JSON:decode(ipc_get("settings"))

local route_ids = {}
local second_waypoints_by_group_name = {}
Expand Down
3 changes: 3 additions & 0 deletions js/admintool.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ $(function() {
zipfs.find("mission").getText(function(luaCode) {
set_status("processing mission...");
Lua.exec(luaCode);
ipc.settings = JSON.stringify({
groundunit_visibility: $("#groundunit_visibility").val(),
});
Lua.exec("load_mission()");
var data = JSON.parse(ipc.data);
set_status("opening websocket...");
Expand Down
13 changes: 12 additions & 1 deletion js/planner_ng-mapview.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ mp.MapView = function(map_type) {
graphicHeight: 20,
fillOpacity: 1,
}, OpenLayers.Feature.Vector.style["default"])),
"UNIT": new OpenLayers.Style(OpenLayers.Util.applyDefaults({
externalGraphic: 'vendors/eagledynamics/mapicons/${iconbasename}_${coalition}.png',
graphicWidth: 32,
graphicHeight: 32,
fillOpacity: 1,
}, OpenLayers.Feature.Vector.style["default"])),
'bullseye': new OpenLayers.Style(OpenLayers.Util.applyDefaults({
externalGraphic: 'vendors/wikimedia-commons/bullseye_${coalition}.svg',
graphicWidth: 30,
Expand Down Expand Up @@ -438,8 +444,13 @@ mp.MapView = function(map_type) {
feature.geometry = new OpenLayers.Geometry.Point(obj.lon, obj.lat).transform('EPSG:4326', this.map.getProjection());

features_by_object_id[obj.id] = [feature];
feature.renderIntent = "UNIT_"+obj.unittype;
feature.renderIntent = "UNIT";
feature.data.object_id = obj.id;
feature.attributes.coalition = obj.coalition;
feature.attributes.iconbasename="P91000001"; // default to tank
if (mp.UNITDATA[obj.unittype]) {
feature.attributes.iconbasename = mp.UNITDATA[obj.unittype].iconbasename;
}

vectorLayers[LAYER_ID_UNITS].addFeatures([feature]);
vectorLayers[LAYER_ID_UNITS].redraw();
Expand Down
1 change: 1 addition & 0 deletions js/unitdata.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion planner_client.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h2>Acknowledgements</h2>
would not have been possible.
<ul>
<li>The airport information was compiled by kosmos224 <a href="http://www.digitalcombatsimulator.com/de/files/379189/">(DCS User Files entry)</a></li>
<li>The unit symbols are from <a href="http://en.wikipedia.org/wiki/NATO_Military_Symbols_for_Land_Based_Systems">Wikipedia</a></li>
<li>The unit symbols are from DCS: World and are redistributed with permission from Eagle Dynamics.</li>
<li>Thanks to the authors of the third-party libraries listed in README.md!</li>
<li>Thanks to Speed for writing Slmod! A lot of confusion about the DCS: World Lua environment was cleared up by reading Slmod source code in the early stages of this project when the server part still lived in DCS.</li>
<li>Thanks to Eagle Dynamics for not only making an awesome simulator, but also making it mod-friendly and leaving comments on how to do coordinate conversion in the Lua files!</li>
Expand Down Expand Up @@ -156,6 +156,7 @@ <h2>Connection Lost</h2>
<script src="vendors/URI.js/URI.js"></script>

<script>var mp = { debug: {} };</script>
<script src="js/unitdata.js"></script>
<script src="js/planner_ng-api.js"></script>
<script src="js/planner_ng-model.js"></script>
<script src="js/planner_ng-mapview.js"></script>
Expand Down
Binary file added scripts/extract-mapicons-and-metadata/blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions scripts/extract-mapicons-and-metadata/generate-mapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!python

# This script extracts the map icons and the mapping of unit type to map icon
# from a DCS: World installation.

# Requires ImageMagick to be in the PATH.

import re
import os.path
import json
import subprocess

DCS_PATH=r"D:\Program Files\Eagle Dynamics\DCS World"
DB_PATH=os.path.join(DCS_PATH, r"Scripts\Database")
FOLDER_SET=["vehicles", "navy", "helicopters", "planes"]
RESULT_PATH=r"D:\data\dcs-mission-planner\repo\vendors\eagledynamics\mapicons"

unitdata = {}
classifiers = set()

for folder in FOLDER_SET:
for (dirpath, dirnames, filenames) in os.walk(os.path.join(DB_PATH, folder)):
if len(filenames):
for filename in filter(lambda x: x.endswith(".lua"), filenames):
with open(os.path.join(dirpath, filename), "r") as f:
lua = f.read()
if folder in ("planes", "helicopters"):
name_match = re.findall(r'return '+folder[:-1]+'\( ?"([^"]+)"', lua)
else:
name_match = re.findall(r'GT.Name = "([^"]+)"', lua)
displayname_match = re.findall(r'GT.DisplayName = _\("([^"]+)"', lua)
mapclasskey_match = re.findall(r'mapclasskey = "([^"]+)"', lua)

if name_match and mapclasskey_match:
name = name_match[-1]
mapclasskey = mapclasskey_match[-1]
displayname = (displayname_match[-1] if displayname_match else "")

unitdata[name] = {'mapclasskey':mapclasskey,
'display_name': displayname,
}
classifiers.add(mapclasskey)

for (name, data) in unitdata.items():
mapclasskey = data["mapclasskey"]
withoutp = mapclasskey[1:]
imgbasename = "P%d" % int(withoutp) # remove leading zero
data["iconbasename"] = imgbasename
imagefilename = os.path.join(DCS_PATH, r"MissionEditor\data\NewMap\images\themes\nato", imgbasename)+".png"
redresultfilename = os.path.join(RESULT_PATH, imgbasename)+"_red.png"
blueresultfilename = os.path.join(RESULT_PATH, imgbasename)+"_blue.png"

p = subprocess.Popen(["composite", "red.png", "-channel", "RGB", "-compose", "multiply", imagefilename, redresultfilename])
p.communicate()
p = subprocess.Popen(["composite", "blue.png", "-channel", "RGB", "-compose", "multiply", imagefilename, blueresultfilename])
p.communicate()

with open("unitdata.json", "w") as f:
json.dump(unitdata, f)
Binary file added scripts/extract-mapicons-and-metadata/red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions vendors/eagledynamics/COPYING.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The content of this directory is derived from DCS: World, (C) Eagle Dynamics
and is redistributed with their permission.
Binary file added vendors/eagledynamics/mapicons/P91000001_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000001_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000002_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000002_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000003_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000003_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000004_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000004_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000005_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000005_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000006_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000006_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000014_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000014_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000015_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000015_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000017_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000017_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000020_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000020_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000021_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000021_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000023_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vendors/eagledynamics/mapicons/P91000023_red.png
Binary file added vendors/eagledynamics/mapicons/P91000024_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000024_red.png
Binary file added vendors/eagledynamics/mapicons/P91000025_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000025_red.png
Binary file added vendors/eagledynamics/mapicons/P91000026_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000026_red.png
Binary file added vendors/eagledynamics/mapicons/P91000027_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000027_red.png
Binary file added vendors/eagledynamics/mapicons/P91000029_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000029_red.png
Binary file added vendors/eagledynamics/mapicons/P91000036_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000036_red.png
Binary file added vendors/eagledynamics/mapicons/P91000038_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000038_red.png
Binary file added vendors/eagledynamics/mapicons/P91000039_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000039_red.png
Binary file added vendors/eagledynamics/mapicons/P91000045_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000045_red.png
Binary file added vendors/eagledynamics/mapicons/P91000046_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000046_red.png
Binary file added vendors/eagledynamics/mapicons/P91000050_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000050_red.png
Binary file added vendors/eagledynamics/mapicons/P91000056_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000056_red.png
Binary file added vendors/eagledynamics/mapicons/P91000062_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000062_red.png
Binary file added vendors/eagledynamics/mapicons/P91000063_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000063_red.png
Binary file added vendors/eagledynamics/mapicons/P91000064_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000064_red.png
Binary file added vendors/eagledynamics/mapicons/P91000065_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000065_red.png
Binary file added vendors/eagledynamics/mapicons/P91000066_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000066_red.png
Binary file added vendors/eagledynamics/mapicons/P91000067_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000067_red.png
Binary file added vendors/eagledynamics/mapicons/P91000069_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000069_red.png
Binary file added vendors/eagledynamics/mapicons/P91000070_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000070_red.png
Binary file added vendors/eagledynamics/mapicons/P91000075_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000075_red.png
Binary file added vendors/eagledynamics/mapicons/P91000076_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000076_red.png
Binary file added vendors/eagledynamics/mapicons/P91000079_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000079_red.png
Binary file added vendors/eagledynamics/mapicons/P91000080_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000080_red.png
Binary file added vendors/eagledynamics/mapicons/P91000081_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000081_red.png
Binary file added vendors/eagledynamics/mapicons/P91000082_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000082_red.png
Binary file added vendors/eagledynamics/mapicons/P91000083_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000083_red.png
Binary file added vendors/eagledynamics/mapicons/P91000084_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000084_red.png
Binary file added vendors/eagledynamics/mapicons/P91000085_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000085_red.png
Binary file added vendors/eagledynamics/mapicons/P91000086_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000086_red.png
Binary file added vendors/eagledynamics/mapicons/P91000087_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000087_red.png
Binary file added vendors/eagledynamics/mapicons/P91000096_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000096_red.png
Binary file added vendors/eagledynamics/mapicons/P91000201_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000201_red.png
Binary file added vendors/eagledynamics/mapicons/P91000202_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000202_red.png
Binary file added vendors/eagledynamics/mapicons/P91000203_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000203_red.png
Binary file added vendors/eagledynamics/mapicons/P91000204_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000204_red.png
Binary file added vendors/eagledynamics/mapicons/P91000205_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000205_red.png
Binary file added vendors/eagledynamics/mapicons/P91000208_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000208_red.png
Binary file added vendors/eagledynamics/mapicons/P91000209_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000209_red.png
Binary file added vendors/eagledynamics/mapicons/P91000211_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000211_red.png
Binary file added vendors/eagledynamics/mapicons/P91000212_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000212_red.png
Binary file added vendors/eagledynamics/mapicons/P91000213_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000213_red.png
Binary file added vendors/eagledynamics/mapicons/P91000214_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000214_red.png
Binary file added vendors/eagledynamics/mapicons/P91000215_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000215_red.png
Binary file added vendors/eagledynamics/mapicons/P91000216_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000216_red.png
Binary file added vendors/eagledynamics/mapicons/P91000217_blue.png
Binary file added vendors/eagledynamics/mapicons/P91000217_red.png

0 comments on commit 1ecb331

Please sign in to comment.