當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript camelot-unchained.hasClientAPI函數代碼示例

本文整理匯總了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' });
  }
}
開發者ID:codecorsair,項目名稱:Camelot-Unchained,代碼行數:10,代碼來源:slash.ts

示例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;
  }
}
開發者ID:codecorsair,項目名稱:Camelot-Unchained,代碼行數:48,代碼來源:slash.ts

示例3: hasClientAPI

export const isClient = () => {
  return hasClientAPI();
};
開發者ID:codecorsair,項目名稱:Camelot-Unchained,代碼行數:3,代碼來源:slash.ts

示例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 = '') => {
//.........這裏部分代碼省略.........
開發者ID:codecorsair,項目名稱:Camelot-Unchained,代碼行數:101,代碼來源:clientCommands.ts


注:本文中的@csegames/camelot-unchained.hasClientAPI函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。