Last active
August 29, 2015 14:16
-
-
Save G33kDude/062c2d55809f1005421d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#NoEnv ; Don't try to pull variables from the environment (speeds things up) | |
SetBatchLines, -1 ; Don't pause between lines (also speeds things up) | |
Macbeth := Shakespeare.Writeth("Macbeth") | |
MsgBox, % Shakespeare.ReadethPassage(Macbeth.PassageThatContaineth("Eye of newt")) | |
class Shakespeare | |
{ | |
static Phrases := StrSplit("Bated breath,Cold comfort,Devil incarnate," | |
. "Elbow room,Faint hearted,Fancy-free,Flaming youth,Foregone conclusion," | |
. "Full circle,Good riddance,Household words,Improbable fiction,Infinite space," | |
. "Itching palm,Killing frost,Knit brow,Laughing stock,Lie low,Ministering angel," | |
. "Naked truth,Star-crossed lovers,Pitched battle,Primrose path,Salad days," | |
. "Sea change,Send packing,Snail paced,Spotless reputation,Stony hearted," | |
. "Towering passion,Wild-goose chase,Working-day world,Yeoman's service", ",") | |
static FamousPersonVoice := ComObjCreate("SAPI.SPVoice") | |
Writeth(PlayName) | |
{ | |
Pen := FileOpen(PlayName ".txt", "r") | |
return new Play(Pen.Read()) | |
} | |
Speaketh(Text) | |
{ | |
this.FamousPersonVoice.Speak(Text) | |
} | |
SayethSomethingAwesomeeth() | |
{ | |
Random, Rand, 1, this.Phrases.MaxIndex() | |
this.Speaketh(this.Phrases[Rand] "!") | |
} | |
ReadethPassage(Passage) | |
{ | |
Text := "In act " Passage.Scene.Act.Number ",`n" | |
. "in scene " Passage.Scene.Number ", " Passage.Scene.Name ",`n" | |
. "in passage " Passage.Number ",`n" | |
. "with characters " Passage.Play.CharactersInScene(Passage.Scene) ",`n" | |
. "character " Passage.Character " says:`n" | |
. Passage.Text | |
this.Speaketh(Text) | |
return Text | |
} | |
} | |
class Play | |
{ | |
__New(Script) | |
{ | |
this.Acts := [] | |
this.Scenes := [] | |
this.Passages := [] | |
Script := RegExReplace(Script, "\R", "`n") | |
PassageNum := 0 | |
for each, Line in StrSplit(Script, "`n") | |
{ | |
if (InStr(Line, "ACT") == 1) | |
{ | |
Numeral := RTrim(StrSplit(Line, " ")[2], ".") | |
ActNum := NumeralToInt(Numeral) | |
Act := {Play: this, Numeral: Numeral, Number: ActNum, Scenes: []} | |
this.Acts[ActNum] := Act | |
} | |
else if (InStr(Line, "SCENE") == 1) | |
{ | |
Numeral := RTrim(StrSplit(Line, " ")[2], ".") | |
SceneName := Trim(SubStr(Line, InStr(Line, "."))) | |
SceneNum := NumeralToInt(Numeral) | |
Scene := {Play: this, Act: Act, Numeral: Numeral, Number: SceneNum, Name: SceneName, Passages: []} | |
this.Scenes.Insert(Scene) | |
this.Acts[ActNum].Scenes[SceneNum] := Scene | |
PassageNum := 0 | |
} | |
else if (Line ~= "^ \S") | |
{ | |
PassageNum++ | |
Character := RTrim(Trim(Line), ".") | |
Passage := {Play: this, Scene: Scene, Number: PassageNum, Character: Character, Text: ""} | |
this.Passages.Insert(Passage) | |
this.Acts[ActNum].Scenes[SceneNum].Passages[PassageNum] := Passage | |
} | |
else if (Line != "") | |
{ | |
this.Acts[ActNum].Scenes[SceneNum].Passages[PassageNum].Text .= Line "`n" | |
} | |
} | |
} | |
PassageThatContaineth(SubPhrase) | |
{ | |
for each, Passage in this.Passages | |
{ | |
if InStr(Passage.Text, SubPhrase) | |
return Passage | |
} | |
} | |
CharactersInScene(Scene) | |
{ | |
Characters := "" | |
for each, Passage in Scene.Passages | |
Characters .= ", " Passage.Character | |
Sort, Characters, U D`, | |
return SubStr(Characters, 3) | |
} | |
} | |
NumeralToInt(Numeral) | |
{ | |
static Map := {I: 1, II: 2, III: 3, IV: 4, V: 5, VI: 6, VII: 7, VIII: 8, IX: 9, X: 10} | |
return Map[Numeral] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment