Skip to content

Instantly share code, notes, and snippets.

@RobinKuiper
Last active April 18, 2018 08:18
Show Gist options
  • Save RobinKuiper/ce48b3f61cdee1d82d202748508ddb9a to your computer and use it in GitHub Desktop.
Save RobinKuiper/ce48b3f61cdee1d82d202748508ddb9a to your computer and use it in GitHub Desktop.
// Fire when the turnorder is changed.
on('change:campaign:turnorder', (obj, prev) => {
// Check if the turnorder is changed, otherwise cancel
if(obj.get('turnorder') === prev.turnorder) return;
// Parse the turnorder to an object, and sort it Ascending.
let turnorder = JSON.parse(obj.get('turnorder')).sort((a,b) => { return a.pr - b.pr });
// Set the new turnorder order.
obj.set('turnorder', JSON.stringify(turnorder));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment