-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added lock system and fixed a few small spellings * When locked, player will fall etc, but stop walking * Also repathed the project.godot icon to prevent an error, and added a few debug functions to LockSystem --------- Co-authored-by: Adam Courtney <adam@thefunnybrain.com>
- Loading branch information
1 parent
bdc1243
commit ab13a8e
Showing
6 changed files
with
123 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
extends Node | ||
class_name LockSystem | ||
|
||
#The array of locks that are presently applied. The player can perform an action if this array is empty. | ||
#The locks can be used for any manner of things: player movement in cutscenes, restricting dialogue choices, door open conditions etc | ||
var _locks = [] | ||
|
||
var lock_count : int : | ||
get: | ||
return _locks.size() | ||
|
||
#An event to hook into - primarily for debugging. | ||
signal Lock_Added(lockName:String) | ||
signal Lock_Removed(lockName:String) | ||
|
||
#This one should only emit if is_locked would have changed. | ||
signal Lock_Status_Changed(newStatus:bool) | ||
|
||
#A getter to see if any locks are being applied | ||
@export var is_locked : bool : | ||
get: | ||
return _check_is_locked() | ||
|
||
#If a lock called lock_name hasn't already been added, adds one. | ||
func add_lock(lock_name:String): | ||
#Don't add duplicate locks | ||
if(contains_lock(lock_name)): | ||
print_debug("Lock %lock is already added." % lock_name) | ||
return | ||
else: | ||
#Add locks and emit events | ||
_locks.append(lock_name) | ||
emit_signal("Lock_Added", lock_name) | ||
#if this is the first and only lock, the locked status has changed to true | ||
if(_locks.size() == 1): | ||
Lock_Status_Changed.emit(true) | ||
return; | ||
|
||
#Removes a lock with the name lock_name. Prints a message if it's not in there. | ||
func remove_lock(lock_name:String): | ||
if(contains_lock(lock_name)): | ||
_locks.erase(lock_name) | ||
#If there's now zero locks remaining, emit event | ||
if(_locks.size() == 0): | ||
Lock_Status_Changed.emit(false) | ||
else: | ||
print_debug("Lock %lock cannot be removed as it isn't there." % lock_name) | ||
|
||
#Returns true if _locks has any entries added, false if no locks are being applied | ||
func _check_is_locked(): | ||
return _locks.size() > 0; | ||
|
||
#Returns true if a lock called lock_name is already added to _locks | ||
func contains_lock(lock_name:String): | ||
for lock in _locks: | ||
if lock == lock_name: | ||
return true; | ||
return false; | ||
|
||
#Prints all current locks - useful for tracking down issues when locks haven't been lifted | ||
func debug_locks(): | ||
var log = "Printing all locks" | ||
for lock in _locks: | ||
print_debug("\n" + str(lock)) | ||
|
||
#To be used for debug - for when the locks need to be bypassed to test. | ||
func debug_release_all_locks(): | ||
for lock in _locks: | ||
Lock_Removed.emit(lock) | ||
_locks.clear(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters