initial commit: canny cat basic movement, bouncing, some gridmap tiles for levels
This commit is contained in:
commit
e1b43c8bc5
120 changed files with 5785 additions and 0 deletions
54
addons/godot_state_charts/utilities/ring_buffer.gd
Normal file
54
addons/godot_state_charts/utilities/ring_buffer.gd
Normal file
|
@ -0,0 +1,54 @@
|
|||
|
||||
|
||||
## The content of the ring buffer
|
||||
var _content:Array[String] = []
|
||||
|
||||
## The current index in the ring buffer
|
||||
var _index = 0
|
||||
|
||||
## The size of the ring buffer
|
||||
var _size = 0
|
||||
|
||||
## Whether the buffer is fully populated
|
||||
var _filled = false
|
||||
|
||||
|
||||
func _init(size:int = 300):
|
||||
_size = size
|
||||
_content.resize(size)
|
||||
|
||||
|
||||
## Sets the maximum number of lines to store. This clears the buffer.
|
||||
func set_maximum_lines(lines:int):
|
||||
_size = lines
|
||||
_content.resize(lines)
|
||||
clear()
|
||||
|
||||
## Adds an item to the ring buffer
|
||||
func append(value:String):
|
||||
_content[_index] = value
|
||||
if _index + 1 < _size:
|
||||
_index += 1
|
||||
else:
|
||||
_index = 0
|
||||
_filled = true
|
||||
|
||||
|
||||
## Joins the items of the ring buffer into a big string
|
||||
func join():
|
||||
var result = ""
|
||||
if _filled:
|
||||
# start by _index + 1, run to the end and then continue from the start
|
||||
for i in range(_index, _size):
|
||||
result += _content[i]
|
||||
|
||||
# when not filled, just start at the beginning
|
||||
for i in _index:
|
||||
result += _content[i]
|
||||
|
||||
return result
|
||||
|
||||
|
||||
func clear():
|
||||
_index = 0
|
||||
_filled = false
|
Loading…
Add table
Add a link
Reference in a new issue