Skip to content

Commit 5b24262

Browse files
committed
Add map markers to map command
1 parent ddc4614 commit 5b24262

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

src/discordGuildSlashCommands/map.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ export default {
5555
.addBooleanOption(option => option
5656
.setName('markers')
5757
.setDescription(lm.getIntl(language, 'slashCommandDescMapMarkers'))
58+
.setRequired(false))
59+
.addBooleanOption(option => option
60+
.setName('tracers')
61+
.setDescription(lm.getIntl(language, 'slashCommandDescMapTracers'))
5862
.setRequired(false));
5963
},
6064

@@ -82,6 +86,7 @@ export default {
8286
const grids = interaction.options.getBoolean('grids', false) ?? complete;
8387
const monuments = interaction.options.getBoolean('monuments', false) ?? complete;
8488
const markers = interaction.options.getBoolean('markers', false) ?? complete;
89+
const tracers = interaction.options.getBoolean('tracers', false) ?? complete;
8590

8691
if (!Object.keys(gInstance.serverInfoMap).includes(serverId)) {
8792
const parameters = {
@@ -108,7 +113,7 @@ export default {
108113
return false;
109114
}
110115

111-
const imageName = await (rpInstance.rpMap as RustPlusMap).writeImage(grids, monuments, markers);
116+
const imageName = await (rpInstance.rpMap as RustPlusMap).writeImage(grids, monuments, markers, tracers);
112117
await discordMessages.sendMapMessage(dm, interaction, serverId, imageName);
113118
log.info(`${fn} ${id} Showing the map.`, logParam);
114119

src/languages/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@
321321
"slashCommandDescMapComplete": "Get the complete map with grids, monuments and markers.",
322322
"slashCommandDescMapGrids": "Get the map with grids.",
323323
"slashCommandDescMapMarkers": "Get the map with markers.",
324+
"slashCommandDescMapTracers": "Get the map with tracers.",
324325
"slashCommandDescMapMonuments": "Get the map with monuments.",
325326
"slashCommandDescMapServer": "The server to retrieve the map from.",
326327
"slashCommandDescRole": "Manage roles and admin roles.",
File renamed without changes.

src/structures/rustPlusMap.ts

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ import { getGridPos, getMonumentsInfo, getDistance, Point } from '../utils/map';
2929
import * as constants from '../utils/constants';
3030
import { GuildInstance } from '../managers/guildInstanceManager';
3131

32+
const MARKERS_PATH = path.join(__dirname, '..', 'resources/images/markers/');
33+
const NOTE_MARKERS_PATH = path.join(__dirname, '..', 'resources/images/note_markers/');
34+
35+
const MARKER_ICON_MAP: Record<rp.AppMarkerType, string> = {
36+
[rp.AppMarkerType.Undefined]: '',
37+
[rp.AppMarkerType.Player]: 'player',
38+
[rp.AppMarkerType.Explosion]: 'explosion',
39+
[rp.AppMarkerType.VendingMachine]: 'vending_machine',
40+
[rp.AppMarkerType.CH47]: 'chinook_body',
41+
[rp.AppMarkerType.CargoShip]: 'cargo_ship_body',
42+
[rp.AppMarkerType.Crate]: 'crate',
43+
[rp.AppMarkerType.GenericRadius]: 'chinook_blade',
44+
[rp.AppMarkerType.PatrolHelicopter]: 'patrol_helicopter_body',
45+
[rp.AppMarkerType.TravellingVendor]: 'travelling_vendor'
46+
}
47+
3248
export class RustPlusMap {
3349
public rpInstance: RustPlusInstance;
3450
public appMap: rp.AppMap;
@@ -92,8 +108,8 @@ export class RustPlusMap {
92108
}
93109
}
94110

95-
public async writeImage(grids: boolean = false, monuments: boolean = false, markers: boolean = false):
96-
Promise<string> {
111+
public async writeImage(grids: boolean = false, monuments: boolean = false, markers: boolean = false,
112+
tracers: boolean = false): Promise<string> {
97113
RustPlusMap.registerFonts();
98114

99115
const cleanImage = grids === false && monuments === false;
@@ -108,7 +124,7 @@ export class RustPlusMap {
108124
if (grids) this.drawGridSystem(ctx);
109125
if (monuments) await this.drawMonuments(ctx);
110126
if (markers) await this.drawMarkers(ctx);
111-
// TODO! tracer for cargoship, patrol helicopter, travelling vendor, chinook 47
127+
if (tracers) await this.drawTracers(ctx);
112128

113129
const outBuffer = canvas.toBuffer('image/png');
114130
fs.writeFileSync(`maps/${imageName}`, outBuffer);
@@ -216,6 +232,43 @@ export class RustPlusMap {
216232

217233
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
218234
private async drawMarkers(ctx: SKRSContext2D) {
235+
const rpMapMarkers = this.rpInstance.rpMapMarkers;
236+
if (!rpMapMarkers) return;
237+
const mapSize = this.rpInstance.rpInfo?.appInfo.mapSize;
238+
if (!mapSize) return;
239+
240+
const width = this.appMap.width;
241+
const height = this.appMap.height;
242+
const oceanMargin = this.appMap.oceanMargin;
243+
244+
for (const marker of this.rpInstance.rpMapMarkers!.appMapMarkers.markers) {
245+
const x = marker.x * ((width - 2 * oceanMargin) / mapSize) + oceanMargin;
246+
const n = height - 2 * oceanMargin;
247+
const y = height - (marker.y * (n / mapSize) + oceanMargin);
248+
249+
let iconPath = MARKER_ICON_MAP[marker.type as rp.AppMarkerType];
250+
if (marker.type === rp.AppMarkerType.VendingMachine) {
251+
iconPath += marker.outOfStock ? '_inactive' : '_active';
252+
}
253+
254+
const markerIcon = await loadImage(path.join(MARKERS_PATH, `${iconPath}.png`));
255+
256+
const scale = 0.3;
257+
const iconWidth = markerIcon.width * scale;
258+
const iconHeight = markerIcon.height * scale;
259+
const radians = Math.abs(marker.rotation - 360) * (Math.PI / 180);
260+
261+
ctx.save();
262+
ctx.translate(x, y);
263+
ctx.rotate(radians);
264+
ctx.drawImage(markerIcon, -iconWidth / 2, -iconHeight / 2, iconWidth, iconHeight);
265+
ctx.restore();
266+
}
267+
268+
// TODO! Add note markers from teaminfo
269+
}
270+
271+
private async drawTracers(ctx: SKRSContext2D) {
219272
// TODO! TBD
220273
}
221274

0 commit comments

Comments
 (0)