Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions internal/rooms/rooms.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/GoMudEngine/GoMud/internal/exit"
"github.com/GoMudEngine/GoMud/internal/gametime"
"github.com/GoMudEngine/GoMud/internal/items"
"github.com/GoMudEngine/GoMud/internal/keywords"
"github.com/GoMudEngine/GoMud/internal/mobs"
"github.com/GoMudEngine/GoMud/internal/mutators"
"github.com/GoMudEngine/GoMud/internal/users"
Expand All @@ -29,6 +30,7 @@ var (
"*": defaultMapSymbol,
//"•": "*",
}

)

type FindFlag uint16
Expand Down Expand Up @@ -1716,6 +1718,29 @@ func (r *Room) FindNoun(noun string) (foundNoun string, nounDescription string)

func (r *Room) FindExitByName(exitNameSearch string) (exitName string, exitRoomId int) {

// Check for direction aliases from keywords.yaml first
fullDirection := keywords.TryDirectionAlias(exitNameSearch)
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding a comment or refactoring to clarify that fuzzy matching is purposefully limited to r.Exits (excluding temporary and mutator exits) to ensure consistent behavior for direction abbreviations.

Copilot uses AI. Check for mistakes.
if fullDirection != exitNameSearch {
// A direction alias was found, check if this exact direction exists
if exitInfo, ok := r.Exits[fullDirection]; ok {
return fullDirection, exitInfo.RoomId
}
// Check temporary exits
if tempExit, ok := r.ExitsTemp[fullDirection]; ok {
return fullDirection, tempExit.RoomId
}
// Check mutator exits
for mut := range r.ActiveMutators {
spec := mut.GetSpec()
if exitInfo, ok := spec.Exits[fullDirection]; ok {
return fullDirection, exitInfo.RoomId
}
}
// Direction alias used but exit doesn't exist
return ``, 0
}

// Build list of all exits for fuzzy matching
exitNames := []string{}
for exitName, _ := range r.Exits {
exitNames = append(exitNames, exitName)
Expand All @@ -1734,21 +1759,10 @@ func (r *Room) FindExitByName(exitNameSearch string) (exitName string, exitRoomI
}
}

// Use fuzzy matching for all exits
exactMatch, closeMatch := util.FindMatchIn(exitNameSearch, exitNames...)

if len(exactMatch) == 0 {

exactMatchesRequired := []string{
`southeast`, `southwest`,
`northeast`, `northwest`,
}
// Do not allow prefix matches on southwest etc
for _, requiredCloseMatchTerm := range exactMatchesRequired {
if requiredCloseMatchTerm == closeMatch {
return "", 0
}
}

portalStr := `portal`
if strings.HasPrefix(closeMatch, exitNameSearch) {
exactMatch = closeMatch
Expand Down