-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
23 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
extends Node | ||
|
||
## Finds the next object in [param array] after [param starting_from], wrapping around to `null` if the end of the array is reached. | ||
func cycle_through(array: Array, starting_from: Variant) -> Variant: | ||
if array.size() == 0: | ||
return null | ||
|
||
if starting_from == null: | ||
return array[0] | ||
|
||
var index := array.find(starting_from) | ||
assert(index >= 0, "Cannot find starting_from in array") | ||
|
||
return array[index + 1] if index + 1 < array.size() else null |