You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
import type { BlockType } from './def'
|
|
import type { InventoryItem } from '../util/usePlayer'
|
|
|
|
export type ItemQuality = 'wood' | 'iron' | 'silver' | 'gold' | 'diamond'
|
|
export type ItemType = 'tool' | 'weapon' | 'block' | 'ore'
|
|
|
|
export type DropItem =
|
|
| 'Shovel' | 'Pick Axe' | 'Sword'
|
|
| 'leaves' | 'dirt' | 'wood' | 'stone' | 'gravel'
|
|
| 'coal' | 'iron' | 'silver' | 'gold' | 'ruby' | 'diamond' | 'emerald'
|
|
|
|
export interface Item {
|
|
name: DropItem
|
|
type: ItemType
|
|
icon: string
|
|
hasQuality?: boolean
|
|
builds?: BlockType
|
|
}
|
|
|
|
export const items: Item[] = [
|
|
{ name: 'Shovel', type: 'tool', icon: 'shovel', hasQuality: true },
|
|
{ name: 'Pick Axe', type: 'tool', icon: 'pick', hasQuality: true },
|
|
{ name: 'Sword', type: 'weapon', icon: 'sword', hasQuality: true },
|
|
|
|
{ name: 'leaves', type: 'block', icon: 'leaves', builds: 'treeLeaves' },
|
|
{ name: 'dirt', type: 'block', icon: 'dirt', builds: 'soil' },
|
|
{ name: 'wood', type: 'block', icon: 'wood', builds: 'treeTrunk' },
|
|
{ name: 'stone', type: 'block', icon: 'stone', builds: 'brickWall' },
|
|
{ name: 'gravel', type: 'block', icon: 'stone' }, // TODO
|
|
|
|
{ name: 'coal', type: 'ore', icon: 'ore_coal' },
|
|
{ name: 'iron', type: 'ore', icon: 'ore_iron' },
|
|
{ name: 'silver', type: 'ore', icon: 'ore_silver' },
|
|
{ name: 'gold', type: 'ore', icon: 'ore_gold' },
|
|
{ name: 'ruby', type: 'ore', icon: 'ore_ruby' },
|
|
{ name: 'diamond', type: 'ore', icon: 'ore_diamond' },
|
|
{ name: 'emerald', type: 'ore', icon: 'ore_emerald' },
|
|
]
|
|
|
|
export const damage: Record<ItemQuality, number> = {
|
|
wood: 1,
|
|
iron: 2,
|
|
silver: 3,
|
|
gold: 5,
|
|
diamond: 8,
|
|
}
|
|
|
|
export function getItem(name: string, quality = null) {
|
|
const item = items.find(i => i.name === name)
|
|
if (item) {
|
|
return {
|
|
...item,
|
|
quality,
|
|
}
|
|
}
|
|
}
|
|
|
|
export function getItemClass(item: InventoryItem) {
|
|
if (item.quality) return `${item.type}-${item.icon}-${item.quality}`
|
|
return `${item.type}-${item.icon}`
|
|
}
|