mirror of
https://github.com/Mestima/GodotStack.git
synced 2025-05-03 12:50:14 +00:00
Initial commit
This commit is contained in:
commit
c121073f62
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/__pycache__
|
||||
*.obj
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Mestima
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
26
README.md
Normal file
26
README.md
Normal file
@ -0,0 +1,26 @@
|
||||
# GodotStack
|
||||
A stack class for Godot Engine
|
||||
|
||||
## Supported versions
|
||||
| Godot version | Supported | Branch |
|
||||
| - | - | - |
|
||||
| 4.x | yes | main |
|
||||
|
||||
## Compilation
|
||||
- Download GodotStack and place it to the Godot `modules` folder.
|
||||
- Rename `GodotStack-main` to `GodotStack`
|
||||
- Compile Godot like usual using one of [these guides](https://docs.godotengine.org/en/stable/development/compiling/index.html).
|
||||
|
||||
Example compilation `Windows` command: `scons p=windows tools=yes -j4`
|
||||
|
||||
## Methods
|
||||
```gdscript
|
||||
stack.getQueue() # get stack as an array
|
||||
stack.push(element: Variant) # push a new element to stack 1st position
|
||||
stack.pushBack(element: Variant) # push a new element to stack last position
|
||||
stack.first() # get first stack element
|
||||
stack.last() # get stack last element
|
||||
stack.size() # get stack size
|
||||
stack.isEmpty() # returns a boolean value indicates that stack is empty or not
|
||||
stack.drop() # removes all stack elements
|
||||
```
|
5
SCsub
Normal file
5
SCsub
Normal file
@ -0,0 +1,5 @@
|
||||
# SCsub
|
||||
|
||||
Import('env')
|
||||
|
||||
env.add_source_files(env.modules_sources, "*.cpp") # Add all cpp files to the build
|
7
config.py
Normal file
7
config.py
Normal file
@ -0,0 +1,7 @@
|
||||
# config.py
|
||||
|
||||
def can_build(env, platform):
|
||||
return True
|
||||
|
||||
def configure(env):
|
||||
pass
|
17
register_types.cpp
Normal file
17
register_types.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
/* register_types.cpp */
|
||||
|
||||
#include "register_types.h"
|
||||
#include "core/object/class_db.h"
|
||||
#include "stack.h"
|
||||
|
||||
void initialize_GodotStack_module(ModuleInitializationLevel p_level) {
|
||||
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
ClassDB::register_class<Stack>();
|
||||
}
|
||||
}
|
||||
|
||||
void uninitialize_GodotStack_module(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
return;
|
||||
}
|
||||
}
|
7
register_types.h
Normal file
7
register_types.h
Normal file
@ -0,0 +1,7 @@
|
||||
/* register_types.h */
|
||||
|
||||
#include "modules/register_module_types.h"
|
||||
|
||||
void initialize_GodotStack_module(ModuleInitializationLevel p_level);
|
||||
void uninitialize_GodotStack_module(ModuleInitializationLevel p_level);
|
||||
/* yes, the word in the middle must be the same as the module folder name */
|
50
stack.cpp
Normal file
50
stack.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
/* stack.cpp */
|
||||
|
||||
#include "stack.h"
|
||||
|
||||
Array Stack::getQueue() {
|
||||
return queue;
|
||||
}
|
||||
|
||||
void Stack::push(Variant element) {
|
||||
queue.push_front(element);
|
||||
}
|
||||
|
||||
void Stack::pushBack(Variant element) {
|
||||
queue.push_back(element);
|
||||
}
|
||||
|
||||
Variant Stack::first() {
|
||||
return queue.pop_front();
|
||||
}
|
||||
|
||||
Variant Stack::last() {
|
||||
return queue.pop_back();
|
||||
}
|
||||
|
||||
int Stack::size() {
|
||||
return queue.size();
|
||||
}
|
||||
|
||||
bool Stack::isEmpty() {
|
||||
return queue.is_empty();
|
||||
}
|
||||
|
||||
void Stack::drop() {
|
||||
queue.clear();
|
||||
}
|
||||
|
||||
void Stack::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("getQueue"), &Stack::getQueue);
|
||||
ClassDB::bind_method(D_METHOD("push", "element"), &Stack::push);
|
||||
ClassDB::bind_method(D_METHOD("pushBack", "element"), &Stack::pushBack);
|
||||
ClassDB::bind_method(D_METHOD("first"), &Stack::first);
|
||||
ClassDB::bind_method(D_METHOD("last"), &Stack::last);
|
||||
ClassDB::bind_method(D_METHOD("size"), &Stack::size);
|
||||
ClassDB::bind_method(D_METHOD("isEmpty"), &Stack::isEmpty);
|
||||
ClassDB::bind_method(D_METHOD("drop"), &Stack::drop);
|
||||
};
|
||||
|
||||
Stack::Stack() {
|
||||
queue = Array();
|
||||
}
|
32
stack.h
Normal file
32
stack.h
Normal file
@ -0,0 +1,32 @@
|
||||
/* stack.h */
|
||||
|
||||
#ifndef STACK_H
|
||||
#define STACK_H
|
||||
|
||||
#include "core/object/ref_counted.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/variant/variant.h"
|
||||
#include "core/variant/array.h"
|
||||
#include "core/variant/dictionary.h"
|
||||
|
||||
class Stack : public RefCounted {
|
||||
GDCLASS(Stack, RefCounted);
|
||||
|
||||
Array queue;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
Array getQueue();
|
||||
void push(Variant element);
|
||||
void pushBack(Variant element);
|
||||
Variant first();
|
||||
Variant last();
|
||||
int size();
|
||||
bool isEmpty();
|
||||
void drop();
|
||||
Stack();
|
||||
};
|
||||
|
||||
#endif // STACK_H
|
Loading…
x
Reference in New Issue
Block a user