Skip to content

Commit

Permalink
Updated commenting + bug fix
Browse files Browse the repository at this point in the history
removed out of date comments

self.current_affect in affecter.py now is initialized to the highest valued affect based on equilibrium points to avoid crashes under certain circumstances
  • Loading branch information
njunius committed May 6, 2022
1 parent ad2e434 commit 2e5ceaa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
11 changes: 3 additions & 8 deletions src/core/action_key_map.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# gesture_interface contains the default keybindings for performing gestures in a dictionary
# action_key_map contains the interface for storing keybindings and performing actions
# the dictionary is modeled on Ren'Py's keymap
# the class also wraps the flags for detecting if an action is being done
#
Expand All @@ -15,17 +15,12 @@ class Action_Key_Map:

def __init__(self, key_map, default_action = 'resting', default_modifier = 'neutral'):

# ALL must have a value corresponding to a key in the actual_action_states dictionary of actions or modifiers
# for the current usage both the current and default actions are initialized to the first value in the actions list
# for the current usage both the current and default modifiers are initialized to the last value in the modifiers list

# this dictionary and values should not be modified ever and are generally for internal use only
self._default_states = {
'actions' : default_action,
'modifiers' : default_modifier
}
# this dictionary and values should only be modified internally and are used to access the current
# state of the actions being performed
# this dictionary and values should only be modified internally and are used to access the current state of the actions being performed
self.current_states = {
'actions' : self._default_states['actions'],
'modifiers' : self._default_states['modifiers']
Expand Down Expand Up @@ -113,7 +108,7 @@ def update_possible_states(self, state_to_update, new_value):
# UPDATING AN ACTION WILL SET ALL OTHER ACTIONS TO FALSE
# UPDATING A MODIFIER WILL SET ALL OTHER MODIFIERS TO FALSE
#
# MODIFERS, ACTIONS, AND CADENCES ARE ASSUMED TO BE MUTUALLY EXCLUSIVE WHEN UPDATING
# MODIFERS AND ACTIONS ARE ASSUMED TO BE MUTUALLY EXCLUSIVE WHEN UPDATING
def update_actual_states(self, state_to_update, class_of_action, new_value):

updatable_states = self.actual_action_states[class_of_action]
Expand Down
18 changes: 13 additions & 5 deletions src/core/affecter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Affecter is a wrapper around a JSON object based dictionary of affects (see contents of the affect_rules directory for formatting details)
#
# By default Affecter clamps the values of an affect vector (dictionaries built using make_affect_vector) in the range of 0.0 to 1.0 and uses theatrical terminology, consistent with
# the default keys in gesture_keys.py inside of the actual_action_states dictionary in the Gesture_Interface class
# the default keys in action_key_map.py inside of the actual_action_states dictionary in the Action_Key_Map class
#
import json
import random
Expand All @@ -21,7 +21,15 @@ def __init__(self, affect_rules_file, affect_floor = 0.0, affect_ceiling = 1.0,
self.floor_value = affect_floor
self.ceil_value = affect_ceiling
self.equilibrium_action = equilibrium_action
self.current_affect = None # changed to None because this value will get updated immediately through the run loop (as long as you call update_affect()
self.current_affect = None

for affect in self.affect_rules:
entry_equilibrium = self.affect_rules[affect]['equilibrium_point']

if not self.current_affect:
self.current_affect = affect
elif entry_equilibrium > self.affect_rules[self.current_affect]['equilibrium_point']:
self.current_affect = affect

# discards the stored affect_rules and replaces it with a new rule_file in the above JSON format
def load_open_rule_file(self, affect_rule_file):
Expand All @@ -35,9 +43,9 @@ def _update_and_clamp_values(self, affect_value, affect_update_value, floor_valu

# affect_vector is a dictionary built using make_affect_vector()
# the floats correspond to the strength of the expressed affect
# current_action corresponds to the standard action expressed by a Gesture_Interface instance in its actual_action_states
# current_action corresponds to the standard action expressed by an Action_Key_Map instance in its actual_action_states
# NOTE: clamps affect values between floor_value and ceil_value
# NOTE: while performing the equilibrium_action the affect values will move toward the equilibrium_value of the given affect_vector
# NOTE: while performing the equilibrium_action the affect values will move toward the equilibrium_value of the Affecter
def update_affect(self, affect_vector, current_action, current_modifier):
for affect in affect_vector:

Expand Down Expand Up @@ -124,7 +132,7 @@ def get_prevailing_affect(self, affect_vector, allowable_error = 0.00000001):


# affect_names takes a list of strings
# equilibrium_values is expected to be the rules stored in the affect_rules dictionary of a Gesture_Affecter
# equilibrium_values is expected to be the rules stored in the affect_rules dictionary of an Affecter
def make_affect_vector(affect_names, equilibrium_values):

affect_vector = {}
Expand Down

0 comments on commit 2e5ceaa

Please sign in to comment.