import type { DropItem } from './items'

export const BLOCK_SIZE = 64 // each block is 64̨̣̌̇x64 pixel in size and equals 1m
export const RECIPROCAL = 1 / BLOCK_SIZE

export const STAGE_WIDTH = 20 // 20*64 = 1280 pixel wide stage
// export const STAGE_HEIGHT = ~~(STAGE_WIDTH * 0.5625) // 16:9 😎
export const STAGE_HEIGHT = 12 // 12*64 = 768 pixel high stage

export const GRAVITY = 10 // blocks per second

export type Block = {
  type: string,          // what is it?
  hp: number,            // how long do I need to hit it?
  walkable: boolean,     // can I walk through it?
  climbable?: boolean,   // can I climb it?
  transparent?: boolean, // can I see through it?
  illuminated?: boolean, // is it glowing?
  drops?: DropItem,        // what do I get, when loot it?
}

export type BlockType =
  | 'air' | 'grass'
  | 'treeCrown' | 'treeLeaves' | 'treeTrunk' | 'treeRoot'
  | 'soil' | 'soilGravel' | 'stone' | 'stoneGravel'
  | 'bedrock' | 'cave'
  | 'brickWall'

export const blockTypes: Record<BlockType, Block> = {
  // Transparent Blocks
  air: { type: 'air', hp: Infinity, walkable: true, transparent: true },
  cave: { type: 'cave', hp: Infinity, walkable: true, transparent: true },
  // Tree Parts
  treeCrown: { type: 'treeCrown', hp: 1, walkable: true, transparent: true, drops: 'leaves' },
  treeLeaves: { type: 'treeLeaves', hp: 1, walkable: true, transparent: true, drops: 'leaves' },
  treeTrunk: { type: 'treeTrunk', hp: 10, walkable: true, climbable: true, transparent: true, drops: 'wood' },
  treeRoot: { type: 'treeRoot', hp: 10, walkable: true, climbable: true, drops: 'wood' },
  // Opaque Natural Blocks
  grass: { type: 'grass', hp: 5, walkable: false, drops: 'dirt' },
  soil: { type: 'soil', hp: 5, walkable: false, drops: 'dirt' },
  soilGravel: { type: 'soilGravel', hp: 5, walkable: false, drops: 'gravel' },
  stoneGravel: { type: 'stoneGravel', hp: 10, walkable: false, drops: 'gravel' },
  stone: { type: 'stone', hp: 10, walkable: false, drops: 'stone' },
  bedrock: { type: 'bedrock', hp: 25, walkable: false, drops: 'stone' },
  // Built Blocks
  brickWall: { type: 'brickWall', hp: 25, walkable: false, drops: 'stone' },
}

export const level = {
  treeTop: 9,
  ground: 14,
  rock: 16,
  underground: 24,
  caveMax: 250,
}

export const probability = {
  tree: 0.3,
  soilHole: 0.3,
  soilGravel: 0.2,
  stoneGravel: 0.1,
  cave: 0.5,
  fray: 0.4,
}
