AdjustExitName splits an exit identifier into a base name and an optional direction. Supported formats: "east" → ("east", "east", nil) "east-x2" → ("east", "east-x2", nil) "cave" → ("cave", "", nil) "cave:south" → ("cave", "south", nil) "cave:south-x2" → ("
(exitName string)
| 1209 | // "cave:south" → ("cave", "south", nil) |
| 1210 | // "cave:south-x2" → ("cave", "south-x2", nil) |
| 1211 | func AdjustExitName(exitName string) (newExitName, newExitDirection string, err error) { |
| 1212 | // Start with the raw name and no direction. |
| 1213 | newExitName = exitName |
| 1214 | newExitDirection = "" |
| 1215 | |
| 1216 | // 1) "exitName:exitDirection" syntax |
| 1217 | if i := strings.Index(exitName, ":"); i >= 0 { |
| 1218 | |
| 1219 | if strings.Contains(exitName[:i], `-`) { |
| 1220 | return exitName, "", fmt.Errorf("mixed `-` syntax with `:` in exit name: %s. `-` should only be in direction modifier or stand alone exit name.", exitName) |
| 1221 | } |
| 1222 | |
| 1223 | newExitName = exitName[:i] |
| 1224 | |
| 1225 | // pure compass directions |
| 1226 | if IsValidExitDirection(exitName[i+1:]) { |
| 1227 | newExitDirection = exitName[i+1:] |
| 1228 | } |
| 1229 | |
| 1230 | } else if IsValidExitDirection(exitName) { |
| 1231 | newExitDirection = exitName |
| 1232 | } |
| 1233 | |
| 1234 | // 2) special directions without colon (“north-x2”) |
| 1235 | if strings.Contains(newExitName, `-`) { |
| 1236 | |
| 1237 | if !IsValidExitDirection(newExitName) { |
| 1238 | return exitName, "", fmt.Errorf(`invalid "special" exit name: %s`, newExitName) |
| 1239 | } |
| 1240 | |
| 1241 | newExitDirection = newExitName |
| 1242 | |
| 1243 | parts := strings.SplitN(exitName, `-`, 2) |
| 1244 | newExitName = parts[0] |
| 1245 | } |
| 1246 | |
| 1247 | return newExitName, newExitDirection, nil |
| 1248 | } |
| 1249 | |
| 1250 | ///////////////////////////////////////////// |
| 1251 | // EXPERIMENTAL |