Skip to content

Commit fe9307c

Browse files
committed
Refactor
1 parent 68fb1ca commit fe9307c

2 files changed

Lines changed: 131 additions & 105 deletions

File tree

Emotion_Handler.vb

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
''' Current emotion
44
''' </summary>
55
Public CurrentState As EmotionType
6+
''' <summary>
7+
''' Current emotion as STRING
8+
''' </summary>
69
Public CurrentStateStr As String = "Neutral"
710
''' <summary>
811
''' If state has changed mood has changed
@@ -17,17 +20,19 @@
1720
''' </summary>
1821
Private StateDetected As Boolean = False
1922
''' <summary>
20-
''' Intensity of emotion increases if emotional state remains the same
23+
''' Intensity of emotion increases if emotional state remains the same and is reduced if At JOY 3 and state is detected Neutral is reduced
24+
''' Intensity can rise and fall eventually becomming neutral - Even neutrality and indifference can be intesified:
25+
''' Perhaps if neutrality reaches a certain point then BORDEM can SET IN!
2126
''' </summary>
22-
Public CurrentQuotient As Integer = 0
27+
Public CurrentQuotient As Integer = 1
2328
'PROCESS: PRESERVE VARIABLES
2429
'EMOTION
2530
''' <summary>
2631
''' Used to make a Generic Emotional Response
2732
''' </summary>
2833
''' <param name="FoundEmotion">Provided emotion (HAPPY)</param>
2934
''' <returns></returns>
30-
Public Function MakeEmotionalResponse(ByVal FoundEmotion As String) As String
35+
Public Shared Function MakeEmotionalResponse(ByVal FoundEmotion As String) As String
3136
MakeEmotionalResponse = ""
3237
Randomize()
3338
Dim C As Short = Int(Rnd() * 6 + 1)
@@ -70,47 +75,68 @@
7075
MakeEmotionalResponse = "" & LCase(FoundEmotion) & " "
7176
End Select
7277
End Function
73-
78+
''' <summary>
79+
''' Resets Indicator values for determining state change
80+
''' </summary>
7481
Private Sub ResetStateCounters()
7582
'Reset Counters
7683
StateChanged = False
7784
DetectedState = EmotionType.Neutral
7885
StateDetected = False
7986
End Sub
87+
''' <summary>
88+
''' Increases or Decreases current intensity of emotion held
89+
''' </summary>
8090
Private Sub SetCurrentQuotient()
8191
'Check if neutral - Then reduce current Quotient
8292
If Handler.DetectedEmotion = EmotionType.Neutral Then
8393
CurrentQuotient -= 1
8494
If CurrentQuotient = 0 Then
95+
'Reset State
8596
CurrentState = EmotionType.Neutral
97+
CurrentStateStr = "Neutral"
98+
StateChanged = True
8699
Else
87100
End If
88101
End If
89102
End Sub
90-
103+
''' <summary>
104+
''' Shared between functions holding the currently detected emotions and Created intefaces(STATES)
105+
''' </summary>
91106
Private Handler As New EmotionHandler
92-
107+
''' <summary>
108+
''' Determines and sets the current state and intensity of state:
109+
''' The Quotient value can be used to determine how much of a particular emotion is experienced,
110+
''' the value is increased as emotion is repeatly detected.
111+
''' as the conversation returns to neutrality if another emotion is ot detected the Qujotient is decreased
112+
''' At point of 0 intensity the state is returned to Neutral
113+
''' </summary>
114+
''' <param name="UserInput"></param>
93115
Private Sub SetEmotionState(ByRef UserInput As String)
116+
'Reset the indicators for Detected ans State Change
94117
ResetStateCounters()
95118

96119
'Start - Emotion Test
97120
If Handler.DetectEmotion(UserInput) = True Then
98-
121+
'Updates Quotient If No Changes have been Detected +/- (intensity of emotion)
99122
SetCurrentQuotient()
100123

101124
'Get State
102125
DetectedState = Handler.DetectedEmotion
103126
StateDetected = True
127+
104128
'IF State is the same Increase Intensity
105129
If DetectedState = CurrentState Then
106130
CurrentQuotient += 1
131+
'Update State "DATA"
107132
CurrentStateStr = Handler.DetectedEmotionStr
108133
CurrentState = DetectedState
109134
Else
110-
'IF State is the differnt then change
135+
'IF State is the differnt then change (Update State Data)
111136
CurrentStateStr = Handler.DetectedEmotionStr
112137
CurrentState = DetectedState
113138
StateChanged = True
139+
'Reset Intensity
114140
CurrentQuotient = 1
115141
End If
116142
End If
@@ -140,7 +166,7 @@ End Class
140166
''' </summary>
141167
Public Class EmotionHandler
142168

143-
Private iLoadedEmotions As New List(Of Emotion)
169+
Private iLoadedEmotions As New List(Of IEmotion)
144170

145171
Private mDetectedEmotion As EmotionType
146172

@@ -159,7 +185,7 @@ Public Class EmotionHandler
159185

160186
End Property
161187

162-
Public ReadOnly Property LoadedEmotions As List(Of Emotion)
188+
Public ReadOnly Property LoadedEmotions As List(Of IEmotion)
163189
Get
164190
Return iLoadedEmotions
165191
End Get
@@ -169,12 +195,12 @@ Public Class EmotionHandler
169195
iLoadedEmotions = LoadEmotions()
170196
End Sub
171197

172-
Public Sub AddEmotion(ByRef Emo As Emotion)
198+
Public Sub AddEmotion(ByRef Emo As IEmotion)
173199
iLoadedEmotions.Add(Emo)
174200
End Sub
175201

176202
Public Function DetectEmotion(ByRef Userinput As String) As Boolean
177-
For Each emo As Emotion In LoadedEmotions
203+
For Each emo As IEmotion In LoadedEmotions
178204
If emo.Detect(Userinput) = True Then
179205
mDetectedEmotion = emo.Type
180206
mEmotion = emo.Name
@@ -189,8 +215,8 @@ Public Class EmotionHandler
189215
Return False
190216
End Function
191217

192-
Public Function LoadEmotions() As List(Of Emotion)
193-
Dim mLoadedEMOTIONs As New List(Of Emotion) From {
218+
Public Function LoadEmotions() As List(Of IEmotion)
219+
Dim mLoadedEMOTIONs As New List(Of IEmotion) From {
194220
New EmotionAngry,
195221
New EmotionConcerned,
196222
New EmotionCurious,

0 commit comments

Comments
 (0)