本文整理汇总了TypeScript中@csegames/camelot-unchained.hasClientAPI函数的典型用法代码示例。如果您正苦于以下问题:TypeScript hasClientAPI函数的具体用法?TypeScript hasClientAPI怎么用?TypeScript hasClientAPI使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hasClientAPI函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: slash
export function slash(command: string, callback?: (response: any) => void) {
if (hasClientAPI()) {
// If the / command includes a callback, then send the response
// back to the caller
if (callback) listen(callback);
client.SendSlashCommand(command);
} else {
if (callback) callback({ type: 'complete', complete: 'Simulated completion' });
}
}
示例2: listen
export function listen(cb: any) {
if (hasClientAPI()) {
callbacks[++listening] = cb;
function cancel() {
delete callbacks[this.id];
}
const res = {
id: listening,
cancel,
};
if (listening > 1) return res;
client.OnConsoleText((text: string) => {
const lines = text.split(/[\r\n]/g);
const what = lines[0];
switch (what) {
default:
// ERROR: prefixed errors
if (text.match(/^ERROR: /)) {
response.type = 'error';
const errors = text.substr(7).split('\n');
response.errors = (response.errors || []).concat(errors);
return;
}
// Errors possibly
if (text.match(/^Tried /)
|| text.match(/^No nearby /) // for /harvest
|| text.match(/^Failed /)
) {
response.type = 'error';
(response.errors = response.errors || []).push(text);
return;
}
// Signals the end of the / command
if (text.match(/^Running /)) {
response.complete = text;
delaySend();
return;
}
(response.unknown = response.unknown || []).push(text);
break;
}
});
return res;
}
}
示例3: hasClientAPI
export const isClient = () => {
return hasClientAPI();
};
示例4: default
export default () => {
if (!hasClientAPI()) return;
/**
* Set field of view
*/
registerSlashCommand('fov', 'set your field of view, client accepts values from 20 -> 179.9', (params: string = '') => {
const argv = parseArgs(params);
const degrees = argv._.length > 0 ? argv._[0] : 120;
client.FOV(degrees);
});
/**
* Drop a temporary light at the characters feet
*/
registerSlashCommand(
'droplight',
'drop a light at your location, options: (colors are 0-255) droplight <intensity> <radius> <red> <green> <blue>',
(params: string = '') => {
if (params.length === 0) return;
const argv = parseArgs(params);
if (argv._.length > 0) {
const intensity = argv._.length >= 0 ? argv._[0] : 1;
const radius = argv._.length > 1 ? argv._[1] : 20;
const red = argv._.length > 2 ? argv._[2] : 100;
const green = argv._.length > 3 ? argv._[3] : 100;
const blue = argv._.length > 4 ? argv._[4] : 100;
client.DropLight(intensity, radius, red, green, blue);
return;
}
const intensity = argv.intensity ? argv.intensity : 1;
const radius = argv.radius > 1 ? argv.radius : 20;
const red = argv.red > 2 ? argv.red : 100;
const green = argv.green > 3 ? argv.green : 100;
const blue = argv.blue > 4 ? argv.blue : 100;
client.DropLight(intensity, radius, red, green, blue);
});
/**
* Remove the closest dropped light to the player
*/
registerSlashCommand('removelight', 'removes the closest dropped light to the player', (params: string = '') => {
client.RemoveLight();
});
/**
* Remove all lights placed with the drop light command
*/
registerSlashCommand('resetlights', 'removes all dropped lights from the world', (params: string = '') => {
client.ResetLights();
});
/**
* Count all the placed blocks in the world
*/
registerSlashCommand('countblocks', 'count all placed blocks in the world.', () => {
client.CountBlocks();
setTimeout(() => systemMessage(`There are ${client.placedBlockCount} blocks in this world.`), 1000);
});
/**
* Quit the game
*/
registerSlashCommand('exit', 'quit the game', () => client.Quit());
registerSlashCommand(
'replacesubstance',
'replace blocks with type args[0] with blocks with type of args[1]', (params: string = '') => {
if (params.length === 0) return;
const argv = parseArgs(params);
if (argv._.length >= 2) {
client.ReplaceSubstance(argv._[0], argv._[1]);
}
return;
});
registerSlashCommand(
'replaceshape',
'replace blocks with shape args[0] with blocks with shape of args[1]', (params: string = '') => {
if (params.length === 0) return;
const argv = parseArgs(params);
if (argv._.length >= 2) {
client.ReplaceShapes(argv._[0], argv._[1]);
}
return;
});
registerSlashCommand(
'replaceselectedsubstance',
'replace blocks with type args[0] with blocks with type of args[1] within selected range', (params: string = '') => {
if (params.length === 0) return;
const argv = parseArgs(params);
if (argv._.length >= 2) {
client.ReplaceSelectedSubstance(argv._[0], argv._[1]);
}
return;
});
registerSlashCommand(
'replaceselectedshape',
'replace blocks with shape args[0] to blocks with shape of args[1] within selected range', (params: string = '') => {
//.........这里部分代码省略.........