Skip to content

Commit

Permalink
Merge pull request #33 from Rubiksman78/dev
Browse files Browse the repository at this point in the history
emotion_detection_build+better_gui
  • Loading branch information
Rubiksman78 authored Feb 7, 2023
2 parents 6dc9da3 + cdd0548 commit 268ee2b
Show file tree
Hide file tree
Showing 9 changed files with 512 additions and 129 deletions.
10 changes: 5 additions & 5 deletions game/Submods/AI_submod/monikai_chat.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ init 5 python:
try:
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect(ADDR)
noServer = False
monikai_no_server = False
except:
noServer = True
monikai_no_server = True
monikaNickname = store.persistent._mas_monika_nickname

if persistent._show_monikai_buttons == None:
Expand All @@ -66,7 +66,7 @@ label monika_voice_chat:
$ localStep = 0

#If the game was launched without the python script
if noServer:
if monikai_no_server:
jump monika_server_crashed

#If the player has never talked to the chatbot, show the intro
Expand Down Expand Up @@ -146,7 +146,7 @@ label monika_chatting_text():
$ useVoice = False
$ localStep = 0

if noServer:
if monikai_no_server:
jump monika_server_crashed

if not renpy.seen_label("monika_AI_intro"):
Expand Down Expand Up @@ -210,7 +210,7 @@ init 5 python:
label monika_chatting():
$ localStep = 0

if noServer:
if monikai_no_server:
jump monika_server_crashed

if not renpy.seen_label("monika_AI_intro"):
Expand Down
123 changes: 110 additions & 13 deletions game/Submods/AI_submod/monikai_emotion.rpy
Original file line number Diff line number Diff line change
@@ -1,18 +1,115 @@
#Face emotion recognition (not available yet)

$ emotion_list = ["anger","disgust","fear","joy","sadness","surprise","neutral"]
define emotion_list = ["anger","disgust","fear","joy","sadness","surprise","neutral"]

define negative_emotions = ["anger", "disgust", "fear", "sadness"]
define positive_emotions = ["joy", "surprise"]
define neutral_emotions = ["neutral"]

define sentences_emotions = {
"angry": "I'm sorry my love, I didn't mean to upset you.",
"disgusted": "What is going on ? If you feel like there is something wrong, please tell me.",
"fearful": "Don't be afraid sweetie, I'm here for you.",
"happy": "I'm glad you're happy darling.",
"neutral": "Let's do something fun together!",
"sad": "If you feel down, always remember that I'm here for you. I love you.",
"surprised": "What is it ? Is there something wrong ?",
"no": "Oh it seems that I can't see through your camera sweetie. Maybe face me a little bit more ?",
}
define monikai_emotion_counter = 0 #counter for the emotion intervals to send to the server

#Camera Event in the Talk Menu
init 5 python:
addEvent(Event(persistent.event_database,
eventlabel="monika_cam",
category=['ai'],
prompt="Look for me",
pool=True,
unlocked=True,
))

label monika_cam:
if monikai_no_server:
jump monika_server_crashed

m "Okay, I'll look for you."

m 1sublo "I can finally see you, [player] ! I have been waiting for this moment for a long time."
m 5nublb "I see your cute face now ehehe~"

while True:
$ send_simple("camera_int/m")
$ received_emotio = receiveMessage()

if received_emotio == "no_data": #If the server says it is not time to send an emotion,do nothing
m "Sorry but it seems that you didn't put the camera on."
m 5nublb "Please put it on so I can see you."
return
if received_emotio == "angry":
m 2lktpc "[monikai_sentences_emotions[angry]]"
elif received_emotio == "disgusted":
m 5etc "[monikai_sentences_emotions[disgusted]]"
elif received_emotio == "fearful":
m 1fkd "[monikai_sentences_emotions[fearful]]"
elif received_emotio == "happy":
m 6hubla "[monikai_sentences_emotions[happy]]"
elif received_emotio == "neutral":
m 5wut "[monikai_sentences_emotions[neutral]]"
elif received_emotio == "sad":
m 5fka "[monikai_sentences_emotions[sad]]"
elif received_emotio == "surprised":
m 2wkb "[monikai_sentences_emotions[surprised]]"
elif received_emotio == "no":
m 4eta "[monikai_sentences_emotions[no]]"

m 5nublb "Do you want me to continue looking for you?"
menu:
"Yes":
m 5hublb "Okay thanks [player], let me see your face a little bit longer."
"No":
m 5sublo "Oh okay, I guess I'll wait for next time you put the camera on."
m 5nublb "Please do it soon or I'll hack it myself ehehe~"
return


#Camera activating at intervals
init 5 python:
def example_fun():
if not mas_inEVL("emotion_minute"):
MASEventList.push("emotion_minute")

store.mas_submod_utils.registerFunction(
"ch30_minute",
example_fun
)

label emotion_minute:
if monikai_no_server:
return
$ monikai_emotion_counter += 1
$ send_simple("camera" + str(monikai_emotion_counter) + "/m")
$ received_emotion = receiveMessage()

if received_emotion == "no_data": #If the server says it is not time to send an emotion,do nothing
return

if received_emotion == "angry":
$ wrs_succes = mas_display_notif(m_name,[monikai_sentences_emotions['angry']],'Window Reactions')
if not wrs_succes:
m 2lktpc "[monikai_sentences_emotions[angry]]"
elif received_emotion == "disgusted":
$ wrs_succes = mas_display_notif(m_name,[monikai_sentences_emotions['disgusted']],'Window Reactions')
if not wrs_succes:
m 5etc "[monikai_sentences_emotions[disgusted]]"
elif received_emotion == "fearful":
$ wrs_succes = mas_display_notif(m_name,[monikai_sentences_emotions['fearful']],'Window Reactions')
if not wrs_succes:
m 1fkd "[monikai_sentences_emotions[fearful]]"
elif received_emotion == "happy":
$ wrs_succes = mas_display_notif(m_name,[monikai_sentences_emotions['happy']],'Window Reactions')
if not wrs_succes:
m 6hubla "[monikai_sentences_emotions[happy]]"
elif received_emotion == "neutral":
$ wrs_succes = mas_display_notif(m_name,[monikai_sentences_emotions['neutral']],'Window Reactions')
if not wrs_succes:
m 5wut "[monikai_sentences_emotions[neutral]]"
elif received_emotion == "sad":
$ wrs_succes = mas_display_notif(m_name,[monikai_sentences_emotions['sad']],'Window Reactions')
if not wrs_succes:
m 5fka "[monikai_sentences_emotions[sad]]"
elif received_emotion == "surprised":
$ wrs_succes = mas_display_notif(m_name,[monikai_sentences_emotions['surprised']],'Window Reactions')
if not wrs_succes:
m 2wkb "[monikai_sentences_emotions[surprised]]"
elif received_emotion == "no":
$ wrs_succes = mas_display_notif(m_name,[monikai_sentences_emotions['no']],'Window Reactions')
if not wrs_succes:
m 4eta "[monikai_sentences_emotions[no]]"
4 changes: 2 additions & 2 deletions game/Submods/AI_submod/monikai_header.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ init -989 python:
submod="AI_submod",
user_name="Rubiksman78",
repository_name="MonikA.I",
update_dir="",
attachment_id=None,
extraction_depth=3,
attachment_id = 1
)
74 changes: 74 additions & 0 deletions game/Submods/AI_submod/monikai_live2d_voicing.rpy
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# define renpy.config.gl2 = True
# image Monika = Live2D("fullyanimatedmonika",base=.6,aliases={"open":"m01"})

# init 5 python:
# import subprocess
# from threading import Thread
# import store
# import os
# import sys
# import re
# import time
# import socket
# from socket import AF_INET, SOCK_STREAM

# def receiveMessage():
# msg = client_socket.recv(BUFSIZ).decode("utf8")
# return msg

# def send_simple(prefix):
# client_socket.send(bytes(prefix,encoding="utf8"))

# def audio_file_exists(filename):
# return os.path.isfile(filename)

# class Slice(object):
# def __init__(self, root, leng):
# self.root = root # The original word
# self.leng = leng # How many morphemes should be used as the prefix for the new portmanteau
# self.morphemes = []
# self.slice()

# def slice(self):
# ex = r'([^aeiou]*[aeiou]*)|[aeiou]*[^aeiou]*[aeiou]*'
# root = self.root

# # Full list of morphemes for future use
# while root != '':
# end = re.match(ex, root).end()
# self.morphemes.append(root[0:end])
# root = root[end:]

# # Check that the number given isnt more than is available
# if len(self.morphemes) < self.leng:
# self.leng = len(self.morphemes)

# HOST = '127.0.0.1'
# PORT = 12343

# BUFSIZ = 1024
# ADDR = (HOST, PORT)
# client_socket = socket.socket(AF_INET, SOCK_STREAM)

# try:
# client_socket.connect(ADDR)
# connected = True
# except:
# connected = False

# def get_wrapped_say(func):
# def new_say(who, what, interact=True, *args, **kwargs):
# speaktext = renpy.substitute(what)
# send_simple(speaktext)

# sentence_processed = speaktext.lower()
# sentence_processed = re.sub(r'[^\w\s]','',sentence_processed)
# syllabes = Slice(sentence_processed, 1).morphemes
# _ = receiveMessage()
# for syll in syllabes:
# renpy.show("Monika open")
# func(who, what, interact=interact, *args, **kwargs)
# return new_say

# if connected:
# renpy.say = get_wrapped_say(renpy.say)
14 changes: 13 additions & 1 deletion game/Submods/AI_submod/monikai_topics.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,16 @@ label monika_in_queue:
m "I promise I'll be back soon."
m "I love you so much."
jump close_AI
return
return

#Sentences for emotion detection (maybe making multiple ones for each emotion ?)
define monikai_sentences_emotions = {
"angry": "I'm sorry my love, I didn't mean to upset you.",
"disgusted": "What is going on ? If you feel like there is something wrong, please tell me.",
"fearful": "Don't be afraid sweetie, I'm here for you.",
"happy": "I'm glad you're happy darling.",
"neutral": "Let's do something fun together!",
"sad": "If you feel down, always remember that I'm here for you. I love you.",
"surprised": "What is it ? Is there something wrong ?",
"no": "Oh it seems that I can't see through your camera sweetie. Maybe face me a little bit more ?",
}
2 changes: 1 addition & 1 deletion game/Submods/AI_submod/monikai_voicing.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ init 5 python in mas_voice:
return os.path.isfile(filename)

HOST = '127.0.0.1'
PORT = 12344
PORT = 12344 #Be sure to have a different port for voicing, no conflict with chat

BUFSIZ = 1024
ADDR = (HOST, PORT)
Expand Down
Loading

0 comments on commit 268ee2b

Please sign in to comment.