Last active
October 26, 2023 16:25
-
-
Save sinistamunkey/4e1750a34965b81a3388a532f6d33da4 to your computer and use it in GitHub Desktop.
Else Heart.Break() tool kit
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
var weather = Connect("MeteorologyServer") | |
var doors = Connect("SteeringComputer") | |
var locator = Connect("MissingPersonFinder") | |
var playstation = Connect("LongsonPlaystation") | |
var extractor = Connect("Extractor") | |
var teleporter = Connect("Teleporter") | |
var hugin = Connect("Hugin") | |
# Unlock() | |
# Lock() | |
# Locate() | |
# SetRain(0) | |
# Move() | |
# Teleport() | |
# | |
# Helper Methods. | |
# | |
void Unlock(string doorName) | |
doors.Unlock(doorName) | |
end | |
void Lock(string doorName) | |
doors.Lock(doorName) | |
end | |
void Locate(string thing) | |
var position = playstation.GetPosition(thing) | |
extractor.CopyToClipboard(position) | |
Print(position) | |
end | |
var Move(string source, string location) | |
playstation.SetPosition(source, location) | |
end | |
void SetRain(number rain) | |
weather.SetRain(rain) | |
end | |
void Teleport(string room, number x, number y) | |
teleporter.SetWorldPosition(room, x ,y) | |
end | |
string Replace(string text, string phrase, string replace) | |
array result = [] | |
array matches = FindInString(text, phrase) | |
loop c in text | |
Append(result, c) | |
end | |
loop match in matches | |
number inc = 0 | |
number replaceLength = Count(replace) | |
number matchLength = Count(Range(match[0], match[1])) | |
if matchLength < replaceLength | |
array temp = [] | |
loop c in replace | |
Append(temp, c) | |
end | |
loop index in Range(match[1] + 1, Count(result) - 1) | |
Append(temp, result[index]) | |
end | |
result = temp | |
else | |
loop index in Range(match[0], match[1]) | |
if inc < replaceLength - 1 | |
result[index] = replace[inc] | |
else | |
Remove(result, index) | |
end | |
end | |
end | |
end | |
return ArrayToString(result) | |
end | |
string ArrayToString(array source) | |
string result | |
loop c in source | |
result += c | |
end | |
return result | |
end | |
array FindInString(string source, string phrase) | |
array rawSource = [] | |
array rawPhrase = [] | |
array matches = [] | |
array possible = [] | |
number currentIndex = 0 | |
number phraseLength = -1 | |
loop c in source | |
Append(rawSource, CharToInt(c)) | |
end | |
loop c in phrase | |
Append(rawPhrase, CharToInt(c)) | |
phraseLength++ | |
end | |
loop c in rawSource | |
if currentIndex > phraseLength | |
break | |
end | |
number endIndex = currentIndex + phraseLength | |
if c == rawPhrase[0] and rawSource[endIndex] == rawPhrase[phraseLength] | |
Append(possible, [currentIndex, endIndex]) | |
end | |
currentIndex++ | |
end | |
# Now verify that our matches are true. | |
loop match in possible | |
bool hasErrors = false | |
number inc = 0 | |
loop index in Range(match[0], match[1]) | |
if rawSource[index] == rawPhrase[inc] | |
inc++ | |
else | |
hasErrors = true | |
inc = 0 | |
end | |
end | |
if !hasErrors | |
Append(matches, match) | |
end | |
end | |
return matches | |
end | |
number CharToInt(string char) | |
return locator.CharToInt(char) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment