// Greeting text functions that can be hooked into your cd function so that moving between folders becomes an experience of the AO import { selectRandom } from './util.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.', ] 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.', ] } export default 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) } } return selectRandom(wanderMessages[direction]) }