Skip to content

Commit

Permalink
generate chat scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cheryllium committed Jan 4, 2024
1 parent 0dc46e8 commit 0836656
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 8 deletions.
Binary file added assets/emotes/boo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/emotes/grumpy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/emotes/laugh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/emotes/sad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/emotes/smile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/emotes/surprised.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/emotes/wave.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/emotes/yelling.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/speech-bubbles.aseprite
Binary file not shown.
1 change: 0 additions & 1 deletion ideas.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@ A: grumpy
B: grumpy
- If it goes down the negative branch, set both fish moods to unhappy.
- If it goes down the positive branch, set both fish moods to happy.

2 changes: 2 additions & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export default class ActionManager {
case 'flip':
fish.flipOverride = action.value;
break;
case 'mood':
fish.updateMood(action.value, true);
}
}

Expand Down
138 changes: 138 additions & 0 deletions src/chats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
let pleasantChat = {
description: "FISH1 and FISH2 are having a nice chat.",
start: ['wave', 'wave', 'smile'],
positive: ['smile', 'happy', 'heart', 'A-happy', 'B-happy'],
negative: ['angry', 'surprised', 'grumpy', 'A-unhappy'],
isPositive: function (fish1, fish2) {
return Math.random() < 0.8;
},
};
let prankChat = {
description: "FISH1 is playing a prank on FISH2!",
start: ['boo', 'shocked', 'laugh'],
positive: ['laugh', 'heart', 'heart', 'A-happy', 'B-happy'],
negative: ['angry', 'surprised', 'grumpy', 'B-unhappy'],
isPositive: function (fish1, fish2) {
if (!fish2.goodMood) {
return Math.random() < 0.3;
}
return Math.random() < 0.6;
},
};
let cheerUpChat = {
description: "FISH1 is trying to cheer FISH2 up.",
start: ['smile', 'grumpy', 'heart'],
positive: ['heart', 'happy', 'smile', 'B-happy'],
negative: ['angry', 'surprised', 'grumpy'],
isPositive: function (fish1, fish2) {
return Math.random() < 0.7;
},
};
let argumentChat = {
description: "FISH1 and FISH2 are arguing about something...",
start: ['yelling', 'angry', 'angry'],
positive: ['sad', 'heart', 'heart', 'A-happy', 'B-happy'],
negative: ['yelling', 'grumpy', 'grumpy', 'A-unhappy', 'B-unhappy'],
isPositive: function (fish1, fish2) {
if (!fish1.goodMood && !fish2.goodMood) {
return false;
}
if (fish1.goodMood && fish2.goodMood) {
return Math.random() < 0.5;
}
return Math.random() < 0.3;
}
};

export default function generateChatScripts(fish1, fish2) {
console.log(`${fish1.name} is feeling ${fish1.mood}`);
console.log(`${fish2.name} is feeling ${fish2.mood}`);

// Choose which chat the fish will have
let chat = null;
let chance = Math.random();
if (fish1.goodMood && fish2.goodMood) {
// Both fish are in a good mood
if (chance < 0.6) {
chat = pleasantChat;
} else if (chance < 0.9) {
chat = prankChat;
} else {
chat = argumentChat;
}
} else if (fish1.goodMood && !fish2.goodMood) {
// Only first fish is in a good mood
if (chance < 0.7) {
chat = cheerUpChat;
} else if (chance < 0.8) {
chat = pleasantChat;
} else if (chance < 0.9) {
chat = argumentChat;
} else {
chat = prankChat;
}
} else if (!fish1.goodMood && !fish2.goodMood) {
// Both fish are in a bad mood
if (chance < 0.8) {
chat = argumentChat;
} else if (chance < 0.9) {
chat = prankChat;
} else {
chat = pleasantChat;
}
} else {
// Only second fish is in a good mood
if (chance < 0.5) {
chat = argumentChat;
} else if (chance < 0.9) {
chat = pleasantChat;
} else {
chat = prankChat;
}
}

// Determine whether the chat is positive or negative
let isPositive = chat.isPositive(fish1, fish2);

// Concatenate the script cues
let cues = chat.start;
if (isPositive) {
cues = cues.concat(chat.positive);
} else {
cues = cues.concat(chat.negative);
}

// Construct the two actual scripts
let scriptA = [];
let scriptB = [];
let flagA = true;
for(let cue of cues) {
let action = {};
if (cue.includes("-")) {
action.type = "mood";
action.value = cue.includes("-happy");
action.duration = 0;
if (cue.includes("A-")) {
scriptA.push(action);
} else {
scriptB.push(action);
}
} else {
action.type = "emote";
action.value = cue;
action.duration = 3000;
if (flagA) {
scriptA.push(action);
} else {
scriptB.push(action);
}
flagA = !flagA;
}
}

return {
record: chat.description,
scriptA,
scriptB,
};
}
18 changes: 17 additions & 1 deletion src/fish.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export default class Fish {
this.selected = false;

// Personal information about this fish
this.name = randomFishName();
this.name = randomFishName();
this.updateMood(Math.random() > 0.5);
}

setRandomVelocity() {
Expand Down Expand Up @@ -230,4 +231,19 @@ export default class Fish {
this.action = false;
this.flipOverride = null;
}

updateMood (goodMood, addRecord) {
let goodMoods = ["cheerful", "jovial", "happy", "great"];
let badMoods = ["grumpy", "upset", "moody", "down"];
this.goodMood = goodMood;
if (goodMood) {
this.mood = goodMoods[randomIntFromInterval(0, goodMoods.length-1)];
} else {
this.mood = badMoods[randomIntFromInterval(0, badMoods.length-1)];
}

if (addRecord) {
uiManager.addRecord(`FISH1 is feeling ${this.mood}.`, this);
}
}
}
7 changes: 7 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ window.emoteImages = {
happy: null,
sleepy: null,
angry: null,
grumpy: null,
wave: null,
smile: null,
surprised: null,
yelling: null,
boo: null,
sad: null,
};
window.foodImages = {
broccoli: null,
Expand Down
8 changes: 5 additions & 3 deletions src/routines.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { states as fishStates } from './fish.js';
import generateChatScripts from './chats.js';

export const SCRIPTS = {
happy: [
{ type: 'emote', value: 'happy', duration: 3000 }, // Set emote to happy, wait 3s
{ type: 'emote', value: null, duration: 1000 }, // Set emote to nothing, wait 3s
{ type: 'state', value: fishStates.IDLING, duration: 1000 }, // Set state to idling
{ type: 'state', value: fishStates.BOIDING, duration: 0 }, // Set state to boiding, go to next action
{ type: 'emote', value: 'heart', duration: 3000 }, // Set emote to heart, wait 3s
{ type: 'mood', value: true, duration: 0}, // Set mood to happy
],
moveToCorner: [
{ type: 'state', value: fishStates.MOVING, duration: 4000, moveto: {x: 500, y: 500} },
Expand Down Expand Up @@ -119,6 +119,8 @@ export default class RoutineManager {
indexB = randomIntFromInterval(0, filteredFish.length-1);
} while (indexB == indexA);

console.log(generateChatScripts(filteredFish[indexA], filteredFish[indexB]));

// Choose two random conversation scripts
let scriptA = JSON.parse(JSON.stringify(SCRIPTS.chat1[0]));
let scriptB = JSON.parse(JSON.stringify(SCRIPTS.chat1[1]));
Expand Down Expand Up @@ -149,7 +151,7 @@ export default class RoutineManager {
);

// Add record
uiManager.addRecord(`FISH1 and FISH2 are having a nice chat!`, filteredFish[indexA], filteredFish[indexB]);
uiManager.addRecord("FISH1 and FISH2 are having a nice chat!", filteredFish[indexA], filteredFish[indexB]);
});
}
}
6 changes: 3 additions & 3 deletions src/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ export default class UIManager {
fishImage.src = `assets/fish/fish${fish.type}.png`;

// Create paragraphs for the name and personality
let nameParagraph = document.createElement("p");
nameParagraph.innerHTML = `<b>Name: </b>${fish.name}`;
let fishInfo = document.createElement("div");
fishInfo.innerHTML = `<b>Name: </b>${fish.name}<br><b>Mood: </b>${fish.mood}`;

fishDiv.appendChild(fishImage);
fishDiv.appendChild(nameParagraph);
fishDiv.appendChild(fishInfo);

// Add it to the selected fish div
selectedFishDiv.appendChild(fishDiv);
Expand Down

0 comments on commit 0836656

Please sign in to comment.