-
Notifications
You must be signed in to change notification settings - Fork 1
/
GrammarLoader.gd
42 lines (28 loc) · 969 Bytes
/
GrammarLoader.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@tool
extends ResourceFormatLoader
class_name GrammarLoader
var loaded = {}
func _exists(path: String) -> bool:
return true
func _get_recognized_extensions() -> PackedStringArray:
return ["grammar"]
func _get_resource_script_class(path: String) -> String:
return "Grammar"
func _get_resource_type(path: String) -> String:
return "Resource"
func _handles_type(type: StringName) -> bool:
return type == "Resource"
func _load(path: String, original_path: String, _use_sub_threads: bool, cache_mode: int) -> Variant:
if loaded.has(path) and cache_mode != CacheMode.CACHE_MODE_REPLACE:
return self.loaded[path]
else:
var file = FileAccess.open(path, FileAccess.READ)
if file == null:
return Error.ERR_FILE_CANT_OPEN
var len = file.get_length()
file.seek(0)
var packed = file.get_var()
var grammar_resource = Grammar.new()
grammar_resource.unpack(packed)
self.loaded[path] = grammar_resource
return grammar_resource