Skip to content

Instantly share code, notes, and snippets.

@IntegerMan
Last active February 8, 2020 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IntegerMan/15f7eb797fe6d0b25b0eec44e042e81c to your computer and use it in GitHub Desktop.
Save IntegerMan/15f7eb797fe6d0b25b0eec44e042e81c to your computer and use it in GitHub Desktop.
import {EventEmitter, Injectable} from '@angular/core';
import {StoryEntry} from '../Model/StoryEntry';
import {StoryEntryType} from '../Model/StoryEntryType';
@Injectable({
providedIn: 'root'
})
export class StoryService {
public EntryAdded: EventEmitter<StoryEntry> = new EventEmitter<StoryEntry>();
constructor() { }
public handlePlayerInput(text: string): void {
// Log it if the console is available (won't be in all browsers)
if (console && console.log) {
console.log(`Command entered: ${text}`);
}
// Emit an event containing the player's command so we have a log of it in the UI
this.EntryAdded.emit(new StoryEntry(StoryEntryType.PlayerCommand, text));
// Add a generic response since we're not actually parsing or responding to input yet
this.EntryAdded.emit(new StoryEntry(StoryEntryType.SystemText, 'I don\'t understand.')); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment