Created
April 5, 2016 17:49
-
-
Save laverdet/ace36f6a3b666f616601f6790d2c0938 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[...] | |
// Reverse of parseRoomName | |
renderRoomName(room) { | |
if (room[0] === 255) { | |
return 'sim'; | |
} | |
return ( | |
(room[0] < 0 ? 'W'+ (-room[0] - 1) : 'E'+ room[0])+ | |
(room[1] < 0 ? 'N'+ (-room[1] - 1) : 'S'+ room[1]) | |
); | |
}, | |
[....] | |
// Return world offset from origin | |
parseRoomName() { | |
if (this.roomName === 'sim') { | |
return [255, 255]; | |
} else { | |
let room = /^([WE])([0-9]+)([NS])([0-9]+)$/.exec(this.roomName); | |
if (!room) { | |
throw new Error('Invalid room name'); | |
} | |
return [ | |
room[1] === 'W' ? -room[2] - 1 : +room[2], | |
room[3] === 'N' ? -room[4] - 1 : +room[4], | |
]; | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment