@@ -18,6 +18,7 @@ import (
1818 common "github.com/markus-wa/demoinfocs-golang/common"
1919 events "github.com/markus-wa/demoinfocs-golang/events"
2020 ex "github.com/markus-wa/demoinfocs-golang/examples"
21+ "github.com/markus-wa/demoinfocs-golang/metadata"
2122 st "github.com/markus-wa/demoinfocs-golang/sendtables"
2223)
2324
3536 colorFlash color.Color = color.RGBA {0x00 , 0x00 , 0xff , 0xff } // Blue, because of the color on the nade
3637 colorSmoke color.Color = color.RGBA {0xbe , 0xbe , 0xbe , 0xff } // Light gray
3738 colorDecoy color.Color = color.RGBA {0x96 , 0x4b , 0x00 , 0xff } // Brown, because it's shit :)
39+ curMap metadata.Map
3840)
3941
4042type inferno []r3.Vector
@@ -55,9 +57,11 @@ func main() {
5557
5658 p := dem .NewParser (f )
5759
58- _ , err = p .ParseHeader ()
60+ hd , err : = p .ParseHeader ()
5961 checkError (err )
6062
63+ curMap = metadata .MapNameToMap [hd .MapName ]
64+
6165 nadeTrajectories := make (map [int64 ]* nadePath ) // Trajectories of all destroyed nades
6266
6367 p .RegisterEventHandler (func (e events.NadeProjectileDestroyedEvent ) {
@@ -122,18 +126,18 @@ func main() {
122126 err = p .ParseToEnd ()
123127 checkError (err )
124128
125- // Draw image
126-
127- // Create output canvas
128- dest := image .NewRGBA (image .Rect (0 , 0 , 1024 , 1024 ))
129-
130129 // Use cache map overview as base
131- fCache , err := os .Open ("../de_cache. jpg" )
130+ fMap , err := os .Open (fmt . Sprintf ( "../../metadata/maps/%s. jpg" , hd . MapName ) )
132131 checkError (err )
133132
134- imgCache , _ , err := image .Decode (fCache )
133+ imgMap , _ , err := image .Decode (fMap )
135134 checkError (err )
136- draw .Draw (dest , dest .Bounds (), imgCache , image.Point {0 , 0 }, draw .Src )
135+
136+ // Create output canvas
137+ dest := image .NewRGBA (imgMap .Bounds ())
138+
139+ // Draw image
140+ draw .Draw (dest , dest .Bounds (), imgMap , image.Point {0 , 0 }, draw .Src )
137141
138142 // Initialize the graphic context
139143 gc := draw2dimg .NewGraphicContext (dest )
@@ -171,11 +175,15 @@ func drawInfernos(gc *draw2dimg.GraphicContext, hulls []*s2.Loop) {
171175
172176func buildInfernoPath (gc * draw2dimg.GraphicContext , hull * s2.Loop ) {
173177 vertices := hull .Vertices ()
174- gc .MoveTo (translateX (vertices [0 ].X ), translateY (vertices [0 ].Y ))
178+ x , y , _ := curMap .TranslateScale (vertices [0 ].X , vertices [0 ].Y , 0 )
179+ gc .MoveTo (x , y )
180+
175181 for _ , fire := range vertices [1 :] {
176- gc .LineTo (translateX (fire .X ), translateY (fire .Y ))
182+ x , y , _ := curMap .TranslateScale (fire .X , fire .Y , 0 )
183+ gc .LineTo (x , y )
177184 }
178- gc .LineTo (translateX (vertices [0 ].X ), translateY (vertices [0 ].Y ))
185+
186+ gc .LineTo (x , y )
179187}
180188
181189func drawTrajectories (gc * draw2dimg.GraphicContext , trajectories []* nadePath ) {
@@ -209,38 +217,18 @@ func drawTrajectories(gc *draw2dimg.GraphicContext, trajectories []*nadePath) {
209217 }
210218
211219 // Draw path
212- gc .MoveTo (translateX (np .path [0 ].X ), translateY (np .path [0 ].Y )) // Move to a position to start the new path
220+ x , y , _ := curMap .TranslateScale (np .path [0 ].X , np .path [0 ].Y , 0 )
221+ gc .MoveTo (x , y ) // Move to a position to start the new path
213222
214223 for _ , pos := range np .path [1 :] {
215- gc .LineTo (translateX (pos .X ), translateY (pos .Y ))
224+ x , y , _ := curMap .TranslateScale (pos .X , pos .Y , 0 )
225+ gc .LineTo (x , y )
216226 }
217227
218228 gc .FillStroke ()
219229 }
220230}
221231
222- // Rough translations for x & y coordinates from de_cache to 1024x1024 px.
223- // This could be done nicer by only having to provide the mapping between two source & target coordinates and the max size.
224- // Then we could calculate the correct stretch & offset automatically.
225-
226- func translateX (x float64 ) float64 {
227- const (
228- stretch = 0.18
229- offset = 414
230- )
231-
232- return x * stretch + offset
233- }
234-
235- func translateY (y float64 ) float64 {
236- const (
237- stretch = - 0.18
238- offset = 630
239- )
240-
241- return y * stretch + offset
242- }
243-
244232func checkError (err error ) {
245233 if err != nil {
246234 log .Fatal (err )
0 commit comments