Skip to content

Commit

Permalink
fix dialog answers animation
Browse files Browse the repository at this point in the history
  • Loading branch information
bastienguillon committed Feb 8, 2019
1 parent 55b050a commit 79a8692
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
25 changes: 12 additions & 13 deletions src/messages/dialog_graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,27 @@ export function get_animation(node: IDialogNode): DialogAnimation {
}

export function get_animation_factor(node: IDialogNode): number {
return node.animation != null ? node.animation.factor : 0;
return node.animation != null && node.animation.factor != null ? node.animation.factor : 0;
}

export const sample_dialog = <IDialogNode>{
message: "Shrubberies are my trade. I am a shrubber.",
next_node: <IDialogNode>{
message: "My name is Roger the Shrubber. I arrange, design, and sell shrubberies.",
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 4},
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 4 },
next_node: <IQuestionNode>{
message: "Are you saying Ni to that old woman?",
answers: [
{
message: "Um, yes.",
animation: <IDialogAnimation>{ type: DialogAnimation.None },
animation_factor: 0,
animation: { type: DialogAnimation.None },
next_node: <IDialogNode>{
message: "Oh, what sad times are these when passing ruffians can say Ni at will to old ladies."
}
},
{
message: "Ni!",
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 4},
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 4 },
next_node: <IDialogNode>{
message: "There is a pestilence upon this land, nothing is sacred. Even those who arrange and design shrubberies are under considerable economic stress in this period in history."
}
Expand All @@ -72,28 +71,28 @@ export const angry_dialog = <IDialogNode>{
message: "Hello there! How are you? ^_^",
next_node: <IDialogNode>{
message: "Why don't you answer me...?",
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 2},
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 2 },
next_node: <IDialogNode>{
message: "Please stop ignoring me...",
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 4},
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 4 },
next_node: <IDialogNode>{
message: "Don't you think I've already suffered enough? Do you even know what I've been through until now?",
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 6},
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 6 },
next_node: <IDialogNode>{
message: "Oh sure! Keep not answering! After all, you're smarter than everyone! You're above EVERYTHING",
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 8},
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 8 },
next_node: <IDialogNode>{
message: "HEY, I'M TALKING TO YOU, YOU BRAT",
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 10},
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 10 },
next_node: <IDialogNode>{
message: "I'm so angry that my text starts to shakea bit too much right now...",
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 15},
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 15 },
next_node: <IDialogNode>{
message: "But after all, you're right... In this world. it's kill or to be killed.",
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 20},
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 20 },
next_node: <IDialogNode>{
message: "Anyway, stop playing Cloud at Smash Bros, you fucking noob!",
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 100}
animation: <IDialogAnimation>{ type: DialogAnimation.Shaky, factor: 100 }
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/messages/message_box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Direction } from "../enum";
export class MessageBox {

/** Number of characters per line */
private static readonly _line_width_in_characters = 49;
private static readonly _line_width_in_characters = 48;
/** Bottom margin, so that the text is not stuck to the bottom of the message box */
private static readonly _bottom_margin = 20;
private static readonly DOM_ID = "message-box";
Expand Down Expand Up @@ -178,16 +178,16 @@ export class MessageBox {
for (let character_index = 0; character_index < text.length; ++character_index) {
this._context.fillText(
text[character_index],
this.get_character_x_offset(character_index) + MathUtil.get_random_int(get_animation_factor(this._current_node)),
this.get_character_y_offset(i + 1 + this._current_line_index) + MathUtil.get_random_int(get_animation_factor(this._current_node))
this.get_character_x_offset(character_index) + MathUtil.get_random_int(get_animation_factor(current_choice)),
this.get_character_y_offset(i + 1 + this._current_line_index) + MathUtil.get_random_int(get_animation_factor(current_choice))
);
}
break;
}
}
}

/**
/**
* Prepares the MessageBox to display the given node
*/
private load_node(node: IDialogNode) {
Expand Down

0 comments on commit 79a8692

Please sign in to comment.