Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee0cf0659d | ||
|
|
d1fade919c | ||
|
|
b2eb85fdf1 | ||
|
|
d8138fbe69 | ||
|
|
e54dd191f1 | ||
|
|
aef117bcf9 | ||
|
|
582b2c43cb |
@@ -12,3 +12,10 @@
|
||||
- `test1/test1` - Super User
|
||||
- `test3/test3` - User
|
||||
|
||||
## Controls
|
||||
- Move: WASD
|
||||
- Jump: Space
|
||||
- Interact (enter/exit car): E
|
||||
- Flashlight: F
|
||||
- Phone: Tab
|
||||
- Pause menu: Esc
|
||||
|
||||
@@ -25,6 +25,7 @@ MenuMusic="*res://scenes/UI/menu_music.tscn"
|
||||
MenuSfx="*res://scenes/UI/menu_sfx.tscn"
|
||||
AuthState="*res://scenes/UI/auth_state.gd"
|
||||
CharacterService="*res://scenes/UI/character_service.gd"
|
||||
SelectedCharacter="*res://scenes/UI/selected_character.gd"
|
||||
|
||||
[dotnet]
|
||||
|
||||
@@ -74,3 +75,8 @@ player_phone={
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194306,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
interact={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ extends Node3D
|
||||
@export var camera_path: NodePath
|
||||
@export var look_origin_path: NodePath = NodePath("Body/HeadPivot")
|
||||
@export var look_reference_path: NodePath = NodePath("Body")
|
||||
@export var look_target_path: NodePath = NodePath("")
|
||||
@export var lock_vertical: bool = true
|
||||
@export var vertical_unlock_height: float = 0.6
|
||||
@export var vertical_lock_smooth_speed: float = 6.0
|
||||
@@ -29,6 +30,7 @@ var _head_base_rot: Vector3
|
||||
var _vertical_lock_factor: float = 1.0
|
||||
var _vertical_hold_timer: float = 0.0
|
||||
var _look_reference: Node3D
|
||||
var _look_target: Node3D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -41,6 +43,7 @@ func _ready() -> void:
|
||||
_camera = _resolve_camera()
|
||||
_look_origin = get_node_or_null(look_origin_path) as Node3D
|
||||
_look_reference = get_node_or_null(look_reference_path) as Node3D
|
||||
_look_target = get_node_or_null(look_target_path) as Node3D
|
||||
_head = get_node_or_null(head_path) as Node3D
|
||||
if _head:
|
||||
_head_base_rot = _head.rotation
|
||||
@@ -55,14 +58,20 @@ func _process(_delta: float) -> void:
|
||||
|
||||
|
||||
func _update_pupils() -> void:
|
||||
if _camera == null or not _camera.is_inside_tree():
|
||||
_camera = _resolve_camera()
|
||||
if _camera == null:
|
||||
if _look_target == null and look_target_path != NodePath(""):
|
||||
_look_target = get_node_or_null(look_target_path) as Node3D
|
||||
if _look_target == null:
|
||||
var viewport_cam := get_viewport().get_camera_3d()
|
||||
if viewport_cam != null and viewport_cam != _camera:
|
||||
_camera = viewport_cam
|
||||
elif _camera == null or not _camera.is_inside_tree():
|
||||
_camera = _resolve_camera()
|
||||
if _look_target == null and _camera == null:
|
||||
return
|
||||
var origin := _look_origin
|
||||
if origin == null:
|
||||
origin = self
|
||||
var target := _camera.global_position
|
||||
var target := _look_target.global_position if _look_target != null else _camera.global_position
|
||||
var dir_world := target - origin.global_position
|
||||
if dir_world.length_squared() <= 0.0001:
|
||||
return
|
||||
|
||||
@@ -57,7 +57,12 @@ height = 1.1
|
||||
[node name="RepoBot" type="Node3D"]
|
||||
script = ExtResource("1_repo_bot")
|
||||
|
||||
[node name="Body" type="StaticBody3D" parent="."]
|
||||
[node name="Body" type="RigidBody3D" parent="."]
|
||||
mass = 1.5
|
||||
axis_lock_angular_x = true
|
||||
axis_lock_angular_z = true
|
||||
angular_damp = 8.0
|
||||
linear_damp = 0.5
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Body"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.55, 0)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
[ext_resource type="Script" uid="uid://b7fopt7sx74g8" path="res://scenes/Levels/menu.gd" id="3_tc7dm"]
|
||||
[ext_resource type="PackedScene" path="res://scenes/Characters/repo_bot.tscn" id="4_repo"]
|
||||
[ext_resource type="PackedScene" uid="uid://bnqaqbgynoyys" path="res://assets/models/TestCharAnimated.glb" id="5_fi66n"]
|
||||
[ext_resource type="PackedScene" path="res://scenes/Vehicles/car.tscn" id="5_car"]
|
||||
|
||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_2q6dc"]
|
||||
bounce = 0.5
|
||||
@@ -43,6 +44,7 @@ script = ExtResource("1_a4mo8")
|
||||
|
||||
[node name="RepoBot" parent="." instance=ExtResource("4_repo")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.9426608, 0, -4.4451966)
|
||||
look_target_path = NodePath("../Player")
|
||||
|
||||
[node name="Thing" type="RigidBody3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -3.7986288)
|
||||
@@ -186,8 +188,8 @@ bones/62/rotation = Quaternion(0.56540585, 0.011310213, -0.008501466, 0.8246915)
|
||||
bones/63/position = Vector3(7.93632e-09, 0.1572156, -2.6982683e-10)
|
||||
bones/63/rotation = Quaternion(0.28907102, 0.031904068, 0.014082117, 0.9566723)
|
||||
bones/64/position = Vector3(7.567915e-10, 0.099999994, -3.2595668e-09)
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Player"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||
shape = SubResource("SphereShape3D_mx8sn")
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="Player"]
|
||||
@@ -197,6 +199,8 @@ fov = 49.0
|
||||
|
||||
[node name="SpotLight3D" type="SpotLight3D" parent="Player"]
|
||||
|
||||
[node name="Car" parent="." instance=ExtResource("5_car")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -6, 0, -3)
|
||||
[node name="Ground" type="StaticBody3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0)
|
||||
|
||||
@@ -204,6 +208,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0)
|
||||
shape = SubResource("BoxShape3D_2q6dc")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Ground"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00053596497, 0.0075991154, -0.0019865036)
|
||||
mesh = SubResource("BoxMesh_w7c3h")
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
extends Node3D
|
||||
|
||||
@export var tile_size := 4.0
|
||||
@export var block_height := 1.0
|
||||
|
||||
@onready var _block: MeshInstance3D = $TerrainBlock
|
||||
@onready var _camera: Camera3D = $Camera3D
|
||||
|
||||
func _ready() -> void:
|
||||
var coord := SelectedCharacter.get_coord()
|
||||
var block_pos := Vector3(coord.x * tile_size, block_height * 0.5, coord.y * tile_size)
|
||||
_block.position = block_pos
|
||||
_block.scale = Vector3(tile_size, block_height, tile_size)
|
||||
if _camera:
|
||||
_camera.look_at(block_pos, Vector3.UP)
|
||||
@@ -0,0 +1 @@
|
||||
uid://1fico5npv6dy
|
||||
@@ -0,0 +1,23 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://b7p7k1i4t0m2l"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/Levels/location_level.gd" id="1_6y4q1"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_yu2x4"]
|
||||
albedo_color = Color(0.2, 0.6, 0.2, 1)
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_t2a5k"]
|
||||
material = SubResource("StandardMaterial3D_yu2x4")
|
||||
|
||||
[node name="LocationLevel" type="Node3D"]
|
||||
script = ExtResource("1_6y4q1")
|
||||
|
||||
[node name="TerrainBlock" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("BoxMesh_t2a5k")
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.819152, 0.573576, 0, -0.573576, 0.819152, 0, 6, 0)
|
||||
shadow_enabled = true
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.92388, 0.382683, 0, -0.382683, 0.92388, 0, 6, 10)
|
||||
current = true
|
||||
@@ -17,10 +17,12 @@ func _input(event):
|
||||
func pause_game():
|
||||
get_tree().paused = true
|
||||
visible = true
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
|
||||
func resume_game():
|
||||
get_tree().paused = false
|
||||
visible = false
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
func _on_quit_button_pressed():
|
||||
get_tree().quit()
|
||||
@@ -30,6 +32,7 @@ func _on_continue_button_pressed():
|
||||
|
||||
func _on_main_menu_button_pressed():
|
||||
resume_game()
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
get_tree().change_scene_to_file(START_SCREEN_SCENE)
|
||||
|
||||
func _register_focus_sounds() -> void:
|
||||
|
||||
@@ -97,6 +97,21 @@ func _on_delete_button_pressed() -> void:
|
||||
_character_list.remove_item(index)
|
||||
_status_label.text = "Character deleted."
|
||||
|
||||
func _on_select_button_pressed() -> void:
|
||||
var selected := _character_list.get_selected_items()
|
||||
if selected.is_empty():
|
||||
_status_label.text = "Select a character first."
|
||||
return
|
||||
|
||||
var index := selected[0]
|
||||
if index < 0 or index >= _characters.size():
|
||||
_status_label.text = "Invalid selection."
|
||||
return
|
||||
|
||||
var character: Dictionary = _characters[index]
|
||||
SelectedCharacter.set_character(character)
|
||||
get_tree().change_scene_to_file("res://scenes/Levels/location_level.tscn")
|
||||
|
||||
func _on_refresh_button_pressed() -> void:
|
||||
_load_characters()
|
||||
|
||||
|
||||
@@ -92,6 +92,13 @@ layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
theme_override_constants/separation = 10
|
||||
|
||||
[node name="SelectButton" type="Button" parent="MarginContainer/ContentCenter/ContentVBox/ActionHBox"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
theme = ExtResource("4_5b3b7")
|
||||
text = "SELECT"
|
||||
text_alignment = 1
|
||||
|
||||
[node name="RefreshButton" type="Button" parent="MarginContainer/ContentCenter/ContentVBox/ActionHBox"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
@@ -124,6 +131,7 @@ text_alignment = 1
|
||||
unique_name_in_owner = true
|
||||
|
||||
[connection signal="pressed" from="MarginContainer/ContentCenter/ContentVBox/AddHBox/AddButton" to="." method="_on_add_button_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer/ContentCenter/ContentVBox/ActionHBox/SelectButton" to="." method="_on_select_button_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer/ContentCenter/ContentVBox/ActionHBox/RefreshButton" to="." method="_on_refresh_button_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer/ContentCenter/ContentVBox/ActionHBox/DeleteButton" to="." method="_on_delete_button_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer/ContentCenter/ContentVBox/ActionHBox/BackButton" to="." method="_on_back_button_pressed"]
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
extends Node
|
||||
|
||||
var character: Dictionary = {}
|
||||
|
||||
func set_character(data: Dictionary) -> void:
|
||||
character = data
|
||||
|
||||
func clear() -> void:
|
||||
character = {}
|
||||
|
||||
func get_coord() -> Vector2:
|
||||
var coord: Dictionary = character.get("coord", {})
|
||||
return Vector2(
|
||||
float(coord.get("x", 0)),
|
||||
float(coord.get("y", 0))
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bbl0our5y4k7a
|
||||
@@ -0,0 +1,105 @@
|
||||
extends RigidBody3D
|
||||
|
||||
@export var drive_speed := 18.0
|
||||
@export var drive_accel := 20.0
|
||||
@export var brake_strength := 28.0
|
||||
@export var turn_speed := 2.0
|
||||
@export var turn_accel := 8.0
|
||||
@export var lateral_damp := 10.0
|
||||
@export var launch_impulse := 28.0
|
||||
@export var launch_up_impulse := 6.0
|
||||
@export var seat_path: NodePath
|
||||
@export var exit_path: NodePath
|
||||
@export var camera_path: NodePath
|
||||
@export var interact_area_path: NodePath
|
||||
|
||||
@onready var seat: Node3D = get_node(seat_path) if seat_path != NodePath("") else null
|
||||
@onready var exit_point: Node3D = get_node(exit_path) if exit_path != NodePath("") else null
|
||||
@onready var car_camera: Camera3D = get_node(camera_path) if camera_path != NodePath("") else null
|
||||
@onready var interact_area: Area3D = get_node(interact_area_path) if interact_area_path != NodePath("") else null
|
||||
|
||||
var _nearby_driver: Node = null
|
||||
var _driver: Node = null
|
||||
|
||||
func _ready() -> void:
|
||||
if interact_area:
|
||||
interact_area.collision_layer = 2
|
||||
interact_area.collision_mask = 1
|
||||
interact_area.body_entered.connect(_on_interact_body_entered)
|
||||
interact_area.body_exited.connect(_on_interact_body_exited)
|
||||
if car_camera:
|
||||
car_camera.current = false
|
||||
contact_monitor = true
|
||||
max_contacts_reported = 8
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if _driver == null and _nearby_driver != null and Input.is_action_just_pressed("interact"):
|
||||
_enter_vehicle(_nearby_driver)
|
||||
elif _driver != null and Input.is_action_just_pressed("interact"):
|
||||
_exit_vehicle()
|
||||
|
||||
func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
|
||||
if _driver == null:
|
||||
return
|
||||
|
||||
var input2v := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
||||
var forward := global_transform.basis.z
|
||||
forward.y = 0.0
|
||||
forward = forward.normalized()
|
||||
|
||||
var current_speed := linear_velocity.dot(forward)
|
||||
var target_speed := input2v.y * drive_speed
|
||||
var accel := drive_accel if abs(input2v.y) > 0.01 else brake_strength
|
||||
var new_forward_speed := move_toward(current_speed, target_speed, accel * state.step)
|
||||
var forward_vel := forward * new_forward_speed
|
||||
var lateral_vel := linear_velocity - (forward * current_speed)
|
||||
lateral_vel = lateral_vel.move_toward(Vector3.ZERO, lateral_damp * state.step)
|
||||
linear_velocity = forward_vel + lateral_vel
|
||||
|
||||
var speed_factor: float = clamp(abs(new_forward_speed) / drive_speed, 0.0, 1.0)
|
||||
var turn_input := input2v.x
|
||||
if new_forward_speed < -0.1:
|
||||
turn_input = -turn_input
|
||||
var target_turn: float = turn_input * turn_speed * speed_factor
|
||||
angular_velocity.y = move_toward(angular_velocity.y, target_turn, turn_accel * state.step)
|
||||
|
||||
if speed_factor > 0.2:
|
||||
var hit_ids := {}
|
||||
for i in state.get_contact_count():
|
||||
var collider := state.get_contact_collider_object(i)
|
||||
if collider is RigidBody3D and collider != self:
|
||||
var collider_id := (collider as Node).get_instance_id()
|
||||
if hit_ids.has(collider_id):
|
||||
continue
|
||||
hit_ids[collider_id] = true
|
||||
var contact_pos := state.get_contact_collider_position(i)
|
||||
var launch_dir := (contact_pos - global_position).normalized()
|
||||
if launch_dir.length() <= 0.001:
|
||||
var normal_world := (global_transform.basis * state.get_contact_local_normal(i)).normalized()
|
||||
launch_dir = normal_world if normal_world.length() > 0.001 else forward.normalized()
|
||||
var impulse := launch_dir * (launch_impulse * speed_factor) + Vector3.UP * launch_up_impulse
|
||||
(collider as RigidBody3D).apply_central_impulse(impulse)
|
||||
|
||||
func _enter_vehicle(player: Node) -> void:
|
||||
if seat == null:
|
||||
return
|
||||
_driver = player
|
||||
player.call("enter_vehicle", self, seat, car_camera)
|
||||
if car_camera:
|
||||
car_camera.current = true
|
||||
|
||||
func _exit_vehicle() -> void:
|
||||
if _driver == null:
|
||||
return
|
||||
_driver.call("exit_vehicle", exit_point, car_camera)
|
||||
_driver = null
|
||||
if car_camera:
|
||||
car_camera.current = false
|
||||
|
||||
func _on_interact_body_entered(body: Node) -> void:
|
||||
if body.has_method("enter_vehicle"):
|
||||
_nearby_driver = body
|
||||
|
||||
func _on_interact_body_exited(body: Node) -> void:
|
||||
if body == _nearby_driver:
|
||||
_nearby_driver = null
|
||||
@@ -0,0 +1 @@
|
||||
uid://4qf5yinepytc
|
||||
@@ -0,0 +1,43 @@
|
||||
[gd_scene load_steps=6 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/Vehicles/car.gd" id="1_kbd20"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_7r1j6"]
|
||||
size = Vector3(1.4, 0.9, 2.6)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_jk0m1"]
|
||||
size = Vector3(2.2, 2.0, 3.8)
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_4y8xk"]
|
||||
size = Vector3(1.4, 0.9, 2.6)
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_red"]
|
||||
albedo_color = Color(0.85, 0.1, 0.1, 1)
|
||||
|
||||
[node name="Car" type="RigidBody3D"]
|
||||
script = ExtResource("1_kbd20")
|
||||
seat_path = NodePath("Seat")
|
||||
exit_path = NodePath("Exit")
|
||||
camera_path = NodePath("CarCamera")
|
||||
interact_area_path = NodePath("InteractArea")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("BoxShape3D_7r1j6")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("BoxMesh_4y8xk")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_red")
|
||||
|
||||
[node name="InteractArea" type="Area3D" parent="."]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="InteractArea"]
|
||||
shape = SubResource("BoxShape3D_jk0m1")
|
||||
|
||||
[node name="Seat" type="Node3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0, 0.6, 0.0)
|
||||
|
||||
[node name="Exit" type="Node3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.3, 0.0, 0.0)
|
||||
|
||||
[node name="CarCamera" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0, 2.0, 4.2)
|
||||
+83
-1
@@ -23,8 +23,21 @@ var _last_move_right := Vector3(1, 0, 0)
|
||||
var _camera_offset_local := Vector3.ZERO
|
||||
var _camera_yaw := 0.0
|
||||
var _camera_pitch := 0.0
|
||||
var _in_vehicle := false
|
||||
var _vehicle_collision_layer := 0
|
||||
var _vehicle_collision_mask := 0
|
||||
var _vehicle_original_parent: Node = null
|
||||
var _light_was_on := false
|
||||
var _jump_triggered := false
|
||||
@onready var _flashlight: SpotLight3D = $SpotLight3D
|
||||
@onready var _anim_player: AnimationPlayer = find_child("AnimationPlayer", true, false) as AnimationPlayer
|
||||
@onready var _model_root: Node3D = find_child("TestCharAnimated", true, false) as Node3D
|
||||
|
||||
@export var camera_follow_speed := 10.0
|
||||
@export var anim_idle_name := "Idle"
|
||||
@export var anim_walk_name := "Walk"
|
||||
@export var anim_jump_name := "Jump"
|
||||
@export var anim_walk_speed_threshold := 0.25
|
||||
|
||||
var jump_sound = preload("res://assets/audio/jump.ogg")
|
||||
var audio_player = AudioStreamPlayer.new()
|
||||
@@ -60,8 +73,13 @@ func _ready() -> void:
|
||||
_last_move_forward = forward.normalized()
|
||||
if right.length() > 0.0001:
|
||||
_last_move_right = right.normalized()
|
||||
_vehicle_collision_layer = collision_layer
|
||||
_vehicle_collision_mask = collision_mask
|
||||
|
||||
func _integrate_forces(state):
|
||||
if _in_vehicle:
|
||||
linear_velocity = Vector3.ZERO
|
||||
return
|
||||
if cameraMoveMode and _pending_mouse_delta != Vector2.ZERO:
|
||||
rotation_x -= _pending_mouse_delta.y * mouse_sensitivity
|
||||
rotation_y -= _pending_mouse_delta.x * mouse_sensitivity
|
||||
@@ -117,6 +135,7 @@ func _integrate_forces(state):
|
||||
current_number_of_jumps = (current_number_of_jumps + 1) % 2
|
||||
linear_velocity.y = JUMP_SPEED
|
||||
audio_player.play()
|
||||
_jump_triggered = true
|
||||
|
||||
if cam:
|
||||
var target_yaw := global_transform.basis.get_euler().y
|
||||
@@ -126,7 +145,12 @@ func _integrate_forces(state):
|
||||
cam.global_position = cam.global_position.lerp(target_pos, camera_follow_speed * state.step)
|
||||
cam.global_rotation = Vector3(_camera_pitch, _camera_yaw, 0.0)
|
||||
|
||||
_update_animation(on_floor, state.linear_velocity)
|
||||
_jump_triggered = false
|
||||
|
||||
func _input(event):
|
||||
if _in_vehicle:
|
||||
return
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == MOUSE_BUTTON_MIDDLE:
|
||||
if event.pressed:
|
||||
@@ -146,9 +170,67 @@ func _input(event):
|
||||
zoom_camera(ZOOM_FACTOR) # Zoom out
|
||||
|
||||
if event.is_action_pressed("player_light"):
|
||||
$SpotLight3D.visible = !$SpotLight3D.visible
|
||||
_flashlight.visible = !_flashlight.visible
|
||||
|
||||
func zoom_camera(factor):
|
||||
var new_fov = cam.fov * factor
|
||||
cam.fov = clamp(new_fov, MIN_FOV, MAX_FOV)
|
||||
|
||||
func _update_animation(on_floor: bool, velocity: Vector3) -> void:
|
||||
if _anim_player == null:
|
||||
return
|
||||
var horizontal_speed := Vector3(velocity.x, 0.0, velocity.z).length()
|
||||
if _jump_triggered and _anim_player.has_animation(anim_jump_name):
|
||||
if _anim_player.current_animation != anim_jump_name:
|
||||
_anim_player.play(anim_jump_name)
|
||||
return
|
||||
if not on_floor and _anim_player.has_animation(anim_jump_name):
|
||||
if _anim_player.current_animation != anim_jump_name:
|
||||
_anim_player.play(anim_jump_name)
|
||||
return
|
||||
if horizontal_speed > anim_walk_speed_threshold and _anim_player.has_animation(anim_walk_name):
|
||||
if _anim_player.current_animation != anim_walk_name:
|
||||
_anim_player.play(anim_walk_name)
|
||||
return
|
||||
if _anim_player.has_animation(anim_idle_name):
|
||||
if _anim_player.current_animation != anim_idle_name:
|
||||
_anim_player.play(anim_idle_name)
|
||||
|
||||
func enter_vehicle(_vehicle: Node, seat: Node3D, vehicle_camera: Camera3D) -> void:
|
||||
_in_vehicle = true
|
||||
freeze = true
|
||||
sleeping = true
|
||||
collision_layer = 0
|
||||
collision_mask = 0
|
||||
_vehicle_original_parent = get_parent()
|
||||
_light_was_on = _flashlight.visible
|
||||
_flashlight.visible = false
|
||||
if _model_root:
|
||||
_model_root.visible = false
|
||||
if seat:
|
||||
reparent(seat, true)
|
||||
global_transform = seat.global_transform
|
||||
if cam:
|
||||
cam.current = false
|
||||
if vehicle_camera:
|
||||
vehicle_camera.current = true
|
||||
|
||||
func exit_vehicle(exit_point: Node3D, vehicle_camera: Camera3D) -> void:
|
||||
_in_vehicle = false
|
||||
freeze = false
|
||||
sleeping = false
|
||||
collision_layer = _vehicle_collision_layer
|
||||
collision_mask = _vehicle_collision_mask
|
||||
if _vehicle_original_parent:
|
||||
reparent(_vehicle_original_parent, true)
|
||||
_vehicle_original_parent = null
|
||||
_flashlight.visible = _light_was_on
|
||||
if _model_root:
|
||||
_model_root.visible = true
|
||||
if exit_point:
|
||||
global_transform = exit_point.global_transform
|
||||
if vehicle_camera:
|
||||
vehicle_camera.current = false
|
||||
if cam:
|
||||
cam.current = true
|
||||
|
||||
|
||||
@@ -11,10 +11,12 @@ namespace CharacterApi.Controllers;
|
||||
public class CharactersController : ControllerBase
|
||||
{
|
||||
private readonly CharacterStore _characters;
|
||||
private readonly LocationsClient _locations;
|
||||
|
||||
public CharactersController(CharacterStore characters)
|
||||
public CharactersController(CharacterStore characters, LocationsClient locations)
|
||||
{
|
||||
_characters = characters;
|
||||
_locations = locations;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@@ -67,4 +69,39 @@ public class CharactersController : ControllerBase
|
||||
|
||||
return Ok("Deleted");
|
||||
}
|
||||
|
||||
[HttpPut("{id}/move")]
|
||||
[Authorize(Roles = "USER,SUPER")]
|
||||
public async Task<IActionResult> Move(string id, [FromBody] MoveCharacterRequest req, CancellationToken ct)
|
||||
{
|
||||
if (req?.Coord is null)
|
||||
return BadRequest("Coord required");
|
||||
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (string.IsNullOrWhiteSpace(userId))
|
||||
return Unauthorized();
|
||||
|
||||
var allowAnyOwner = User.IsInRole("SUPER");
|
||||
var existing = await _characters.GetForOwnerByIdAsync(id, userId, allowAnyOwner);
|
||||
if (existing is null)
|
||||
return NotFound();
|
||||
|
||||
var presence = await _locations.UpdatePresenceAsync(id, req.Coord, ct);
|
||||
if (!presence.Ok)
|
||||
{
|
||||
var message = string.IsNullOrWhiteSpace(presence.Body)
|
||||
? "Location presence update failed"
|
||||
: presence.Body;
|
||||
return StatusCode((int)presence.Status, message);
|
||||
}
|
||||
|
||||
var updated = await _characters.UpdateCoordAsync(id, userId, allowAnyOwner, req.Coord);
|
||||
if (!updated)
|
||||
{
|
||||
await _locations.UpdatePresenceAsync(id, existing.Coord, ct);
|
||||
return StatusCode(500, "Failed to update character coord");
|
||||
}
|
||||
|
||||
return Ok("Moved");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,15 @@ Inbound JSON documents
|
||||
"name": "string"
|
||||
}
|
||||
```
|
||||
- MoveCharacterRequest (`PUT /api/characters/{id}/move`)
|
||||
```json
|
||||
{
|
||||
"coord": {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Stored documents (MongoDB)
|
||||
- Character
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace CharacterApi.Models;
|
||||
|
||||
public class MoveCharacterRequest
|
||||
{
|
||||
public Coord? Coord { get; set; }
|
||||
}
|
||||
@@ -9,6 +9,11 @@ builder.Services.AddControllers();
|
||||
|
||||
// DI
|
||||
builder.Services.AddSingleton<CharacterStore>();
|
||||
builder.Services.AddHttpClient<LocationsClient>(client =>
|
||||
{
|
||||
var baseUrl = builder.Configuration["LocationsApi:BaseUrl"] ?? "http://localhost:5002";
|
||||
client.BaseAddress = new Uri(baseUrl);
|
||||
});
|
||||
|
||||
// Swagger + JWT auth in Swagger
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
||||
@@ -7,3 +7,4 @@ See `DOCUMENTS.md` for request payloads and stored document shapes.
|
||||
- `POST /api/characters` Create a character.
|
||||
- `GET /api/characters` List characters for the current user.
|
||||
- `DELETE /api/characters/{id}` Delete a character owned by the current user.
|
||||
- `PUT /api/characters/{id}/move` Move a character to a new coord.
|
||||
|
||||
@@ -24,6 +24,36 @@ public class CharacterStore
|
||||
public Task<List<Character>> GetForOwnerAsync(string ownerUserId) =>
|
||||
_col.Find(c => c.OwnerUserId == ownerUserId).ToListAsync();
|
||||
|
||||
public async Task<Character?> GetForOwnerByIdAsync(string id, string ownerUserId, bool allowAnyOwner)
|
||||
{
|
||||
var filter = Builders<Character>.Filter.Eq(c => c.Id, id);
|
||||
if (!allowAnyOwner)
|
||||
{
|
||||
filter = Builders<Character>.Filter.And(
|
||||
filter,
|
||||
Builders<Character>.Filter.Eq(c => c.OwnerUserId, ownerUserId)
|
||||
);
|
||||
}
|
||||
|
||||
return await _col.Find(filter).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateCoordAsync(string id, string ownerUserId, bool allowAnyOwner, Coord coord)
|
||||
{
|
||||
var filter = Builders<Character>.Filter.Eq(c => c.Id, id);
|
||||
if (!allowAnyOwner)
|
||||
{
|
||||
filter = Builders<Character>.Filter.And(
|
||||
filter,
|
||||
Builders<Character>.Filter.Eq(c => c.OwnerUserId, ownerUserId)
|
||||
);
|
||||
}
|
||||
|
||||
var update = Builders<Character>.Update.Set(c => c.Coord, coord);
|
||||
var result = await _col.UpdateOneAsync(filter, update);
|
||||
return result.ModifiedCount > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteForOwnerAsync(string id, string ownerUserId, bool allowAnyOwner)
|
||||
{
|
||||
var filter = Builders<Character>.Filter.Eq(c => c.Id, id);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using CharacterApi.Models;
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace CharacterApi.Services;
|
||||
|
||||
public class LocationsClient
|
||||
{
|
||||
private readonly HttpClient _http;
|
||||
private readonly string _internalKey;
|
||||
|
||||
public LocationsClient(HttpClient http, IConfiguration cfg)
|
||||
{
|
||||
_http = http;
|
||||
_internalKey = cfg["LocationsApi:InternalKey"] ?? string.Empty;
|
||||
}
|
||||
|
||||
public async Task<(bool Ok, HttpStatusCode Status, string? Body)> UpdatePresenceAsync(
|
||||
string characterId,
|
||||
Coord coord,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
using var request = new HttpRequestMessage(HttpMethod.Post, "api/locations/presence")
|
||||
{
|
||||
Content = JsonContent.Create(new { characterId, coord })
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(_internalKey))
|
||||
request.Headers.TryAddWithoutValidation("X-Internal-Key", _internalKey);
|
||||
|
||||
using var response = await _http.SendAsync(request, ct);
|
||||
var body = await response.Content.ReadAsStringAsync(ct);
|
||||
return (response.IsSuccessStatusCode, response.StatusCode, body);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"Kestrel": { "Endpoints": { "Http": { "Url": "http://0.0.0.0:5001" } } },
|
||||
"MongoDB": { "ConnectionString": "mongodb://192.168.86.50:27017", "DatabaseName": "promiscuity" },
|
||||
"LocationsApi": { "BaseUrl": "http://localhost:5002", "InternalKey": "dev-internal-key" },
|
||||
"Jwt": { "Key": "SuperUltraSecureJwtKeyWithAtLeast32Chars!!", "Issuer": "promiscuity", "Audience": "promiscuity-auth-api" },
|
||||
"Logging": { "LogLevel": { "Default": "Information" } }
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"Kestrel": { "Endpoints": { "Http": { "Url": "http://0.0.0.0:5001" } } },
|
||||
"MongoDB": { "ConnectionString": "mongodb://192.168.86.50:27017", "DatabaseName": "promiscuity" },
|
||||
"LocationsApi": { "BaseUrl": "http://localhost:5002", "InternalKey": "dev-internal-key" },
|
||||
"Jwt": { "Key": "SuperUltraSecureJwtKeyWithAtLeast32Chars!!", "Issuer": "promiscuity", "Audience": "promiscuity-auth-api" },
|
||||
"Logging": { "LogLevel": { "Default": "Information" } },
|
||||
"AllowedHosts": "*"
|
||||
|
||||
@@ -11,10 +11,12 @@ namespace LocationsApi.Controllers;
|
||||
public class LocationsController : ControllerBase
|
||||
{
|
||||
private readonly LocationStore _locations;
|
||||
private readonly IConfiguration _cfg;
|
||||
|
||||
public LocationsController(LocationStore locations)
|
||||
public LocationsController(LocationStore locations, IConfiguration cfg)
|
||||
{
|
||||
_locations = locations;
|
||||
_cfg = cfg;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@@ -31,6 +33,7 @@ public class LocationsController : ControllerBase
|
||||
{
|
||||
Name = req.Name.Trim(),
|
||||
Coord = req.Coord,
|
||||
CharacterIds = new List<string>(),
|
||||
CreatedUtc = DateTime.UtcNow
|
||||
};
|
||||
|
||||
@@ -85,4 +88,28 @@ public class LocationsController : ControllerBase
|
||||
|
||||
return Ok("Updated");
|
||||
}
|
||||
|
||||
[HttpPost("presence")]
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> UpdatePresence([FromBody] UpdateLocationPresenceRequest req)
|
||||
{
|
||||
var internalKey = _cfg["Internal:Key"];
|
||||
if (!string.IsNullOrWhiteSpace(internalKey))
|
||||
{
|
||||
if (!Request.Headers.TryGetValue("X-Internal-Key", out var provided) || provided != internalKey)
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(req.CharacterId))
|
||||
return BadRequest("CharacterId required");
|
||||
|
||||
if (req.Coord is null)
|
||||
return BadRequest("Coord required");
|
||||
|
||||
var updated = await _locations.UpdatePresenceAsync(req.CharacterId.Trim(), req.Coord);
|
||||
if (!updated)
|
||||
return NotFound("Location not found");
|
||||
|
||||
return Ok("Updated");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,16 @@ Inbound JSON documents
|
||||
}
|
||||
```
|
||||
`coord` cannot be updated.
|
||||
- UpdateLocationPresenceRequest (`POST /api/locations/presence`)
|
||||
```json
|
||||
{
|
||||
"characterId": "string",
|
||||
"coord": {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Stored documents (MongoDB)
|
||||
- Location
|
||||
@@ -32,6 +42,7 @@ Stored documents (MongoDB)
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"characterIds": ["string"],
|
||||
"createdUtc": "string (ISO-8601 datetime)"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -15,6 +15,9 @@ public class Location
|
||||
[BsonElement("coord")]
|
||||
public required Coord Coord { get; set; }
|
||||
|
||||
[BsonElement("characterIds")]
|
||||
public List<string> CharacterIds { get; set; } = new();
|
||||
|
||||
[BsonElement("createdUtc")]
|
||||
public DateTime CreatedUtc { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace LocationsApi.Models;
|
||||
|
||||
public class UpdateLocationPresenceRequest
|
||||
{
|
||||
public string CharacterId { get; set; } = string.Empty;
|
||||
|
||||
public Coord? Coord { get; set; }
|
||||
}
|
||||
@@ -8,3 +8,4 @@ See `DOCUMENTS.md` for request payloads and stored document shapes.
|
||||
- `GET /api/locations` List all locations (SUPER only).
|
||||
- `DELETE /api/locations/{id}` Delete a location (SUPER only).
|
||||
- `PUT /api/locations/{id}` Update a location name (SUPER only).
|
||||
- `POST /api/locations/presence` Update which characters are present at a coord (internal).
|
||||
|
||||
@@ -54,6 +54,13 @@ public class LocationStore
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"characterIds", new BsonDocument
|
||||
{
|
||||
{ "bsonType", "array" },
|
||||
{ "items", new BsonDocument { { "bsonType", "string" } } }
|
||||
}
|
||||
},
|
||||
{ "createdUtc", new BsonDocument { { "bsonType", "date" } } }
|
||||
}
|
||||
}
|
||||
@@ -103,6 +110,24 @@ public class LocationStore
|
||||
return result.ModifiedCount > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdatePresenceAsync(string characterId, Coord coord)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(characterId))
|
||||
return false;
|
||||
|
||||
var pullFilter = Builders<Location>.Filter.AnyEq(l => l.CharacterIds, characterId);
|
||||
var pullUpdate = Builders<Location>.Update.Pull(l => l.CharacterIds, characterId);
|
||||
await _col.UpdateManyAsync(pullFilter, pullUpdate);
|
||||
|
||||
var targetFilter = Builders<Location>.Filter.And(
|
||||
Builders<Location>.Filter.Eq(l => l.Coord.X, coord.X),
|
||||
Builders<Location>.Filter.Eq(l => l.Coord.Y, coord.Y)
|
||||
);
|
||||
var addUpdate = Builders<Location>.Update.AddToSet(l => l.CharacterIds, characterId);
|
||||
var result = await _col.UpdateOneAsync(targetFilter, addUpdate);
|
||||
return result.MatchedCount > 0;
|
||||
}
|
||||
|
||||
private void EnsureOriginLocation()
|
||||
{
|
||||
var filter = Builders<Location>.Filter.And(
|
||||
@@ -117,6 +142,7 @@ public class LocationStore
|
||||
{
|
||||
Name = "Origin",
|
||||
Coord = new Coord { X = 0, Y = 0 },
|
||||
CharacterIds = new List<string>(),
|
||||
CreatedUtc = DateTime.UtcNow
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"Kestrel": { "Endpoints": { "Http": { "Url": "http://0.0.0.0:5002" } } },
|
||||
"MongoDB": { "ConnectionString": "mongodb://192.168.86.50:27017", "DatabaseName": "promiscuity" },
|
||||
"Internal": { "Key": "dev-internal-key" },
|
||||
"Jwt": { "Key": "SuperUltraSecureJwtKeyWithAtLeast32Chars!!", "Issuer": "promiscuity", "Audience": "promiscuity-auth-api" },
|
||||
"Logging": { "LogLevel": { "Default": "Information" } }
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"Kestrel": { "Endpoints": { "Http": { "Url": "http://0.0.0.0:5002" } } },
|
||||
"MongoDB": { "ConnectionString": "mongodb://192.168.86.50:27017", "DatabaseName": "promiscuity" },
|
||||
"Internal": { "Key": "dev-internal-key" },
|
||||
"Jwt": { "Key": "SuperUltraSecureJwtKeyWithAtLeast32Chars!!", "Issuer": "promiscuity", "Audience": "promiscuity-auth-api" },
|
||||
"Logging": { "LogLevel": { "Default": "Information" } },
|
||||
"AllowedHosts": "*"
|
||||
|
||||
Reference in New Issue
Block a user