@@ -29,6 +29,22 @@ import { getGridPos, getMonumentsInfo, getDistance, Point } from '../utils/map';
2929import * as constants from '../utils/constants' ;
3030import { 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+
3248export 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