mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-02-06 16:16:06 +01:00
Created a new UserManagerStatic class.
This commit is contained in:
parent
0854b8999d
commit
be68b69b65
@ -8,7 +8,10 @@ sources = [
|
||||
"register_types.cpp",
|
||||
|
||||
"users/user.cpp",
|
||||
|
||||
"managers/user_manager.cpp",
|
||||
"managers/user_manager_static.cpp",
|
||||
|
||||
"singleton/user_db.cpp",
|
||||
]
|
||||
|
||||
|
@ -12,6 +12,7 @@ def get_doc_classes():
|
||||
return [
|
||||
"User",
|
||||
"UserManager",
|
||||
"UserManagerStatic",
|
||||
"UserDB",
|
||||
]
|
||||
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
virtual bool _is_username_taken(const String &user_name);
|
||||
virtual bool _is_email_taken(const String &email);
|
||||
|
||||
Vector<Ref<User>> get_all();
|
||||
virtual Vector<Ref<User>> get_all();
|
||||
|
||||
UserManager();
|
||||
~UserManager();
|
||||
|
87
modules/users/managers/user_manager_static.cpp
Normal file
87
modules/users/managers/user_manager_static.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
#include "user_manager_static.h"
|
||||
|
||||
#include "../users/user.h"
|
||||
|
||||
Ref<User> UserManagerStatic::_get_user(const int id) {
|
||||
ERR_FAIL_INDEX_V(id, _users.size(), Ref<User>());
|
||||
|
||||
return _users[id];
|
||||
}
|
||||
Ref<User> UserManagerStatic::_get_user_name(const String &user_name) {
|
||||
for (int i = 0; i < _users.size(); ++i) {
|
||||
Ref<User> u = _users[i];
|
||||
|
||||
if (u.is_valid()) {
|
||||
if (u->get_name_user_input() == user_name) {
|
||||
return u;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Ref<User>();
|
||||
}
|
||||
void UserManagerStatic::_save_user(Ref<User> user) {
|
||||
//With this class Users are serialized via editor properties, ignore
|
||||
}
|
||||
Ref<User> UserManagerStatic::_create_user() {
|
||||
//With this class Users are managed via the editor editor
|
||||
return Ref<User>();
|
||||
}
|
||||
bool UserManagerStatic::_is_username_taken(const String &user_name) {
|
||||
for (int i = 0; i < _users.size(); ++i) {
|
||||
Ref<User> u = _users[i];
|
||||
|
||||
if (u.is_valid()) {
|
||||
if (u->get_name_user_input() == user_name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool UserManagerStatic::_is_email_taken(const String &email) {
|
||||
for (int i = 0; i < _users.size(); ++i) {
|
||||
Ref<User> u = _users[i];
|
||||
|
||||
if (u.is_valid()) {
|
||||
if (u->get_email_user_input() == email) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector<Ref<User>> UserManagerStatic::get_all() {
|
||||
return _users;
|
||||
}
|
||||
|
||||
Vector<Variant> UserManagerStatic::get_users() {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _users.size(); i++) {
|
||||
r.push_back(_users[i].get_ref_ptr());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void UserManagerStatic::set_users(const Vector<Variant> &users) {
|
||||
_users.clear();
|
||||
for (int i = 0; i < users.size(); i++) {
|
||||
Ref<User> u = Ref<User>(users.get(i));
|
||||
|
||||
_users.push_back(u);
|
||||
}
|
||||
}
|
||||
|
||||
UserManagerStatic::UserManagerStatic() {
|
||||
}
|
||||
|
||||
UserManagerStatic::~UserManagerStatic() {
|
||||
}
|
||||
|
||||
void UserManagerStatic::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_users"), &UserManagerStatic::get_users);
|
||||
ClassDB::bind_method(D_METHOD("set_users", "users"), &UserManagerStatic::set_users);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "users", PROPERTY_HINT_NONE, "17/17:User", PROPERTY_USAGE_DEFAULT, "User"), "set_users", "get_users");
|
||||
}
|
40
modules/users/managers/user_manager_static.h
Normal file
40
modules/users/managers/user_manager_static.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef USER_MANAGER_STATIC_H
|
||||
#define USER_MANAGER_STATIC_H
|
||||
|
||||
#include "core/os/rw_lock.h"
|
||||
#include "core/reference.h"
|
||||
#include "core/ustring.h"
|
||||
#include "core/vector.h"
|
||||
|
||||
#include "user_manager.h"
|
||||
|
||||
class User;
|
||||
|
||||
class UserManagerStatic : public UserManager {
|
||||
GDCLASS(UserManagerStatic, UserManager);
|
||||
|
||||
public:
|
||||
Ref<User> _get_user(const int id);
|
||||
Ref<User> _get_user_name(const String &user);
|
||||
void _save_user(Ref<User> user);
|
||||
|
||||
Ref<User> _create_user();
|
||||
|
||||
bool _is_username_taken(const String &user_name);
|
||||
bool _is_email_taken(const String &email);
|
||||
|
||||
Vector<Ref<User>> get_all();
|
||||
|
||||
Vector<Variant> get_users();
|
||||
void set_users(const Vector<Variant> &users);
|
||||
|
||||
UserManagerStatic();
|
||||
~UserManagerStatic();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
Vector<Ref<User>> _users;
|
||||
};
|
||||
|
||||
#endif
|
@ -27,13 +27,18 @@ SOFTWARE.
|
||||
#include "users/user.h"
|
||||
|
||||
#include "managers/user_manager.h"
|
||||
#include "managers/user_manager_static.h"
|
||||
|
||||
#include "singleton/user_db.h"
|
||||
|
||||
UserDB *_user_db = nullptr;
|
||||
|
||||
void register_users_types() {
|
||||
ClassDB::register_class<User>();
|
||||
|
||||
ClassDB::register_class<UserManager>();
|
||||
ClassDB::register_class<UserManagerStatic>();
|
||||
|
||||
ClassDB::register_class<UserDB>();
|
||||
|
||||
_user_db = memnew(UserDB);
|
||||
|
Loading…
Reference in New Issue
Block a user