Skip to content

Commit

Permalink
Merge pull request #1 from opensuspect/main
Browse files Browse the repository at this point in the history
e
  • Loading branch information
TheRyeGuyWhoWillNowDie authored Dec 19, 2020
2 parents 87c4e7a + d6dc4c0 commit 854cf9b
Show file tree
Hide file tree
Showing 153 changed files with 6,106 additions and 3,283 deletions.
121 changes: 121 additions & 0 deletions code-styleguide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
## Use descriptive variable names
### Bad
func computerTime(d):
### Good
func computeTime(daysElapsed):
## Be consistent
### Bad
obj.fetch()
thing.Get()
### Good
obj.get()
thing.get()

## The first word in a function name should be a verb, in a class it should be a noun
### Bad
timerIncrement()
### Good
incrementTimer()

## Avoid vague comments
### Bad
# TODO
setTime()
### Good
# TODO: add timezones
setTime()

## Avoid excessive elif
### Bad
````
if (a ==1):
doSomething()
elif (a == 2)
doSomethingElse()
elif (a ==3)
doYetAnotherThing()
else
doDefaultThing()
````
### Good
````
match a:
1:
doSomething()
2:
doSomethingElse()
3:
doYetAnotherThing()
_:
doDefaultThing()
````
## Avoid deep nesting
### Bad
````
if objectExists():
if objectIsGreen():
if objectIsMoving():
return true
else:
return false
else:
return false
else:
return false
````
### Good
````
if not objectExists():
return false
if not objectIsGreen():
return false
if not objectIsMoving():
return false
return true
````
## Avoid horizontally long code
### Bad
var colors = {1: "green", 2: "red", 3: "orange", 4: "purple"}
### Good
```
var colors = {}
colors[1] = "green"
colors[2] = "red"
colors[3] = "orange"
colors[4] = "purple"
```

## Obey the Law of Demeter
### Bad
Players[i].player.inventory += item
### Good
Players[current].AddInventoryItem(item)

## Break long functions up
### Bad
````
func doSomethingComplex:
# Setup
[ 30 lines of code ]
# Process
[ 60 lines of code ]
# Cleanup
[ 20 lines of code ]
````
### Good
````
func doSomethingComplex:
var values = setup()
process(values)
cleanup()
````
## Keep code DRY (don't repeat yourself)
### Bad
````
process(obj1)
process(obj2)
process(obj3)
````
### Good
for obj in [obj1, obj2, obj3]:
process(obj)
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ interact_data = {

}

[sub_resource type="Resource" id=2]
[sub_resource type="Resource" id=4]
resource_local_to_scene = true
resource_name = "InteractUI"
script = ExtResource( 4 )
ui_name = "clockset"
ui_name = ""
ui_data = {

}
Expand All @@ -31,7 +31,7 @@ resource_local_to_scene = true
resource_name = "InteractTask"
script = ExtResource( 5 )
task_text = ""
ui_resource = SubResource( 2 )
ui_resource = SubResource( 4 )
outputs/toggle_map_interactions = false

[resource]
Expand Down
17 changes: 14 additions & 3 deletions src/addons/opensusinteraction/resources/interactmap/interactmap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var attached_to: Node
#data to pass to the UI node
export(Dictionary) var interact_data

var network_sync: bool = false

var reported_interact_data: Dictionary = {}

#called to execute the interaction this resource is customized for
Expand All @@ -22,7 +24,7 @@ func interact(_from: Node, _interact_data: Dictionary = {}):
return
#print("InteractMap attached_to: ", attached_to)
#print(attached_to.get_node(interact_with))
MapManager.interact_with(attached_to.get_node(interact_with), attached_to, _interact_data)
MapManager.interact_with(attached_to.get_node(interact_with), attached_to, _interact_data, network_sync)

func init_resource(_from: Node, interact_data: Dictionary = {}):
if attached_to == null and _from != null:
Expand Down Expand Up @@ -61,17 +63,26 @@ func _init():
#match actual var names
func _set(property, value):
pass
# match property:
match property:
"advanced/network_sync":
network_sync = value

#overrides get(), allows for export var groups and display properties that don't
#match actual var names
func _get(property):
pass
# match property:
match property:
"advanced/network_sync":
return network_sync

#overrides get_property_list(), tells editor to show more vars in inspector
func _get_property_list():
#if not Engine.editor_hint:
# return []
var property_list: Array = []
property_list.append({"name": "advanced/network_sync",
"type": TYPE_BOOL,
"usage": PROPERTY_USAGE_DEFAULT,
"hint": PROPERTY_HINT_NONE,
})
return property_list
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ interact_with = NodePath("")
interact_data = {

}
advanced/network_sync = false
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ extends Resource

export(String) var task_text

#export(Resource) var ui_name = base_ui_resource.duplicate()

var item_inputs_on: bool
var item_inputs: PoolStringArray

Expand All @@ -29,40 +27,90 @@ var ui_res: Resource = base_ui_resource.duplicate()
#node this task is attached to
var attached_to: Node

