Merge branch 'main' of http://192.168.1.120:3000/derekdz/fps_project_1
This commit is contained in:
51
scripts/authentication.gd
Normal file
51
scripts/authentication.gd
Normal file
@@ -0,0 +1,51 @@
|
||||
extends Control
|
||||
|
||||
@onready var email_edit: LineEdit = $VBoxContainer/email_edit
|
||||
@onready var password_edit: LineEdit = $VBoxContainer/password_edit
|
||||
@onready var state_label: Label = %StateLabel
|
||||
|
||||
func _ready() -> void:
|
||||
Firebase.Auth.login_succeeded.connect(on_login_succeeded)
|
||||
Firebase.Auth.login_failed.connect(on_login_failed)
|
||||
Firebase.Auth.signup_succeeded.connect(on_signup_succeeded)
|
||||
Firebase.Auth.signup_failed.connect(on_signup_failed)
|
||||
|
||||
if Firebase.Auth.check_auth_file():
|
||||
state_label.text = "Logged in"
|
||||
|
||||
func _on_log_in_pressed() -> void:
|
||||
var email = email_edit.text
|
||||
var password = password_edit.text
|
||||
Firebase.Auth.login_with_email_and_password(email,password)
|
||||
|
||||
state_label.text = "Logging In"
|
||||
|
||||
|
||||
func _on_sign_up_pressed() -> void:
|
||||
var email = email_edit.text
|
||||
var password = password_edit.text
|
||||
Firebase.Auth.signup_with_email_and_password(email,password)
|
||||
|
||||
state_label.text = "Signing Up"
|
||||
|
||||
func on_login_succeeded(auth):
|
||||
print(auth)
|
||||
state_label.text = "Login Success!"
|
||||
Firebase.Auth.save_auth(auth)
|
||||
visible = false
|
||||
|
||||
func on_signup_succeeded(auth):
|
||||
print(auth)
|
||||
state_label.text = "Signup Success!"
|
||||
Firebase.Auth.save_auth(auth)
|
||||
visible = false
|
||||
|
||||
func on_login_failed(error_code,message):
|
||||
print(error_code)
|
||||
print(message)
|
||||
state_label.text = "Login failed. Error: %s" % message
|
||||
|
||||
func on_signup_failed(error_code,message):
|
||||
print(error_code)
|
||||
print(message)
|
||||
state_label.text = "Signup failed. Error: %s" % message
|
||||
1
scripts/authentication.gd.uid
Normal file
1
scripts/authentication.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cbmnj1dfgfwp5
|
||||
@@ -17,3 +17,4 @@ func _process(delta: float) -> void:
|
||||
|
||||
func interact():
|
||||
SignalBus.emit_signal("money_deposited")
|
||||
Leaderboard.save_leaderboard_data()
|
||||
|
||||
44
scripts/leaderboard.gd
Normal file
44
scripts/leaderboard.gd
Normal file
@@ -0,0 +1,44 @@
|
||||
extends Node
|
||||
|
||||
func save_leaderboard_data():
|
||||
var auth = Firebase.Auth.auth
|
||||
var COLLECTION_ID = get_leaderboard_name()
|
||||
if auth.localid:
|
||||
var collection: FirestoreCollection = Firebase.Firestore.collection(COLLECTION_ID)
|
||||
var data : Dictionary = {
|
||||
"user_name" : GameGlobals.user_names[GameGlobals.user_id],
|
||||
"leaderboard" : get_leaderboard_name(),
|
||||
"high_score" : GameGlobals.high_score,
|
||||
"money" : GameGlobals.money,
|
||||
"deposited_money" : GameGlobals.deposited_money
|
||||
}
|
||||
print("DATA: ",data)
|
||||
var document = await collection.get_doc(auth.localid)
|
||||
if document:
|
||||
for key in data.keys():
|
||||
document.add_or_update_field(key,data[key])
|
||||
var task = await collection.update(document)
|
||||
if task:
|
||||
print("Document updated successfully")
|
||||
else:
|
||||
print("Failed to update document")
|
||||
else:
|
||||
await collection.add(auth.localid,data)
|
||||
|
||||
func load_leaderboard_data():
|
||||
var auth = Firebase.Auth.auth
|
||||
var COLLECTION_ID = get_leaderboard_name()
|
||||
|
||||
if auth.localid:
|
||||
var collection : FirestoreCollection = Firebase.Firestore.collection(COLLECTION_ID)
|
||||
|
||||
var document = await collection.get_doc(auth.localid)
|
||||
|
||||
if document:
|
||||
print(document)
|
||||
return document
|
||||
else:
|
||||
print("Failed to load document from Firebase")
|
||||
|
||||
func get_leaderboard_name():
|
||||
return "leaderboard_" + str(GameGlobals.all_user_leaderboards[GameGlobals.user_id][GameGlobals.last_leaderboard_id])
|
||||
1
scripts/leaderboard.gd.uid
Normal file
1
scripts/leaderboard.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ccnfikfg8kph1
|
||||
@@ -8,8 +8,11 @@ var last_scene
|
||||
@onready var option_button: OptionButton = $MarginContainer/VBoxContainer/HBoxContainer/OptionButton
|
||||
@onready var add_leaderboard: Button = $"MarginContainer/VBoxContainer/HBoxContainer/Add Leaderboard"
|
||||
@onready var add_leaderboard_menu: Control = $"Add Leaderboard Menu"
|
||||
@onready var new_leaderboard_name: TextEdit = $"Add Leaderboard Menu/MarginContainer/HBoxContainer/NewLeaderboardName"
|
||||
@onready var new_leaderboard_name: LineEdit = $"Add Leaderboard Menu/MarginContainer/HBoxContainer/NewLeaderboardName"
|
||||
@onready var confirm_leaderboard_add: Button = $"Add Leaderboard Menu/MarginContainer/HBoxContainer/Confirm"
|
||||
@onready var user_name: TextEdit = $MarginContainer/VBoxContainer/UserName
|
||||
@onready var login_status_label: Label = $MarginContainer/VBoxContainer/LoginStatusLabel
|
||||
|
||||
|
||||
|
||||
func _enter_tree() -> void:
|
||||
@@ -22,6 +25,9 @@ func _ready() -> void:
|
||||
playlist_generator.load_playlist()
|
||||
refresh_option_list()
|
||||
continue_text_check()
|
||||
|
||||
user_name.text = GameGlobals.user_names[GameGlobals.user_id]
|
||||
login_status()
|
||||
|
||||
|
||||
func _on_continue_pressed() -> void:
|
||||
@@ -79,3 +85,11 @@ func _on_confirm_pressed() -> void:
|
||||
func _on_option_button_item_selected(index: int) -> void:
|
||||
GameGlobals.last_leaderboard_id = option_button.selected
|
||||
continue_text_check()
|
||||
|
||||
|
||||
func _on_user_name_text_changed() -> void:
|
||||
GameGlobals.user_names[GameGlobals.user_id] = user_name.text
|
||||
|
||||
func login_status():
|
||||
if Firebase.Auth.check_auth_file():
|
||||
login_status_label.text = "Logged in"
|
||||
|
||||
@@ -68,6 +68,7 @@ var gun_is_holstered = false
|
||||
@onready var level_control = get_tree().current_scene
|
||||
@onready var interact_ray = $Head/Recoil/Camera3D/InteractRay
|
||||
@onready var bullet_ray = $Head/Recoil/Camera3D/BulletRay
|
||||
@onready var gun_look_target: Marker3D = $Head/Recoil/Camera3D/BulletRay/GunLookTarget
|
||||
@onready var wall_ray_1: RayCast3D = $wall_ray1
|
||||
@onready var wall_ray_2: RayCast3D = $wall_ray2
|
||||
@onready var wall_ray_3: RayCast3D = $wall_ray3
|
||||
@@ -695,12 +696,18 @@ func weapon_tilt(input_x, delta):
|
||||
camera.rotation.z = lerp(camera.rotation.z, -input_x * HEAD_TILT_AMT, 5 * delta)
|
||||
|
||||
func weapon_sway(delta):
|
||||
#aim gun at center screen
|
||||
if !gun_ray.is_colliding():
|
||||
gun.look_at(gun_look_target.global_position)
|
||||
|
||||
#apply sway
|
||||
if !ads:
|
||||
var joy_input = Vector2(Input.get_joy_axis(0,JOY_AXIS_RIGHT_X)*5,Input.get_joy_axis(0,JOY_AXIS_RIGHT_Y)*5)
|
||||
mouse_input = lerp(mouse_input, Vector2.ZERO, 10 * delta)
|
||||
joy_input = lerp(joy_input,Vector2.ZERO,10 * delta)
|
||||
weapon_holder.rotation.x = lerp(weapon_holder.rotation.x, (mouse_input.y + joy_input.y) * weapon_sway_amount, 5 * delta)
|
||||
weapon_holder.rotation.y = lerp(weapon_holder.rotation.y, (mouse_input.x + joy_input.x) * weapon_sway_amount, 5 * delta)
|
||||
|
||||
else:
|
||||
if gun != null:
|
||||
if gun.weapon_info.ads == true:
|
||||
|
||||
@@ -47,6 +47,7 @@ func load_persistent_data():
|
||||
print("No file found...")
|
||||
|
||||
func save_user_data():
|
||||
Leaderboard.save_leaderboard_data()
|
||||
var user_save_path = str("user://user_",str(GameGlobals.user_id),"_",str(GameGlobals.all_user_leaderboards[GameGlobals.user_id][GameGlobals.last_leaderboard_id]),"_data.save")
|
||||
var file = FileAccess.open(user_save_path, FileAccess.WRITE)
|
||||
|
||||
@@ -148,6 +149,7 @@ func load_user_data():
|
||||
|
||||
|
||||
func save_game_data(level_name):
|
||||
Leaderboard.save_leaderboard_data()
|
||||
var level_control = get_tree().current_scene
|
||||
var player = level_control.player
|
||||
var game_save_path = str("user://user_",str(GameGlobals.user_id),"_",str(GameGlobals.all_user_leaderboards[GameGlobals.user_id][GameGlobals.last_leaderboard_id]),"_last_level","_data.save")
|
||||
|
||||
@@ -10,7 +10,7 @@ extends Node3D
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
Leaderboard.load_leaderboard_data()
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
|
||||
@@ -162,14 +162,13 @@ func reload():
|
||||
|
||||
func spawn_mag():
|
||||
var instance_mag = weapon_info.mag.instantiate()
|
||||
if spawn_av_lv.size() == 1:
|
||||
await spawn_av_lv.size() ==2
|
||||
var anim_velocity = solve_anim_av_lv()
|
||||
|
||||
instance_mag.position = mag_ejector.global_position
|
||||
instance_mag.transform.basis = mag_ejector.global_transform.basis
|
||||
instance_mag.linear_velocity += global_transform.basis * (anim_velocity["lv"] * 5) + player.velocity
|
||||
instance_mag.angular_velocity += global_transform.basis * anim_velocity["av"]
|
||||
|
||||
get_tree().get_root().add_child(instance_mag)
|
||||
|
||||
func spawn_casing():
|
||||
|
||||
Reference in New Issue
Block a user