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


TypeScript ekkiog-editing.drawComponent函數代碼示例

本文整理匯總了TypeScript中ekkiog-editing.drawComponent函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript drawComponent函數的具體用法?TypeScript drawComponent怎麽用?TypeScript drawComponent使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了drawComponent函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: replaceComponents

function replaceComponents(forest : Forest, newComponent : Package){
  const didntFit = [] as {x : number, y : number}[];
  for(const item of getComponents(forest, newComponent.name)){
    if(item.data.package.hash === newComponent.hash) continue;
    const x = item.left + (item.width>>1);
    const y = item.top + (item.height>>1);
    const clearedForest = clear(forest, x, y);
    const newForest = drawComponent(clearedForest, x, y, newComponent);
    if(newForest === clearedForest){
      didntFit.push({x, y});
    }else{
      forest = newForest;
    }
  }
  return {forest, didntFit};
}
開發者ID:mariusGundersen,項目名稱:Ekkiog,代碼行數:16,代碼來源:zoomOutOf.ts

示例2: drawItem

function drawItem(forest : Forest, item : Item, x : number, y : number) : Forest {
  switch(item.type){
    case WIRE:
      return drawWire(forest, x, y);
    case UNDERPASS:
      return drawUnderpass(forest, x, y);
    case LIGHT:
      return drawLight(forest, x+1, y+1, item.direction);
    case BUTTON:
      return drawButton(forest, x+1, y+1, item.direction);
    case GATE:
      return drawGate(forest, x+3, y+1);
    case COMPONENT:
      return drawComponent(forest, x+(item.package.width>>1), y+(item.package.height>>1), item.package);
    default:
      return forest;
  }
}
開發者ID:mariusGundersen,項目名稱:Ekkiog,代碼行數:18,代碼來源:selection.ts

示例3: editing

export default function editing(forest=createForest(), action : Action) : Forest{
  switch(action.type){
    case 'set-forest':
      return action.forest || forest;
    case 'draw':
      return tap(forest, action.tool, action.direction, action.x, action.y);
    case 'remove-tile-at':
      return clear(forest, action.x, action.y);
    case 'convert-wire-to-underpass':
      return wireToUnderpass(forest, action.x, action.y);
    case 'convert-underpass-to-wire':
      return underpassToWire(forest, action.x, action.y);
    case 'insert-component':
      return drawComponent(forest, action.position.x+(action.component.width>>1), action.position.y+(action.component.height>>1), action.component);
    default:
      return forest;
  }
}
開發者ID:mariusGundersen,項目名稱:Ekkiog,代碼行數:18,代碼來源:forest.ts

示例4: zomOutOf

export default function* zomOutOf({} : ZoomOutOfAction){
  const { context: currentContext, selection: {selection: isSelection}} : State = yield select();

  if(isSelection){
    yield put(stopSelection());
    yield put(resetEditorMenu());
  }

  const outerContext = currentContext.previous;
  if(!outerContext) return;

  const innerContext : ContextState = yield* waitUntilSaved(currentContext);

  yield put(popContext());
  yield put(setUrl(outerContext.repo, outerContext.name));
  if(innerContext.isReadOnly || outerContext.isReadOnly) return;

  const pkg = packageComponent(innerContext.forest, innerContext.repo, innerContext.name, innerContext.hash, innerContext.hash);
  const {forest, didntFit} = replaceComponents(outerContext.forest, pkg);
  if(outerContext.forest !== forest){
    yield put(setForest(forest));
  }

  for(const position of didntFit) {
    yield put(removeTileAt(position.x, position.y));
    const {context: {forest: newForest}} : State = yield select();

    const forest = drawComponent(createForest(newForest.buddyTree), position.x, position.y, pkg);

    const item = getTileAt(forest, position.x, position.y);
    yield* selection(item);
  };

  const { context: newContext } : State = yield select();
  if(outerContext.forest !== newContext.forest){
    yield put(saveForest(`Updated ${pkg.name}`));
  }
}
開發者ID:mariusGundersen,項目名稱:Ekkiog,代碼行數:38,代碼來源:zoomOutOf.ts

示例5: insertComponentPackage

export default function* insertComponentPackage({componentPackage} : InsertComponentPackageAction){
  const state : State = yield select();

  if(state.selection.selection){
    yield put(stopSelection());
    yield put(resetEditorMenu());
  }

  const tile = state.view.viewportToTile(state.view.pixelWidth/2, state.view.pixelHeight/2);
  const centerTile = {
    x: tile[0]|0,
    y: tile[1]|0
  };

  const forest = drawComponent(createForest(state.context.forest.buddyTree), centerTile.x, centerTile.y, componentPackage);

  const item = getTileAt(forest, centerTile.x, centerTile.y);

  const ok = yield* selection(item);
  if(ok){
    yield put(saveForest(`Inserted ${componentPackage.name}`));
  }
}
開發者ID:mariusGundersen,項目名稱:Ekkiog,代碼行數:23,代碼來源:insertComponentPackage.ts


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