Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Set a property of the room. This updates basic properties of the room you are in
Exits:
You can interactively add/remove/edit exits using the command:
<ansi fg="command">room edit exits</ansi>
Mutators:
You can interactively add/remove mutators to the room using the command:
<ansi fg="command">room edit mutators</ansi>

<ansi fg="command">room exit [exit_name] [room_id]</ansi> - e.g. <ansi fg="command">room exit west 159</ansi>
This will create a new exit that links to a specific room_id using the exit_name provided.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Set a property of the room. This updates basic properties of the room you are in
Exits:
You can interactively add/remove/edit exits using the command:
<ansi fg="command">room edit exits</ansi>
Mutators:
You can interactively add/remove mutators to the room using the command:
<ansi fg="command">room edit mutators</ansi>

<ansi fg="command">room exit [exit_name] [room_id]</ansi> - e.g. <ansi fg="command">room exit west 159</ansi>
This will create a new exit that links to a specific room_id using the exit_name provided.
Expand Down
160 changes: 158 additions & 2 deletions internal/usercommands/admin.room.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ func Room(rest string, user *users.UserRecord, room *rooms.Room) (bool, error) {
return room_Edit_Exits(``, user, room)
}

user.SendText(`<ansi fg="red">edit WHAT?</ansi> Try: <ansi fg="command">help room</ansi>`)
if rest == `edit mutator` || rest == `edit mutators` {
return room_Edit_Mutators(``, user, room)
}

user.SendText(`<ansi fg="red">edit WHAT?</ansi> Try:`)
user.SendText(` <ansi fg="command">room edit containers</ansi>`)
user.SendText(` <ansi fg="command">room edit exits</ansi>`)
user.SendText(` <ansi fg="command">room edit mutators</ansi>`)

return true, nil
}

Expand Down Expand Up @@ -691,6 +699,7 @@ func room_Edit_Containers(rest string, user *users.UserRecord, room *rooms.Room)
for idx, buffId := range selectedBuffList {
if buffId == buffSelectedInt {
selectedBuffList = append(selectedBuffList[0:idx], selectedBuffList[idx+1:]...)
break
}
}

Expand Down Expand Up @@ -1037,7 +1046,7 @@ func room_Edit_Exits(rest string, user *users.UserRecord, room *rooms.Room) (boo
}

if c.Secret {
exitOpt.Description += `[secret] `
exitOpt.Description += `[hidden] `
}

exitOptions = append(exitOptions, exitOpt)
Expand Down Expand Up @@ -1172,6 +1181,24 @@ func room_Edit_Exits(rest string, user *users.UserRecord, room *rooms.Room) (boo

}

//
// Secret exit?
//
{
secretExitDefault := `no`
if currentlyEditing.Exit.Secret {
secretExitDefault = `yes`
}

// allow them to name/rename the exit.
question := cmdPrompt.Ask(`Is this a hidden exit?`, []string{`yes`, `no`}, secretExitDefault)
if !question.Done {
return true, nil
}

currentlyEditing.Exit.Secret = question.Response == `yes`
}

//
// Lock Options
//
Expand Down Expand Up @@ -1303,6 +1330,7 @@ func room_Edit_Exits(rest string, user *users.UserRecord, room *rooms.Room) (boo
for idx, buffId := range selectedBuffList {
if buffId == buffSelectedInt {
selectedBuffList = append(selectedBuffList[0:idx], selectedBuffList[idx+1:]...)
break
}
}

Expand Down Expand Up @@ -1384,3 +1412,131 @@ func room_Edit_Exits(rest string, user *users.UserRecord, room *rooms.Room) (boo

return true, nil
}

func room_Edit_Mutators(rest string, user *users.UserRecord, room *rooms.Room) (bool, error) {

allRoomMutators := []string{}
for _, roomMut := range room.Mutators {
allRoomMutators = append(allRoomMutators, roomMut.MutatorId)
}

cmdPrompt, _ := user.StartPrompt(`room edit mutators`, rest)

selectedMutatorList := []string{}
if muts, ok := cmdPrompt.Recall(`mutators`); ok {
selectedMutatorList = muts.([]string)
} else {
if len(selectedMutatorList) == 0 {
selectedMutatorList = append(selectedMutatorList, allRoomMutators...)
}
}

// Keep track of the state
cmdPrompt.Store(`mutators`, selectedMutatorList)

selectedMutatorLookup := map[string]bool{}
for _, mutId := range selectedMutatorList {
selectedMutatorLookup[mutId] = true
}

mutatorOptions := []templates.NameDescription{}

for _, mutId := range mutators.GetAllMutatorIds() {
marked := false
if _, ok := selectedMutatorLookup[mutId]; ok {
marked = true
}

mutatorOptions = append(mutatorOptions, templates.NameDescription{Id: mutId, Marked: marked, Name: mutId})

}

sort.SliceStable(mutatorOptions, func(i, j int) bool {
return mutatorOptions[i].Name < mutatorOptions[j].Name
})

question := cmdPrompt.Ask(`Select a mutator to add to the room, or nothing to continue:`, []string{}, `0`)
if !question.Done {
tplTxt, _ := templates.Process("tables/numbered-list-doubled", mutatorOptions)
user.SendText(tplTxt)
return true, nil
}

if question.Response != `0` {

mutatorSelected := ``

if restNum, err := strconv.Atoi(question.Response); err == nil {
if restNum > 0 && restNum <= len(mutatorOptions) {
mutatorSelected = mutatorOptions[restNum-1].Id.(string)
}
}

if mutatorSelected == `` {
for _, b := range mutatorOptions {
if strings.EqualFold(b.Name, question.Response) {
mutatorSelected = b.Id.(string)
break
}
}
}

if mutatorSelected == `` {

user.SendText("Invalid selection.")
question.RejectResponse()

tplTxt, _ := templates.Process("tables/numbered-list-doubled", mutatorOptions)
user.SendText(tplTxt)
return true, nil
}

if _, ok := selectedMutatorLookup[mutatorSelected]; ok {

delete(selectedMutatorLookup, mutatorSelected)
for idx, mutId := range selectedMutatorList {
if mutId == mutatorSelected {
selectedMutatorList = append(selectedMutatorList[0:idx], selectedMutatorList[idx+1:]...)
break
}
}

} else {

selectedMutatorList = append(selectedMutatorList, mutatorSelected)
selectedMutatorLookup[mutatorSelected] = true

}

cmdPrompt.Store(`mutators`, selectedMutatorList)

question.RejectResponse()

for idx, data := range mutatorOptions {
_, data.Marked = selectedMutatorLookup[data.Id.(string)]
mutatorOptions[idx] = data
}

tplTxt, _ := templates.Process("tables/numbered-list-doubled", mutatorOptions)
user.SendText(tplTxt)
return true, nil

}

//
// Done editing. Save results
//
room.Mutators = mutators.MutatorList{}
for _, mutId := range selectedMutatorList {
room.Mutators = append(room.Mutators, mutators.Mutator{MutatorId: mutId})
}
rooms.SaveRoom(*room)

user.SendText(``)
user.SendText(`Changes saved.`)
user.SendText(``)

user.ClearPrompt()

return true, nil
}
Loading