replace Referencer global with individual static instances
This commit is contained in:
@@ -123,7 +123,7 @@ func _update_visibility() -> void:
|
||||
|
||||
|
||||
func _unproject(pos: Vector3) -> Vector2:
|
||||
return Referencer.main_camera.unproject_position(pos)
|
||||
return MainCamera.instance.unproject_position(pos)
|
||||
|
||||
|
||||
func _update_controls_label() -> void:
|
||||
@@ -207,8 +207,8 @@ func _append_event(key: String, frame: int, args: Array[Variant]) -> void:
|
||||
|
||||
func _draw_vector(from: Vector3, to: Vector3, color: Color) -> void:
|
||||
if (
|
||||
not Referencer.main_camera.is_position_in_frustum(from)
|
||||
and not Referencer.main_camera.is_position_in_frustum(to)
|
||||
not MainCamera.instance.is_position_in_frustum(from)
|
||||
and not MainCamera.instance.is_position_in_frustum(to)
|
||||
):
|
||||
return
|
||||
|
||||
@@ -222,8 +222,8 @@ func _draw_vector(from: Vector3, to: Vector3, color: Color) -> void:
|
||||
|
||||
func _draw_line(from: Vector3, to: Vector3, color: Color) -> void:
|
||||
if (
|
||||
not Referencer.main_camera.is_position_in_frustum(from)
|
||||
and not Referencer.main_camera.is_position_in_frustum(to)
|
||||
not MainCamera.instance.is_position_in_frustum(from)
|
||||
and not MainCamera.instance.is_position_in_frustum(to)
|
||||
):
|
||||
return
|
||||
|
||||
@@ -247,7 +247,7 @@ func _draw_triangle(
|
||||
|
||||
|
||||
func _draw_marker(pos: Vector3, radius: float, color: Color) -> void:
|
||||
if not Referencer.main_camera.is_position_in_frustum(pos):
|
||||
if not MainCamera.instance.is_position_in_frustum(pos):
|
||||
return
|
||||
|
||||
var x_start := _unproject(pos + (Vector3.LEFT * radius))
|
||||
@@ -264,7 +264,7 @@ func _draw_marker(pos: Vector3, radius: float, color: Color) -> void:
|
||||
|
||||
|
||||
func _draw_circle(pos: Vector3, color: Color) -> void:
|
||||
if not Referencer.main_camera.is_position_in_frustum(pos):
|
||||
if not MainCamera.instance.is_position_in_frustum(pos):
|
||||
return
|
||||
|
||||
var point := _unproject(pos)
|
||||
@@ -306,7 +306,7 @@ func _on_control_draw() -> void:
|
||||
|
||||
_set_label_texts()
|
||||
|
||||
if !Referencer.main_camera or mode != Mode.FULL:
|
||||
if !MainCamera.instance or mode != Mode.FULL:
|
||||
return
|
||||
|
||||
for v: Dictionary in _vectors_to_draw.values():
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
class_name MainCamera
|
||||
extends Camera3D
|
||||
|
||||
static var instance: MainCamera
|
||||
|
||||
@export_group("References")
|
||||
@export var _listener: AudioListener3D
|
||||
|
||||
@@ -30,9 +32,9 @@ var _hit_shake_time: float = 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Referencer.main_camera = self
|
||||
instance = self
|
||||
_listener.make_current()
|
||||
for player in Referencer.players:
|
||||
for player in Player.instances:
|
||||
_connect_player_signals(player)
|
||||
|
||||
|
||||
@@ -49,9 +51,9 @@ func _physics_process(delta: float) -> void:
|
||||
|
||||
func _process_following(delta: float) -> void:
|
||||
var follow_position: Vector3 = Vector3.ZERO
|
||||
for player in Referencer.players:
|
||||
for player in Player.instances:
|
||||
follow_position += _follow(player, delta)
|
||||
follow_position /= Referencer.players_count
|
||||
follow_position /= Player.instances.size()
|
||||
follow_position += Vector3.UP * _height_offset
|
||||
|
||||
global_position = follow_position + transform.basis.z * _distance
|
||||
@@ -75,7 +77,7 @@ func _follow(player: Player, delta: float) -> Vector3:
|
||||
player_offset.floor_height = player_position.y
|
||||
player_position.y = player_offset.floor_height + Projectile.HEIGHT
|
||||
|
||||
if Referencer.players_count > 1:
|
||||
if not Player.is_single_player():
|
||||
player_offset.aim_offset = Vector3.ZERO
|
||||
elif player.input_mode_is(Inputer.Mode.KB_MOUSE):
|
||||
player_offset.aim_offset = player.aiming.aim_offset
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
class_name Player
|
||||
extends CharacterBody3D
|
||||
|
||||
static var instances: Array[Player]
|
||||
|
||||
@export var cursor_color: Color
|
||||
|
||||
@export var _input_mode: Inputer.Mode = Inputer.Mode.KB_MOUSE
|
||||
@@ -20,10 +22,13 @@ var _respawn_point: Vector3
|
||||
var _debug_collision_shapes := DebugCollisionShapes.new()
|
||||
|
||||
|
||||
static func is_single_player() -> bool:
|
||||
return instances.size() == 1
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_respawn_point = global_position
|
||||
Referencer.players.append(self)
|
||||
Referencer.players_count += 1
|
||||
instances.append(self)
|
||||
_debug_collision_shapes.init(get_children(), self, _collision_debug_material)
|
||||
|
||||
|
||||
@@ -51,7 +56,7 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
if (
|
||||
not input_mode_is(mode)
|
||||
or (
|
||||
Referencer.players_count > 1
|
||||
not Player.is_single_player()
|
||||
and _input_mode == Inputer.Mode.CONTROLLER
|
||||
and event.device != _device_index
|
||||
)
|
||||
@@ -67,8 +72,8 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
|
||||
func input_mode_is(mode: Inputer.Mode) -> bool:
|
||||
return (
|
||||
(Referencer.players_count == 1 and mode == Inputer.mode)
|
||||
or (Referencer.players_count > 1 and _input_mode == mode)
|
||||
(Player.is_single_player() and mode == Inputer.mode)
|
||||
or (not Player.is_single_player() and _input_mode == mode)
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ var _aim_down: float
|
||||
|
||||
|
||||
func handle_input(event: InputEvent, mode: Inputer.Mode) -> void:
|
||||
if Referencer.players_count == 1:
|
||||
if Player.is_single_player():
|
||||
return
|
||||
|
||||
if mode == Inputer.Mode.CONTROLLER and event is InputEventJoypadMotion:
|
||||
@@ -31,7 +31,7 @@ func handle_input(event: InputEvent, mode: Inputer.Mode) -> void:
|
||||
|
||||
|
||||
func controller_aiming(move_input: Vector2) -> void:
|
||||
if Referencer.players_count == 1:
|
||||
if Player.is_single_player():
|
||||
aim_input = Input.get_vector(
|
||||
"aim_left",
|
||||
"aim_right",
|
||||
@@ -52,7 +52,7 @@ func controller_aiming(move_input: Vector2) -> void:
|
||||
var aim_direction := Vector3(input.x, 0, input.y * _vertical_aim_aspect)
|
||||
|
||||
aim_offset = (
|
||||
aim_direction.rotated(Vector3.UP, Referencer.main_camera.rotation.y)
|
||||
aim_direction.rotated(Vector3.UP, MainCamera.instance.rotation.y)
|
||||
* _controller_aim_offset
|
||||
)
|
||||
|
||||
@@ -72,7 +72,7 @@ func mouse_aiming(
|
||||
|
||||
|
||||
func _mouse_project(mouse_pos: Vector2, height: float) -> Vector3:
|
||||
var camera := Referencer.main_camera
|
||||
var camera := MainCamera.instance
|
||||
|
||||
var from := camera.project_ray_origin(mouse_pos)
|
||||
var direction := camera.project_ray_normal(mouse_pos)
|
||||
|
||||
@@ -19,7 +19,7 @@ var _move_down: float
|
||||
|
||||
|
||||
func handle_input(event: InputEvent, mode: Inputer.Mode) -> void:
|
||||
if Referencer.players_count == 1:
|
||||
if Player.is_single_player():
|
||||
return
|
||||
|
||||
if mode == Inputer.Mode.KB_MOUSE and event is InputEventKey:
|
||||
@@ -63,7 +63,7 @@ func movement(
|
||||
|
||||
|
||||
func _lateral_movement(velocity: Vector3, delta: float, can_move: bool) -> Vector3:
|
||||
if Referencer.players_count == 1:
|
||||
if Player.is_single_player():
|
||||
move_input = Input.get_vector(
|
||||
"move_left",
|
||||
"move_right",
|
||||
@@ -83,7 +83,7 @@ func _lateral_movement(velocity: Vector3, delta: float, can_move: bool) -> Vecto
|
||||
|
||||
if move_input.length() > 0 and can_move:
|
||||
_move_direction = Vector3(move_input.x, 0, move_input.y).normalized().rotated(
|
||||
Vector3.UP, Referencer.main_camera.rotation.y
|
||||
Vector3.UP, MainCamera.instance.rotation.y
|
||||
)
|
||||
var new_velocity := _move_direction * move_speed
|
||||
new_velocity.y = velocity.y
|
||||
|
||||
@@ -16,7 +16,7 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if not Referencer.players or not Referencer.main_camera:
|
||||
if not Player.instances or not MainCamera.instance:
|
||||
var mouse_pos := get_viewport().get_mouse_position()
|
||||
_single_cursor.position = mouse_pos - _single_cursor.size / 2
|
||||
_single_cursor.visible = true
|
||||
@@ -29,7 +29,7 @@ func _physics_process(delta: float) -> void:
|
||||
|
||||
|
||||
func _handle_cursors(delta: float) -> void:
|
||||
for player_index in range(Referencer.players_count):
|
||||
for player_index in range(Player.instances.size()):
|
||||
_handle_cursor(player_index, delta)
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ func _init_player_cursor(id: int) -> void:
|
||||
|
||||
|
||||
func _handle_cursor(player_index: int, delta: float) -> void:
|
||||
var player := Referencer.players[player_index]
|
||||
var player := Player.instances[player_index]
|
||||
var id := player.get_instance_id()
|
||||
|
||||
if not _cursors.has(id):
|
||||
@@ -52,7 +52,7 @@ func _handle_cursor(player_index: int, delta: float) -> void:
|
||||
return
|
||||
|
||||
var cursor_pos_world := player.attack.global_position + player.aiming.aim_offset
|
||||
var cursor_pos_screen := Referencer.main_camera.unproject_position(cursor_pos_world)
|
||||
var cursor_pos_screen := MainCamera.instance.unproject_position(cursor_pos_world)
|
||||
|
||||
var clamp_corner_min := Vector2.ZERO
|
||||
var clamp_corner_max := get_viewport().get_visible_rect().size
|
||||
@@ -74,13 +74,13 @@ func _handle_cursor(player_index: int, delta: float) -> void:
|
||||
)
|
||||
|
||||
var aim_offset_normalized := player.aiming.aim_offset.normalized()
|
||||
var bat_rotation_point_screen := Referencer.main_camera.unproject_position(
|
||||
var bat_rotation_point_screen := MainCamera.instance.unproject_position(
|
||||
(
|
||||
cursor_pos_world
|
||||
+ aim_offset_normalized.rotated(Vector3.UP, cursor.side as float)
|
||||
)
|
||||
)
|
||||
var arrow_rotation_point_screen := Referencer.main_camera.unproject_position(
|
||||
var arrow_rotation_point_screen := MainCamera.instance.unproject_position(
|
||||
cursor_pos_world + aim_offset_normalized
|
||||
)
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
extends Node
|
||||
|
||||
var main_camera: MainCamera
|
||||
var players: Array[Player]
|
||||
var players_count: int = 0
|
||||
@@ -1 +0,0 @@
|
||||
uid://xe3jh3bo5skb
|
||||
Reference in New Issue
Block a user