@@ -52,7 +52,15 @@ func Room(rest string, user *users.UserRecord, room *rooms.Room) (bool, error) {
5252 return room_Edit_Exits (`` , user , room )
5353 }
5454
55- user .SendText (`<ansi fg="red">edit WHAT?</ansi> Try: <ansi fg="command">help room</ansi>` )
55+ if rest == `edit mutator` || rest == `edit mutators` {
56+ return room_Edit_Mutators (`` , user , room )
57+ }
58+
59+ user .SendText (`<ansi fg="red">edit WHAT?</ansi> Try:` )
60+ user .SendText (` <ansi fg="command">room edit containers</ansi>` )
61+ user .SendText (` <ansi fg="command">room edit exits</ansi>` )
62+ user .SendText (` <ansi fg="command">room edit mutators</ansi>` )
63+
5664 return true , nil
5765 }
5866
@@ -691,6 +699,7 @@ func room_Edit_Containers(rest string, user *users.UserRecord, room *rooms.Room)
691699 for idx , buffId := range selectedBuffList {
692700 if buffId == buffSelectedInt {
693701 selectedBuffList = append (selectedBuffList [0 :idx ], selectedBuffList [idx + 1 :]... )
702+ break
694703 }
695704 }
696705
@@ -1037,7 +1046,7 @@ func room_Edit_Exits(rest string, user *users.UserRecord, room *rooms.Room) (boo
10371046 }
10381047
10391048 if c .Secret {
1040- exitOpt .Description += `[secret ] `
1049+ exitOpt .Description += `[hidden ] `
10411050 }
10421051
10431052 exitOptions = append (exitOptions , exitOpt )
@@ -1172,6 +1181,24 @@ func room_Edit_Exits(rest string, user *users.UserRecord, room *rooms.Room) (boo
11721181
11731182 }
11741183
1184+ //
1185+ // Secret exit?
1186+ //
1187+ {
1188+ secretExitDefault := `no`
1189+ if currentlyEditing .Exit .Secret {
1190+ secretExitDefault = `yes`
1191+ }
1192+
1193+ // allow them to name/rename the exit.
1194+ question := cmdPrompt .Ask (`Is this a hidden exit?` , []string {`yes` , `no` }, secretExitDefault )
1195+ if ! question .Done {
1196+ return true , nil
1197+ }
1198+
1199+ currentlyEditing .Exit .Secret = question .Response == `yes`
1200+ }
1201+
11751202 //
11761203 // Lock Options
11771204 //
@@ -1303,6 +1330,7 @@ func room_Edit_Exits(rest string, user *users.UserRecord, room *rooms.Room) (boo
13031330 for idx , buffId := range selectedBuffList {
13041331 if buffId == buffSelectedInt {
13051332 selectedBuffList = append (selectedBuffList [0 :idx ], selectedBuffList [idx + 1 :]... )
1333+ break
13061334 }
13071335 }
13081336
@@ -1384,3 +1412,131 @@ func room_Edit_Exits(rest string, user *users.UserRecord, room *rooms.Room) (boo
13841412
13851413 return true , nil
13861414}
1415+
1416+ func room_Edit_Mutators (rest string , user * users.UserRecord , room * rooms.Room ) (bool , error ) {
1417+
1418+ allRoomMutators := []string {}
1419+ for _ , roomMut := range room .Mutators {
1420+ allRoomMutators = append (allRoomMutators , roomMut .MutatorId )
1421+ }
1422+
1423+ cmdPrompt , _ := user .StartPrompt (`room edit mutators` , rest )
1424+
1425+ selectedMutatorList := []string {}
1426+ if muts , ok := cmdPrompt .Recall (`mutators` ); ok {
1427+ selectedMutatorList = muts .([]string )
1428+ } else {
1429+ if len (selectedMutatorList ) == 0 {
1430+ selectedMutatorList = append (selectedMutatorList , allRoomMutators ... )
1431+ }
1432+ }
1433+
1434+ // Keep track of the state
1435+ cmdPrompt .Store (`mutators` , selectedMutatorList )
1436+
1437+ selectedMutatorLookup := map [string ]bool {}
1438+ for _ , mutId := range selectedMutatorList {
1439+ selectedMutatorLookup [mutId ] = true
1440+ }
1441+
1442+ mutatorOptions := []templates.NameDescription {}
1443+
1444+ for _ , mutId := range mutators .GetAllMutatorIds () {
1445+ marked := false
1446+ if _ , ok := selectedMutatorLookup [mutId ]; ok {
1447+ marked = true
1448+ }
1449+
1450+ mutatorOptions = append (mutatorOptions , templates.NameDescription {Id : mutId , Marked : marked , Name : mutId })
1451+
1452+ }
1453+
1454+ sort .SliceStable (mutatorOptions , func (i , j int ) bool {
1455+ return mutatorOptions [i ].Name < mutatorOptions [j ].Name
1456+ })
1457+
1458+ question := cmdPrompt .Ask (`Select a mutator to add to the room, or nothing to continue:` , []string {}, `0` )
1459+ if ! question .Done {
1460+ tplTxt , _ := templates .Process ("tables/numbered-list-doubled" , mutatorOptions )
1461+ user .SendText (tplTxt )
1462+ return true , nil
1463+ }
1464+
1465+ if question .Response != `0` {
1466+
1467+ mutatorSelected := ``
1468+
1469+ if restNum , err := strconv .Atoi (question .Response ); err == nil {
1470+ if restNum > 0 && restNum <= len (mutatorOptions ) {
1471+ mutatorSelected = mutatorOptions [restNum - 1 ].Id .(string )
1472+ }
1473+ }
1474+
1475+ if mutatorSelected == `` {
1476+ for _ , b := range mutatorOptions {
1477+ if strings .EqualFold (b .Name , question .Response ) {
1478+ mutatorSelected = b .Id .(string )
1479+ break
1480+ }
1481+ }
1482+ }
1483+
1484+ if mutatorSelected == `` {
1485+
1486+ user .SendText ("Invalid selection." )
1487+ question .RejectResponse ()
1488+
1489+ tplTxt , _ := templates .Process ("tables/numbered-list-doubled" , mutatorOptions )
1490+ user .SendText (tplTxt )
1491+ return true , nil
1492+ }
1493+
1494+ if _ , ok := selectedMutatorLookup [mutatorSelected ]; ok {
1495+
1496+ delete (selectedMutatorLookup , mutatorSelected )
1497+ for idx , mutId := range selectedMutatorList {
1498+ if mutId == mutatorSelected {
1499+ selectedMutatorList = append (selectedMutatorList [0 :idx ], selectedMutatorList [idx + 1 :]... )
1500+ break
1501+ }
1502+ }
1503+
1504+ } else {
1505+
1506+ selectedMutatorList = append (selectedMutatorList , mutatorSelected )
1507+ selectedMutatorLookup [mutatorSelected ] = true
1508+
1509+ }
1510+
1511+ cmdPrompt .Store (`mutators` , selectedMutatorList )
1512+
1513+ question .RejectResponse ()
1514+
1515+ for idx , data := range mutatorOptions {
1516+ _ , data .Marked = selectedMutatorLookup [data .Id .(string )]
1517+ mutatorOptions [idx ] = data
1518+ }
1519+
1520+ tplTxt , _ := templates .Process ("tables/numbered-list-doubled" , mutatorOptions )
1521+ user .SendText (tplTxt )
1522+ return true , nil
1523+
1524+ }
1525+
1526+ //
1527+ // Done editing. Save results
1528+ //
1529+ room .Mutators = mutators.MutatorList {}
1530+ for _ , mutId := range selectedMutatorList {
1531+ room .Mutators = append (room .Mutators , mutators.Mutator {MutatorId : mutId })
1532+ }
1533+ rooms .SaveRoom (* room )
1534+
1535+ user .SendText (`` )
1536+ user .SendText (`Changes saved.` )
1537+ user .SendText (`` )
1538+
1539+ user .ClearPrompt ()
1540+
1541+ return true , nil
1542+ }
0 commit comments