-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathTransmissionResource.gd
61 lines (46 loc) · 1.44 KB
/
TransmissionResource.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class_name TransmissionResource
extends ValueResource
## Notifies a need to be updated
signal update_requested
## Value for error from transmission receiver
enum ErrorType {
## Default value
NONE = -1,
## Transmission processed successfully
SUCCESS = 0,
## Try transmission next physics frame
TRY_AGAIN,
## Transmission processing was denied
DENIED,
## Transmission process was denied
FAILED}
@export_group("TransmissionResource")
## Used as transmission channel to match which receiver needs to process it
@export var transmission_name:StringName
## State of transmission process
@export var state:ErrorType = ErrorType.NONE
## Receiving end might decide that transmission is invalid and processing will be cancelled.
@export var valid:bool = true
##
func send_transmission(receiver:AreaReceiver2D)->bool:
assert( !transmission_name.is_empty() )
## Receiving end must call either one
receiver.receive(self)
# TODO: if signal exists use this assert
#assert(state != ErrorType.NONE)
return state == ErrorType.SUCCESS
func success()->void:
state = ErrorType.SUCCESS
func try_again()->void:
state = ErrorType.TRY_AGAIN
func failed()->void:
state = ErrorType.FAILED
func denied()->void:
state = ErrorType.DENIED
func invalid()->void:
valid = false
## Receiver need to provide a reference to a ResourceNode
## Override this function with specific use.
## Should result with a state change
func process(resource_node:ResourceNode)->void:
pass