Initial commit

This commit is contained in:
Mestima 2023-10-10 12:56:02 +03:00
commit c121073f62
10 changed files with 169 additions and 0 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/__pycache__
*.obj

21
LICENSE Normal file
View 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
View 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
View 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
View File

@ -0,0 +1,7 @@
# config.py
def can_build(env, platform):
return True
def configure(env):
pass

17
register_types.cpp Normal file
View 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
View 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
View 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
View 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