Skip to content

Commit 2aab80f

Browse files
committed
add sqlite resourec
1 parent 0631550 commit 2aab80f

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

src/resource_loader_sqlite.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "resource_loader_sqlite.h"
2+
#include "resource_sqlite.h"
3+
4+
Variant ResourceFormatLoaderSqlite::_load(const String &p_path, const String &original_path, bool use_sub_threads, int32_t cache_mode) const {
5+
Ref<SqliteResource> sqlite_model = memnew(SqliteResource);
6+
sqlite_model->set_file(p_path);
7+
return sqlite_model;
8+
}
9+
PackedStringArray ResourceFormatLoaderSqlite::_get_recognized_extensions() const {
10+
PackedStringArray array;
11+
array.push_back("bin");
12+
return array;
13+
}
14+
bool ResourceFormatLoaderSqlite::_handles_type(const StringName &type) const {
15+
return ClassDB::is_parent_class(type, "SqliteResource");
16+
}
17+
String ResourceFormatLoaderSqlite::_get_resource_type(const String &p_path) const {
18+
String el = p_path.get_extension().to_lower();
19+
if (el == "sqlite") {
20+
return "SqliteResource";
21+
}
22+
return "";
23+
}

src/resource_loader_sqlite.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef SQLITE_LOADER_SQLITE_H
2+
#define SQLITE_LOADER_SQLITE_H
3+
4+
#include <godot_cpp/classes/resource_format_loader.hpp>
5+
#include <godot_cpp/classes/resource_loader.hpp>
6+
7+
using namespace godot;
8+
9+
class ResourceFormatLoaderSqlite : public ResourceFormatLoader {
10+
GDCLASS(ResourceFormatLoaderSqlite, ResourceFormatLoader);
11+
12+
protected:
13+
static void _bind_methods() {}
14+
15+
public:
16+
virtual Variant _load(const String &path, const String &original_path, bool use_sub_threads, int32_t cache_mode) const override;
17+
virtual PackedStringArray _get_recognized_extensions() const override;
18+
virtual bool _handles_type(const StringName &type) const override;
19+
virtual String _get_resource_type(const String &p_path) const override;
20+
};
21+
#endif // SQLITE_LOADER_SQLITE_H

src/resource_sqlite.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "resource_sqlite.h"
2+
#include <iostream>
3+
4+
#include <godot_cpp/classes/file_access.hpp>
5+
6+
PackedByteArray SqliteResource::get_content() {
7+
PackedByteArray content;
8+
String p_path = get_file();
9+
content = FileAccess::get_file_as_bytes(p_path);
10+
return content;
11+
}

src/resource_sqlite.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef SQLITE_RESOURCE_H
2+
#define SQLITE_RESOURCE_H
3+
4+
#include <godot_cpp/classes/resource.hpp>
5+
6+
using namespace godot;
7+
8+
class SqliteResource : public Resource {
9+
GDCLASS(SqliteResource, Resource);
10+
11+
protected:
12+
static void _bind_methods() {}
13+
String file;
14+
15+
public:
16+
void set_file(const String &p_file) {
17+
file = p_file;
18+
emit_changed();
19+
}
20+
21+
String get_file() {
22+
return file;
23+
}
24+
25+
PackedByteArray get_content();
26+
SqliteResource() {}
27+
~SqliteResource() {}
28+
};
29+
#endif // SQLITE_RESOURCE_H

0 commit comments

Comments
 (0)