#assigned by TaskManager
#assigned at runtime when registered by TaskManager
var task_id: int
var task_data: Dictionary = {}

var task_registered: bool = false

func complete_task(data: Dictionary = {}) -> bool:
var temp_interact_data = task_data
for key in data.keys():
temp_interact_data[key] = data[key]
if map_outputs_on:
for resource in map_outputs:
resource.interact(attached_to, temp_interact_data)
return true

func assign_player(player_id: int):
if not task_data.keys().has("assigned_players"):
task_data["assigned_players"] = []
if task_data["assigned_players"].has(player_id):
return
task_data["assigned_players"].append(player_id)

func registered(new_id: int, new_task_data: Dictionary):
task_id = new_id
for key in new_task_data.keys():
task_data[key] = new_task_data[key]
task_registered = true

func get_task_data() -> Dictionary:
var temp_task_data = task_data
temp_task_data["task_id"] = task_id
if task_registered:
return temp_task_data
var generated_task_data = gen_task_data()
for key in generated_task_data.keys():
temp_task_data[key] = generated_task_data[key]
return temp_task_data

# generate initial data to send to the task manager, should not be called after it is registered
func gen_task_data() -> Dictionary:
if task_registered:
return task_data
var info: Dictionary = {}
info["task_text"] = task_text
# info["item_inputs"] = item_inputs
# info["item_outputs"] = item_outputs
info["task_outputs"] = task_outputs
info["attached_node"] = attached_to
info["resource"] = self
#info["ui_resource"] = ui_res
for key in info.keys():
task_data[key] = info[key]
return info

func get_task_id() -> int:
return task_id

func get_task_state() -> int:
return task_data["state"]

func set_task_state(new_state: int) -> bool:
task_data["state"] = new_state
return true

func interact(_from: Node = null, _interact_data: Dictionary = {}):
if attached_to == null and _from != null:
attached_to = _from
if attached_to == null:
push_error("InteractTask resource trying to be used with no defined node")
ui_res.interact(_from)
ui_res.interact(_from, get_task_data())

func init_resource(_from: Node):
if attached_to == null and _from != null:
attached_to = _from
if attached_to == null:
push_error("InteractTask resource trying to be initiated with no defined node")
task_id = TaskManager.register_task(gen_task_info())
task_id = TaskManager.register_task(self)

func get_interact_data(_from: Node = null) -> Dictionary:
if attached_to == null and _from != null:
attached_to = _from
if attached_to == null:
push_error("InteractTask resource trying to be used with no defined node")
return gen_task_info()

func gen_task_info() -> Dictionary:
var info: Dictionary = {}
info["task_text"] = task_text
info["item_inputs"] = item_inputs
info["item_outputs"] = item_outputs
info["task_outputs"] = task_outputs
info["attached_node"] = attached_to
info["task_resource"] = self
#info["ui_resource"] = ui_res
return info
return gen_task_data()

func _init():
#print("task init ", task_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
resource_local_to_scene = true
resource_name = "InteractUI"
script = ExtResource( 2 )
ui_name = "clockset"
ui_name = ""
ui_data = {

}
Expand Down
21 changes: 15 additions & 6 deletions src/assets/autoload/gamemanager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ const TRANSITIONS = {
State.Normal: [State.Lobby, State.Start],
}

var priority_amount: int = 6

#signals that help sync the gamestate
#can be connected to from anywhere with GameManager.connect("<signal name>", self, "<function name>")
signal state_changed
signal state_changed(old_state, new_state)
signal state_changed_priority(old_state, new_state, priority)

func _ready():
set_network_master(1)
Expand All @@ -20,32 +23,38 @@ func _ready():
# warning-ignore:return_value_discarded
Network.connect("server_started", self, "_on_connected")

func transition(new_state) -> bool:
func transition(new_state: int) -> bool:
print("attempting to transition gamestate from ", state, " to ", new_state)
if (TRANSITIONS[state].has(new_state)):
var old_state: int = state
state = new_state
if get_tree().is_network_server():
rpc("receiveTransition", new_state)
emit_signal('state_changed', old_state, new_state)
rpc("receive_transition", new_state)
emit_state_changed_signals(old_state, new_state)
print("transition successful")
return true
print("transition failed")
return false

puppet func receiveTransition(new_state):
puppet func receive_transition(new_state: int):
if get_tree().is_network_server():
return
print("attempting to transition gamestate from ", state, " to ", new_state)
if (TRANSITIONS[state].has(new_state)):
var old_state: int = state
state = new_state
emit_signal('state_changed', old_state, new_state)
emit_state_changed_signals(old_state, new_state)
print("transition successful")
return# true
print("transition failed")
return# false

func emit_state_changed_signals(old_state: int, new_state: int):
# emit state_changed_priority, priority starts at 0
for priority in priority_amount:
emit_signal("state_changed_priority", old_state, new_state, priority)
emit_signal('state_changed', old_state, new_state)

func get_state() -> int:
return state

Expand Down
Loading

0 comments on commit 854cf9b

Please sign in to comment.