From c121073f62d20769da8d39cdd2686090e1b0c223 Mon Sep 17 00:00:00 2001 From: Mestima Date: Tue, 10 Oct 2023 12:56:02 +0300 Subject: [PATCH] Initial commit --- .gitattributes | 2 ++ .gitignore | 2 ++ LICENSE | 21 +++++++++++++++++++ README.md | 26 ++++++++++++++++++++++++ SCsub | 5 +++++ config.py | 7 +++++++ register_types.cpp | 17 ++++++++++++++++ register_types.h | 7 +++++++ stack.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++ stack.h | 32 +++++++++++++++++++++++++++++ 10 files changed, 169 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 SCsub create mode 100644 config.py create mode 100644 register_types.cpp create mode 100644 register_types.h create mode 100644 stack.cpp create mode 100644 stack.h diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..36fb54a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/__pycache__ +*.obj \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..44b8424 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..bf66daa --- /dev/null +++ b/README.md @@ -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 +``` diff --git a/SCsub b/SCsub new file mode 100644 index 0000000..3c12e73 --- /dev/null +++ b/SCsub @@ -0,0 +1,5 @@ +# SCsub + +Import('env') + +env.add_source_files(env.modules_sources, "*.cpp") # Add all cpp files to the build \ No newline at end of file diff --git a/config.py b/config.py new file mode 100644 index 0000000..c1c0259 --- /dev/null +++ b/config.py @@ -0,0 +1,7 @@ +# config.py + +def can_build(env, platform): + return True + +def configure(env): + pass \ No newline at end of file diff --git a/register_types.cpp b/register_types.cpp new file mode 100644 index 0000000..b936484 --- /dev/null +++ b/register_types.cpp @@ -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(); + } +} + +void uninitialize_GodotStack_module(ModuleInitializationLevel p_level) { + if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { + return; + } +} \ No newline at end of file diff --git a/register_types.h b/register_types.h new file mode 100644 index 0000000..cacf881 --- /dev/null +++ b/register_types.h @@ -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 */ \ No newline at end of file diff --git a/stack.cpp b/stack.cpp new file mode 100644 index 0000000..1a07732 --- /dev/null +++ b/stack.cpp @@ -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(); +} \ No newline at end of file diff --git a/stack.h b/stack.h new file mode 100644 index 0000000..be0c7cf --- /dev/null +++ b/stack.h @@ -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 \ No newline at end of file