An interactive command-line interface (CLI) tool to help you install, use, and administer an AO instance.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
5.8 KiB

// Greeting text functions that can be hooked into your cd function so that moving between folders becomes an experience of the AO
import { selectRandom, randomInt } from './util.js'
import { isLoggedIn } from './session.js'
import { getTopPriorityText } from './priority.js'
const stepMessages = [
'You find a door and walk through.',
'You walk over there now.',
'You head over.',
'Walking briskly, you arrive quickly.',
]
const walkMessages = [
'You take a winding path near a river.',
'A few meadows away is the place you are looking for.',
'A deer leads you a few galleries away to where you were going.',
'You thank the path for taking you to your destination.',
'You make the journey.',
'After some time, you arrive.',
'Winding your way through the trees, you find your way there.',
]
const wanderMessages = {
up: [
'You crane your head upwards to get a better view.',
'You lean back to try and get a better vantage point.',
'You stand on your toes to see above the underbrush.',
'You pull yourself up to a nearby branch.',
'You climb up into the branches to get an overview.',
'After traveling up a slight incline, you realize you are higher than you were before.',
'You climb up onto a boulder so you can see futher around you.',
'You send your trained falcon on ahead to get an aerial view.',
'A rope ladder here leads up to a cozy treehouse with a window you can look out from.',
'Agily climbing the boulders next to a small waterfall, you can see the pool below.',
'A trapdoor? Here? You climb right up through it, pulling yourself up on your forearms.',
'A small trampoline allows you to reach the next platform.',
],
home: [
'You are weary from your journey. You return home.',
'You head home.',
'You return home.',
'Time to go home.',
'Your journey eventually takes you, once again, back to your home.',
'You return to your origin tree.',
'You fall asleep and when you wake up, you are home again. Was it all a dream?',
'Home, sweet, home.',
'There\'s no place like home!',
'You head to the heart of the forest, where you have built a glowing shrine.',
],
root: [
'You are weary of this world. You head up the Mountain, up where the air is thin, to the very acme of creation!',
'On your many long journeys you sometimes find occasion to return to the Headwaters.',
'Deep under the World-Tree lies the root of all things.',
'You take out your compass and it spins wildly. You are at the Center.',
'A large bird swoops down and takes you high into the sky,',
'A rather ungainly solar-powered dirigible carries you safely into the heavens.',
'Without further ado, you ascend.',
'Returning to the center once again, you feel your memories bend around you.',
],
0: [
'Wherever you go, there you are.',
'You\'re going nowhere.',
'You\'re already here.',
],
1: stepMessages,
2: stepMessages,
3: stepMessages,
4: walkMessages,
5: [
'You teleport.',
'You fold space and arrive there in the blink of an eye.',
'You wrinkle time and arrive there in two shakes of a cat\'s tail.',
'You perform a basic transit spell to take you to your destination.',
'Turning your mind inside out, you transmigrate zones.',
'You bilocate and, when the confusion clears, there you are.',
'Wandering for a way, you stop in a glade for lunch. Alighting, you walk onwards, and soon you arrive.',
'It\'s a long journey, but you make it there in one piece.',
'You\'re used to traveling anywhere in these woods very quickly.',
'Donning your seven-league boots, you make it there in a single bound.'
]
}
const priorityMessages = [
'You suddenly recall your top priority, to %s.',
'"Oh! I almost forgot!" you think to yourself, "I need to %s!"',
'You are suddenly reminded of your top priority, to %s.',
'For some reason, the scenery reminds you of your top priority, to %s.',
'You feel an urgent need to accomplish your next goal, to %s.',
'From deep within a surge of motivation replenishes you. You remember your task, to %s.',
'You draw upon your inner well of stillness and remember the task at hand, to %s.',
'This brings you one step closer to accomplishing your goal, to %s.'
]
export default async function wander(direction) {
direction = !!direction ? direction.trim() : 'home'
switch(direction) {
case '..':
direction = 'up'
break
case '':
case '~':
case process.env.HOME:
case 'home':
direction = 'home'
break
case '/':
direction = 'root'
break
default:
// To find the jump-distance, add the slashes in the old and new paths, then subtract the number of filenames/folder names they share × 2
// This rewards making further jumps with cd with a cooler flavor text message, encouraging diligence and direct transit.
if(direction && direction.length >= 1) {
const findSlashes = /\//g
const slashesInOldPwd = process.env.OLDPWD.match(findSlashes)?.length
const slashesInNewPwd = process.env.PWD.match(findSlashes)?.length
const sharedWordsCount = process.env.OLDPWD.split('/').filter(word => word != '' && process.env.PWD.split('/').includes(word)).length
let totalSlashes = slashesInOldPwd + slashesInNewPwd - (sharedWordsCount * 2)
if(totalSlashes < 0) totalSlashes = 0
direction = Math.min(parseInt(totalSlashes), 5)
}
}
let narration = selectRandom(wanderMessages[direction])
// Remind them of their top priority sometimes
if(randomInt(0, 4) === 4 && isLoggedIn()) {
const priority = await getTopPriorityText()
if(priority !== 'Not logged in.') {
const madLibs = selectRandom(priorityMessages).replace(/%s/, priority)
narration += ' ' + madLibs
}
}
return narration
}