I took cursingbulldog's advice, though didn't take it all the way up to 54. I converted face cards to values 11 - 15 (jokers are both 15), and figured out the char codes for the suit shapes and assigned them a number of 1 - 4. In the case of a tie, I add the suit number to the card number then subtract the first from the second to see if it should be before or after it in the list. I then reverse the list after the sort. on('change:campaign:turnorder',function(obj){ var swInitiativeManager = { compare: function (card1, card2) { var val1 = this.faceToNumber(card1.substring(0, card1.length - 1)); var val2 = this.faceToNumber(card2.substring(0, card2.length - 1)); var suit1 = this.codeToSuit(card1.charCodeAt(card1.length - 1)); var suit2 = this.codeToSuit(card2.charCodeAt(card2.length - 1)); if (val1 == val2) { val1 += suit1; val2 += suit2; } return val1 - val2; }, faceToNumber: function (value) { if (isNaN(value)) { switch (value.toUpperCase()) { case 'RJ': case 'BJ': return 15; case 'A': return 14; case 'K': return 13; case 'Q': return 12; case 'JA': return 11; } }else{ return value; } }, codeToSuit: function (value) { switch (value) { case 9827: // clubs return 1; case 9830: // diamonds return 2; case 9829: // hearts return 3; case 9824: // spades return 4; default: // joker return value; } } };
var turnOrderRaw = obj.get('turnorder'); var turnOrder = []; if(turnOrderRaw != ''){ turnOrder = JSON.parse(turnOrderRaw); } turnOrder.sort(function(a,b){ return swInitiativeManager.compare(a.pr,b.pr); }).reverse(); Campaign().set('turnorder',JSON.stringify(turnOrder)); });