Skip to content

krypciak/cc-vim

Repository files navigation

new.mp4

The menu is openable with ; by default
Move through command history with arrows
See alias list

Dependencies

  1. input-api

Realeses

For Developers

Include the mod as a hard dependency in ccmod.json or use:

if (window.vim) {
	... your aliases ...
}

Executing from the CLI

For example:

vim.executeString('title-screen')
vim.executeString('load-preset: 0')

Types

interface Alias {
    origin: string /* namespace */
    name: string /* command name */
    description: string
    command: (...args: string[]) => void /* command to execute */
    condition: /* if the alias appears in the menu, updated every time the menu is shown */
        | 'ingame' /* can only be used in-game */
        | 'global' /* can be used anywhere */
        | 'titlemenu' /* can only be used in the title menu */
        | ((ingame: boolean) => boolean) /* custom function */

    arguments: AliasArguemnt[] /* see below, argument length is not enforced */

    keys: string[] /* what do include in the fuzzy search */
    display: string[] /* what to display */
}
interface AliasArguemnt {
    type: string /* value type, doesnt really do anything, not enforced */
    possibleArguments?: /* possible types, not enforced */
        AliasArguemntEntry[] /* hard-coded values */ | (() => AliasArguemntEntry[]) /* custom function, run every time the possible values list is shown */
    description: string
}
interface AliasArguemntEntry {
    value: string /* what will be passed to the function */

    keys: string[] /* what do include in the fuzzy search */
    display: string[] /* what to display */
}

Examples

Simplest alias

//           namespace  command-name  description       condition function
vim.addAlias('cc-vim', 'reload',      'Reload the game, 'global', () => { window.location.reload() })

Examples with arguments

vim.addAlias(
    'cc-vim',
    'player-move',
    'Move player',
    'ingame',
    (x?: string, y?: string, z?: string) => {
        const pos: Vec3 = ig.game.playerEntity.coll.pos
        ig.game.playerEntity.setPos(
            pos.x + parseInt(x ?? '0'),
            pos.y + parseInt(y ?? '0'), pos.z + parseInt(z ?? '0')
        )
    },
    [
        { type: 'number', description: 'x to add' },
        { type: 'number', description: 'y to add' },
        { type: 'number', description: 'z to add' },
    ]
)
vim.addAlias(
    'cc-vim',
    'load-preset',
    'Load save preset',
    'global',
    (presetId: string) => {
        const id = parseInt(presetId.trim())
        console.log('presetId:', id)
    },
    [{
        type: 'number',
        possibleArguments(): AliasArguemntEntry[] {
            const arr: AliasArguemntEntry[] = []
            for (const i of Object.keys(sc.savePreset.slots)) {
                const slot: sc.SavePresetData = sc.savePreset.slots[parseInt(i)]
                const value = i.toString()
                const keys = [value, slot.title.value, slot.sub.value, slot.path]
                arr.push({ value, keys, display: keys })
            }
            return arr
        },
        description: 'Preset to load',
    }]
)

TypeScript support

npm install --save-dev github:krypciak/cc-vim
import type * as _ from 'cc-vim'

JavaScript support

you dummy learn typescript
the same as typescript just remove the types (thingis behind :)

Contribution

Feel free to pr any aliases you would like to see added

Building

git clone https://github.com/krypciak/cc-vim
cd cc-vim
pnpm install
pnpm run start
# this should return no errors or very few
npx tsc