diff --git a/project.godot b/project.godot index cb86478..4862c51 100644 --- a/project.godot +++ b/project.godot @@ -18,10 +18,11 @@ config/icon="res://icon.svg" [autoload] +AsyncResourceHandler="*res://src/async_resource_handler.ts" Console="*res://addons/dev_console/console.tscn" DebugDraw="*res://src/debug_draw.ts" MessageBus="*res://src/message_bus.ts" -AsyncResourceLoader="*res://src/async_resource_loader.ts" +SaveSerializer="*res://src/save_serializer.ts" [editor] diff --git a/src/async_resource_handler.ts b/src/async_resource_handler.ts index 569b6c2..64c4142 100644 --- a/src/async_resource_handler.ts +++ b/src/async_resource_handler.ts @@ -36,7 +36,7 @@ export default class AsyncResourceHandler extends Node { return this._instance.load(path, hint_string, use_sub_threads, cache_mode) } - load(path: string, hint_string: string = '', use_sub_threads?: boolean, cache_mode?: ResourceLoader.CacheMode): Promise { + load(path: string, hint_string: string = '', use_sub_threads: boolean = false, cache_mode: ResourceLoader.CacheMode = ResourceLoader.CacheMode.CACHE_MODE_REUSE): Promise { return new Promise(async (resolve, reject) => { const err = ResourceLoader.load_threaded_request(path, hint_string, use_sub_threads, cache_mode) @@ -51,7 +51,6 @@ export default class AsyncResourceHandler extends Node { await this.get_tree().process_frame.as_promise() status = get_status() } - if (status === ResourceLoader.ThreadLoadStatus.THREAD_LOAD_LOADED) { return resolve(ResourceLoader.load_threaded_get(path) as T) } else { diff --git a/src/async_resource_loader.ts b/src/async_resource_loader.ts deleted file mode 100644 index 329d7db..0000000 --- a/src/async_resource_loader.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { GArray, GError, Node, Resource, ResourceLoader, ResourceSaver } from 'godot' -import { GodotError } from './godot_error' - -export class ResourceLoadError extends Error { } - -export default class AsyncResourceHandler extends Node { - private static _instance: AsyncResourceHandler - static readonly SaveFlags = ResourceSaver.SaverFlags - static readonly CacheMode = ResourceLoader.CacheMode - - static get instance() { - return this._instance - } - - _ready(): void { - AsyncResourceHandler._instance = this - } - - save(path: string, data: T, flags: ResourceSaver.SaverFlags): Promise { - return new Promise((resolve, reject) => { - const err = ResourceSaver.save(data, path, flags) - - if (err === GError.OK) { - resolve() - } else { - reject(err) - } - }) - } - - load(path: string, hint_string: string = '', use_sub_threads?: boolean, cache_mode?: ResourceLoader.CacheMode): Promise { - return new Promise(async (resolve, reject) => { - const err = ResourceLoader.load_threaded_request(path, hint_string, use_sub_threads, cache_mode) - - if (err != GError.OK) { - return reject(new GodotError(err)) - } - - const get_status = () => ResourceLoader.load_threaded_get_status(path) - - let status = get_status() - while (status === ResourceLoader.ThreadLoadStatus.THREAD_LOAD_IN_PROGRESS) { - await this.get_tree().process_frame.as_promise() - status = get_status() - } - - if (status === ResourceLoader.ThreadLoadStatus.THREAD_LOAD_LOADED) { - return resolve(ResourceLoader.load_threaded_get(path) as T) - } else { - return reject(new ResourceLoadError()) - } - }) - } - - get_progress(path: string): number { - const arr = new GArray() - ResourceLoader.load_threaded_get_status(path, arr) - return arr.get_indexed(0) - } -} - diff --git a/src/equipped_weapon.ts b/src/equipped_weapon.ts index 4c459b9..380a5aa 100644 --- a/src/equipped_weapon.ts +++ b/src/equipped_weapon.ts @@ -1,4 +1,4 @@ -import { Color, GArray, Node, Node3D, PackedScene, PhysicsBody3D, PhysicsRayQueryParameters3D, Signal1, Timer, Vector3 } from 'godot' +import { Color, GArray, Node, Node3D, PackedScene, PackedStringArray, PhysicsBody3D, PhysicsRayQueryParameters3D, Signal1, Timer, Vector3 } from 'godot' import { export_file, signal } from 'godot.annotations' import { export_node, onready } from './annotations' import Weapon from './weapon' @@ -36,7 +36,7 @@ export default class EquippedWeapon extends Node3D { _ready(): void { if (this.starting_weapon != null) { - AsyncResourceHandler.instance.load(this.starting_weapon, 'Weapon').then(weapon => this.equip(weapon)) + AsyncResourceHandler.load(this.starting_weapon, 'Weapon').then(weapon => this.equip(weapon)) } } diff --git a/src/player_input.ts b/src/player_input.ts index 793c070..5b95a63 100644 --- a/src/player_input.ts +++ b/src/player_input.ts @@ -223,9 +223,6 @@ export default class PlayerInput extends Node3D { this._await_camera_callable = Callable.create(this, this._await_camera) MessageBus.instance.active_camera_changed.connect(this._await_camera_callable) - this._look_direction._camera = this._camera - this._look_direction._world_3d = this.get_world_3d() - this._min_range_sqr = this._sqr(this.min_range) this._max_range_sqr = this._sqr(this.max_range)