Upgraded sl command + added commands reloading
This commit is contained in:
parent
357792ec7d
commit
0df2efffbf
3 changed files with 117 additions and 17 deletions
|
|
@ -1,17 +1,29 @@
|
||||||
import Command from "./command.js";
|
import Command from "./command.js";
|
||||||
|
|
||||||
// Dynamically import commands
|
let commands = [];
|
||||||
const context = require.context("./commands", false, /\.js$/);
|
|
||||||
const commands = [];
|
/**
|
||||||
context.keys().forEach((key) => {
|
* Dynamically import commands
|
||||||
const commandModule = context(key);
|
*/
|
||||||
const commandName = Object.keys(commandModule)[0];
|
const loadCommands = () => {
|
||||||
const command = commandModule[commandName];
|
commands = [];
|
||||||
command.setName(commandName.toLowerCase());
|
const context = require.context("./commands", false, /\.js$/);
|
||||||
commands.push(command);
|
context.keys().forEach((key) => {
|
||||||
});
|
const commandModule = context(key);
|
||||||
|
const commandName = Object.keys(commandModule)[0];
|
||||||
|
|
||||||
|
const command = commandModule[commandName];
|
||||||
|
command.setName(commandName.toLowerCase());
|
||||||
|
|
||||||
|
commands.push(command);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
loadCommands();
|
||||||
|
|
||||||
export default class CommandsManager {
|
export default class CommandsManager {
|
||||||
|
static COMMANDS = commands;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} name
|
* @param {string} name
|
||||||
* @returns {Command}
|
* @returns {Command}
|
||||||
|
|
@ -38,5 +50,8 @@ export default class CommandsManager {
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
static COMMANDS = commands;
|
static reload() {
|
||||||
|
loadCommands();
|
||||||
|
CommandsManager.COMMANDS = commands;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
13
src/features/apps/terminal/commands/reload.js
Normal file
13
src/features/apps/terminal/commands/reload.js
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
import Command from "../command.js";
|
||||||
|
import CommandsManager from "../commands.js";
|
||||||
|
|
||||||
|
export const reload = new Command()
|
||||||
|
.setManual({
|
||||||
|
purpose: "Reload terminal commands",
|
||||||
|
usage: "reload",
|
||||||
|
})
|
||||||
|
.setExecute(() => {
|
||||||
|
CommandsManager.reload();
|
||||||
|
|
||||||
|
return { blank: true };
|
||||||
|
});
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import Command from "../command.js";
|
import Command from "../command.js";
|
||||||
import Stream from "../stream.js";
|
import Stream from "../stream.js";
|
||||||
|
|
||||||
|
const ANIMATION_SPEED = 1.25;
|
||||||
|
|
||||||
const LOCOMOTIVE_SMOKE = [
|
const LOCOMOTIVE_SMOKE = [
|
||||||
[
|
[
|
||||||
" (@@) ( ) (@) ( ) @@ () @ o @ o",
|
" (@@) ( ) (@) ( ) @@ () @ o @ o",
|
||||||
|
|
@ -63,7 +65,8 @@ const LOCOMOTIVE_BOTTOM = [
|
||||||
]
|
]
|
||||||
].reverse();
|
].reverse();
|
||||||
|
|
||||||
const WAGON = [
|
const COAL_WAGON = [
|
||||||
|
" ",
|
||||||
" _________________ ",
|
" _________________ ",
|
||||||
" _| \\_____A ",
|
" _| \\_____A ",
|
||||||
" =| | ",
|
" =| | ",
|
||||||
|
|
@ -74,21 +77,85 @@ const WAGON = [
|
||||||
" \\_/ \\_/ \\_/ \\_/ ",
|
" \\_/ \\_/ \\_/ \\_/ ",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const EXTRA_WAGONS = [
|
||||||
|
[
|
||||||
|
" _______================_______ ",
|
||||||
|
" | | ___ ___ ___ ___ | | ",
|
||||||
|
" | | | | | | | | | | | | ",
|
||||||
|
" | | |_| |_| |_| |_| | | ",
|
||||||
|
" | | | | ",
|
||||||
|
"__|__|____________________|__|__",
|
||||||
|
"_|____________________________|_",
|
||||||
|
" |_D__D__D_| |_D__D__D_| ",
|
||||||
|
" \\_/ \\_/ \\_/ \\_/ ",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
" ",
|
||||||
|
" ________========__HH____ ",
|
||||||
|
" / HH \\ ",
|
||||||
|
"/ HH \\ ",
|
||||||
|
"\\ HH / ",
|
||||||
|
"_\\__________________HH____/__",
|
||||||
|
"|__________________________|_",
|
||||||
|
" |_D__D__D_| |_D__D__D_| ",
|
||||||
|
" \\_/ \\_/ \\_/ \\_/ ",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
"_____________________________",
|
||||||
|
"|__________________________|_",
|
||||||
|
" |_D__D__D_| |_D__D__D_| ",
|
||||||
|
" \\_/ \\_/ \\_/ \\_/ ",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
" ",
|
||||||
|
" _|__|___________|__|___ ",
|
||||||
|
" (_|__|___________|__|___) ",
|
||||||
|
" _(|__|___________|__|__)_ ",
|
||||||
|
" (__|__|___________|__|____)",
|
||||||
|
"_(___|__|___________|__|__)__",
|
||||||
|
"|__________________________|_",
|
||||||
|
" |_D__D__D_| |_D__D__D_| ",
|
||||||
|
" \\_/ \\_/ \\_/ \\_/ ",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
" ",
|
||||||
|
" ___________________________ ",
|
||||||
|
" \\ | | / ",
|
||||||
|
" \\ | | / ",
|
||||||
|
" |\\ | | /| ",
|
||||||
|
"__|_\\___|___________|___/_|__",
|
||||||
|
"|__________________________|_",
|
||||||
|
" |_D__D__D_| |_D__D__D_| ",
|
||||||
|
" \\_/ \\_/ \\_/ \\_/ ",
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
function getLocomotive(frame, wagonCount = 1) {
|
function getLocomotive(frame, wagonCount = 1) {
|
||||||
const smokeHeight = LOCOMOTIVE_SMOKE[0].length;
|
const smokeHeight = LOCOMOTIVE_SMOKE[0].length;
|
||||||
const locomotiveHeight = LOCOMOTIVE_TOP.length + LOCOMOTIVE_BOTTOM[0].length;
|
const locomotiveHeight = LOCOMOTIVE_TOP.length + LOCOMOTIVE_BOTTOM[0].length;
|
||||||
const wagonHeight = WAGON.length;
|
const wagonHeight = COAL_WAGON.length;
|
||||||
|
|
||||||
const wagonStart = smokeHeight + locomotiveHeight - wagonHeight;
|
const wagonStart = smokeHeight + locomotiveHeight - wagonHeight;
|
||||||
|
|
||||||
const smoke = LOCOMOTIVE_SMOKE[Math.round(frame / 6) % LOCOMOTIVE_SMOKE.length];
|
const smoke = LOCOMOTIVE_SMOKE[Math.round(frame / 4) % LOCOMOTIVE_SMOKE.length];
|
||||||
const top = LOCOMOTIVE_TOP;
|
const top = LOCOMOTIVE_TOP;
|
||||||
const bottom = LOCOMOTIVE_BOTTOM[frame % LOCOMOTIVE_BOTTOM.length];
|
const bottom = LOCOMOTIVE_BOTTOM[frame % LOCOMOTIVE_BOTTOM.length];
|
||||||
|
|
||||||
const distance = 50 - frame;
|
const distance = 50 - frame;
|
||||||
const locomotive = smoke.concat(top, bottom).map((line, index) => {
|
const locomotive = smoke.concat(top, bottom).map((line, index) => {
|
||||||
if (index >= wagonStart && wagonCount > 0) {
|
if (index >= wagonStart && wagonCount > 0) {
|
||||||
line += WAGON[index - wagonStart].repeat(wagonCount);
|
for (let i = 0; i < wagonCount; i++) {
|
||||||
|
if (i === 0) {
|
||||||
|
line += COAL_WAGON[index - wagonStart];
|
||||||
|
} else {
|
||||||
|
line += EXTRA_WAGONS[(i - 1) % EXTRA_WAGONS.length][index - wagonStart];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (distance === 0) {
|
if (distance === 0) {
|
||||||
|
|
@ -106,7 +173,12 @@ function getLocomotive(frame, wagonCount = 1) {
|
||||||
|
|
||||||
export const sl = new Command()
|
export const sl = new Command()
|
||||||
.setManual({
|
.setManual({
|
||||||
purpose: "Displays animations aimed to correct users who accidentally enter sl instead of ls. SL stands for Steam Locomotive."
|
purpose: "Displays animations aimed to correct users who accidentally enter sl instead of ls. SL stands for Steam Locomotive.",
|
||||||
|
usage: "sl\n"
|
||||||
|
+ "sl -w [NUMBER]",
|
||||||
|
options: {
|
||||||
|
"-w": "Set the amount of wagons (defaults to 1)"
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.addOption({
|
.addOption({
|
||||||
short: "w",
|
short: "w",
|
||||||
|
|
@ -134,7 +206,7 @@ export const sl = new Command()
|
||||||
|
|
||||||
if (text.trim().length === 0)
|
if (text.trim().length === 0)
|
||||||
stream.stop();
|
stream.stop();
|
||||||
}, 100);
|
}, 100 / ANIMATION_SPEED);
|
||||||
|
|
||||||
stream.on(Stream.EVENT_NAMES.STOP, () => {
|
stream.on(Stream.EVENT_NAMES.STOP, () => {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue