Class: Doom::Wad::HudGraphics

Inherits:
Object
  • Object
show all
Defined in:
lib/doom/wad/hud_graphics.rb

Overview

Loads HUD graphics (status bar, weapons) from WAD

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wad) ⇒ HudGraphics

Returns a new instance of HudGraphics.



9
10
11
12
13
14
15
16
17
18
# File 'lib/doom/wad/hud_graphics.rb', line 9

def initialize(wad)
  @wad = wad
  @cache = {}

  load_status_bar
  load_numbers
  load_weapons
  load_faces
  load_keys
end

Instance Attribute Details

#arms_backgroundObject (readonly)

Returns the value of attribute arms_background.



7
8
9
# File 'lib/doom/wad/hud_graphics.rb', line 7

def arms_background
  @arms_background
end

#facesObject (readonly)

Returns the value of attribute faces.



7
8
9
# File 'lib/doom/wad/hud_graphics.rb', line 7

def faces
  @faces
end

#grey_numbersObject (readonly)

Returns the value of attribute grey_numbers.



7
8
9
# File 'lib/doom/wad/hud_graphics.rb', line 7

def grey_numbers
  @grey_numbers
end

#keysObject (readonly)

Returns the value of attribute keys.



7
8
9
# File 'lib/doom/wad/hud_graphics.rb', line 7

def keys
  @keys
end

#numbersObject (readonly)

Returns the value of attribute numbers.



7
8
9
# File 'lib/doom/wad/hud_graphics.rb', line 7

def numbers
  @numbers
end

#status_barObject (readonly)

Returns the value of attribute status_bar.



7
8
9
# File 'lib/doom/wad/hud_graphics.rb', line 7

def status_bar
  @status_bar
end

#weaponsObject (readonly)

Returns the value of attribute weapons.



7
8
9
# File 'lib/doom/wad/hud_graphics.rb', line 7

def weapons
  @weapons
end

#yellow_numbersObject (readonly)

Returns the value of attribute yellow_numbers.



7
8
9
# File 'lib/doom/wad/hud_graphics.rb', line 7

def yellow_numbers
  @yellow_numbers
end

Instance Method Details

#[](name) ⇒ Object

Get a cached graphic by name



21
22
23
# File 'lib/doom/wad/hud_graphics.rb', line 21

def [](name)
  @cache[name]
end

#load_graphic(name) ⇒ Object

Load (and cache) a single named patch/graphic lump. Returns a HudSprite or nil if the lump is missing or too small. Public so the menu, intermission and font renderers can pull graphics by name.



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/doom/wad/hud_graphics.rb', line 28

def load_graphic(name)
  return @cache[name] if @cache[name]

  entry = @wad.find_lump(name)
  return nil unless entry

  data = @wad.read_lump_at(entry)
  return nil unless data && data.size > 8

  sprite = parse_patch(name, data)
  @cache[name] = sprite
  sprite
end