I was trying to think of an easy way to move a token to a different position in the initiative panel and I don't see a method other than rewriting the entire initiative. I don't want to use sort because the move may not reflect the values. Can we get a function or two for that?
Let's say that there are 10 tokens in initiative (0-9) and the current token is 3. I want to take another token at a different position and insert them before the current token.
token - id of token in initiative
position - value of the position of the token (starts at 0)
moveInInitiative(old position, new position): complete
old position - this is the current position of the token to be moved (see getInitiativePosition)
new position - this is the new position of token. All tokens with the same or greater position are moved
up in position up to the old position.
complete - 0 if move could not be done due to invalid position values, 1 if move takes place.
This is simulating essentially what can only be done manually in MapTool, dragging one token to another position in the panel.
As a side note, putting a position greater than the max position puts it after the last position. So, a move from 3 to 10 (in a 0-9 array) will put new position at 9 and decrement 4-9 to 3-8.
I also think the sort function should include an ascending/descending option.