diff --git a/_datafiles/world/default/templates/admincommands/help/command.room.template b/_datafiles/world/default/templates/admincommands/help/command.room.template index e95f9b14..ab848207 100644 --- a/_datafiles/world/default/templates/admincommands/help/command.room.template +++ b/_datafiles/world/default/templates/admincommands/help/command.room.template @@ -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: room edit exits + Mutators: + You can interactively add/remove mutators to the room using the command: + room edit mutators room exit [exit_name] [room_id] - e.g. room exit west 159 This will create a new exit that links to a specific room_id using the exit_name provided. diff --git a/_datafiles/world/empty/templates/admincommands/help/command.room.template b/_datafiles/world/empty/templates/admincommands/help/command.room.template index e95f9b14..ab848207 100644 --- a/_datafiles/world/empty/templates/admincommands/help/command.room.template +++ b/_datafiles/world/empty/templates/admincommands/help/command.room.template @@ -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: room edit exits + Mutators: + You can interactively add/remove mutators to the room using the command: + room edit mutators room exit [exit_name] [room_id] - e.g. room exit west 159 This will create a new exit that links to a specific room_id using the exit_name provided. diff --git a/internal/usercommands/admin.room.go b/internal/usercommands/admin.room.go index 921ec2e4..82fe77fb 100644 --- a/internal/usercommands/admin.room.go +++ b/internal/usercommands/admin.room.go @@ -52,7 +52,15 @@ func Room(rest string, user *users.UserRecord, room *rooms.Room) (bool, error) { return room_Edit_Exits(``, user, room) } - user.SendText(`edit WHAT? Try: help room`) + if rest == `edit mutator` || rest == `edit mutators` { + return room_Edit_Mutators(``, user, room) + } + + user.SendText(`edit WHAT? Try:`) + user.SendText(` room edit containers`) + user.SendText(` room edit exits`) + user.SendText(` room edit mutators`) + return true, nil } @@ -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 } } @@ -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) @@ -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 // @@ -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 } } @@ -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 +}