Skip to content

Commit 62dafaf

Browse files
committed
Use real map name instead of package name for OnMapSelected
1 parent a1e8325 commit 62dafaf

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

common/package.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ package common
2020

2121
import (
2222
"fmt"
23+
"path/filepath"
24+
"strings"
2325
"time"
2426
)
2527

@@ -70,7 +72,18 @@ func (pkg Package) Marshal() []byte {
7072
if pkg.Type == "map" {
7173
script["uid"] = fmt.Sprintf("map_%d", pkg.ID)
7274
script["luamenu_installed"] = "OnMapDownloaded();"
73-
script["luamenu_action"] = fmt.Sprintf("OnMapSelected( '%s' );", pkg.Name)
75+
76+
// find true name if it's different
77+
mapname := pkg.Name
78+
for _, c := range pkg.Content {
79+
if filepath.Ext(c.Path) != ".bsp" {
80+
continue
81+
}
82+
83+
mapname = strings.TrimSuffix(filepath.Base(c.Path), filepath.Ext(c.Path))
84+
}
85+
86+
script["luamenu_action"] = fmt.Sprintf("OnMapSelected('%s');", mapname)
7487
}
7588

7689
if len(pkg.Content) != 0 {

0 commit comments

Comments
 (0)