本文整理汇总了TypeScript中underscore.min函数的典型用法代码示例。如果您正苦于以下问题:TypeScript min函数的具体用法?TypeScript min怎么用?TypeScript min使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了min函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
makeRoomTypes.forEach((makeRoomType) => {
const items = store.buckets[makeRoomType];
if (items.length > 0 && items.length >= store.capacityForItem(items[0])) {
// We'll move the lowest-value item to the vault.
const itemToMove = _.min(items.filter((i) => !i.equipped && !i.notransfer), (i) => {
let value = {
Common: 0,
Uncommon: 1,
Rare: 2,
Legendary: 3,
Exotic: 4
}[i.tier];
// And low-stat
if (i.primStat) {
value += i.primStat.value / 1000;
}
return value;
});
if (!_.isNumber(itemToMove)) {
itemsToMove.push(itemToMove);
}
}
});
示例2: drawLine
export function drawLine(scope, d, tipdiv) {
const data = scope.stdmodel.data;
const svg = scope.maing;
const attachments: _.Dictionary<any> = [];
const x2 = scope.plotRange.data2scrX(d.targetx);
const y2 = scope.plotRange.data2scrY(d.targety);
const position = tipdiv.position();
const left = position.left;
const top = position.top;
const height = tipdiv.outerHeight();
const width = tipdiv.outerWidth();
addAttachment(left, top + height / 2, x2, y2, attachments);
addAttachment(left + width, top + height / 2, x2, y2, attachments);
addAttachment(left + width / 2, top, x2, y2, attachments);
addAttachment(left + width / 2, top + height, x2, y2, attachments);
addAttachment(left, top, x2, y2, attachments);
addAttachment(left + width, top, x2, y2, attachments);
addAttachment(left + width, top + height, x2, y2, attachments);
addAttachment(left, top + height, x2, y2, attachments);
let attachment = _.min(attachments, (item) => item.dist);
const x1 = attachment.x;
const y1 = attachment.y;
svg.append("line")
.style("stroke", data[d.idx].tip_color)
.attr("class", "plot-tooltip-line")
.attr("id", d.id + "_line")
.attr("x2", x2)
.attr("y2", y2)
.attr("x1", x1)
.attr("y1", y1);
}
示例3: buildTalentGrid
function buildTalentGrid(item, talentDefs, progressDefs): D1TalentGrid | null {
const talentGridDef = talentDefs.get(item.talentGridHash);
if (
!item.progression ||
!talentGridDef ||
!item.nodes ||
!item.nodes.length ||
!progressDefs.get(item.progression.progressionHash)
) {
return null;
}
const totalXP = item.progression.currentProgress;
const totalLevel = item.progression.level; // Can be way over max
// progressSteps gives the XP needed to reach each level, with
// the last element repeating infinitely.
const progressSteps = progressDefs.get(item.progression.progressionHash).steps;
// Total XP to get to specified level
function xpToReachLevel(level) {
if (level === 0) {
return 0;
}
let totalXPRequired = 0;
for (let step = 1; step <= level; step++) {
totalXPRequired += progressSteps[Math.min(step, progressSteps.length) - 1].progressTotal;
}
return totalXPRequired;
}
const possibleNodes = talentGridDef.nodes;
// var featuredPerkNames = item.perks.map(function(perk) {
// var perkDef = perkDefs.get(perk.perkHash);
// return perkDef ? perkDef.displayName : 'Unknown';
// });
let gridNodes = (item.nodes as any[]).map(
(node): D1GridNode | undefined => {
const talentNodeGroup = possibleNodes[node.nodeHash];
const talentNodeSelected = talentNodeGroup.steps[node.stepIndex];
if (!talentNodeSelected) {
return undefined;
}
const nodeName = talentNodeSelected.nodeStepName;
// Filter out some weird bogus nodes
if (!nodeName || nodeName.length === 0 || talentNodeGroup.column < 0) {
return undefined;
}
// Only one node in this column can be selected (scopes, etc)
const exclusiveInColumn = Boolean(
talentNodeGroup.exlusiveWithNodes && talentNodeGroup.exlusiveWithNodes.length > 0
);
// Unlocked is whether or not the material cost has been paid
// for the node
const unlocked =
node.isActivated ||
talentNodeGroup.autoUnlocks ||
// If only one can be activated, the cost only needs to be
// paid once per row.
(exclusiveInColumn &&
_.any(talentNodeGroup.exlusiveWithNodes, (nodeIndex: number) => {
return item.nodes[nodeIndex].isActivated;
}));
// Calculate relative XP for just this node
const startProgressionBarAtProgress = talentNodeSelected.startProgressionBarAtProgress;
const activatedAtGridLevel = talentNodeSelected.activationRequirement.gridLevel;
const xpRequired = xpToReachLevel(activatedAtGridLevel) - startProgressionBarAtProgress;
const xp = Math.max(0, Math.min(totalXP - startProgressionBarAtProgress, xpRequired));
// Build a perk string for the DTR link. See https://github.com/DestinyItemManager/DIM/issues/934
let dtrHash: string | null = null;
if (node.isActivated || talentNodeGroup.isRandom) {
dtrHash = (node.nodeHash as number).toString(16);
if (dtrHash.length > 1) {
dtrHash += '.';
}
if (talentNodeGroup.isRandom) {
dtrHash += node.stepIndex.toString(16);
if (node.isActivated) {
dtrHash += 'o';
}
}
}
// Generate a hash that identifies the weapons permutation and selected perks.
// This is used by the Weapon Reviewing system.
const generateNodeDtrRoll = (node, talentNodeSelected): string => {
let dtrRoll = node.nodeHash.toString(16);
if (dtrRoll.length > 1) {
dtrRoll += '.';
//.........这里部分代码省略.........
示例4: buildTalentGrid
function buildTalentGrid(
item: DestinyItemComponent,
talentsMap: { [key: string]: DestinyItemTalentGridComponent },
talentDefs: LazyDefinition<DestinyTalentGridDefinition>
): DimTalentGrid | null {
if (!item.itemInstanceId || !talentsMap[item.itemInstanceId]) {
return null;
}
const talentGrid = talentsMap[item.itemInstanceId];
if (!talentGrid) {
return null;
}
const talentGridDef = talentDefs.get(talentGrid.talentGridHash);
if (!talentGridDef || !talentGridDef.nodes || !talentGridDef.nodes.length) {
return null;
}
const gridNodes = _.compact(talentGridDef.nodes.map((node): DimGridNode | undefined => {
const talentNodeGroup = node;
const talentNodeSelected = node.steps[0];
if (!talentNodeSelected) {
return undefined;
}
const nodeName = talentNodeSelected.displayProperties.name;
// Filter out some weird bogus nodes
if (!nodeName || nodeName.length === 0 || talentNodeGroup.column < 0) {
return undefined;
}
// Only one node in this column can be selected (scopes, etc)
const exclusiveInColumn = Boolean(talentNodeGroup.exclusiveWithNodeHashes &&
talentNodeGroup.exclusiveWithNodeHashes.length > 0);
const activatedAtGridLevel = talentNodeSelected.activationRequirement.gridLevel;
// There's a lot more here, but we're taking just what we need
return {
name: nodeName,
hash: talentNodeSelected.nodeStepHash,
description: talentNodeSelected.displayProperties.description,
icon: talentNodeSelected.displayProperties.icon,
// Position in the grid
column: talentNodeGroup.column / 8,
row: talentNodeGroup.row / 8,
// Is the node selected (lit up in the grid)
activated: true,
// The item level at which this node can be unlocked
activatedAtGridLevel,
// Only one node in this column can be selected (scopes, etc)
exclusiveInColumn,
// Whether or not the material cost has been paid for the node
unlocked: true,
// Some nodes don't show up in the grid, like purchased ascend nodes
hidden: false
};
}));
if (!gridNodes.length) {
return null;
}
// Fix for stuff that has nothing in early columns
const minByColumn = _.min(gridNodes.filter((n) => !n.hidden), (n) => n.column);
const minColumn = minByColumn.column;
if (minColumn > 0) {
gridNodes.forEach((node) => { node.column -= minColumn; });
}
return {
nodes: _.sortBy(gridNodes, (node) => node.column + (0.1 * node.row)),
complete: _.all(gridNodes, (n) => n.unlocked)
};
}