Vladar

libtcod namegen [nim]

Jul 1st, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 1.35 KB | None | 0 0
  1. import libtcod/libtcod
  2.  
  3. const
  4.   COLS = 80
  5.   ROWS = 50
  6.   FONT = "data/fonts/consolas12x12_gs_tc.png"
  7.   FLAGS = FONT_TYPE_GREYSCALE or FONT_LAYOUT_TCOD
  8.   NB_ROW = 32
  9.   NB_COL = 8
  10.   TITLE = "namegen"
  11.   RENDERER = RENDERER_SDL
  12.  
  13. var
  14.   sets: seq[string] = @[]
  15.   names: seq[string] = @[]
  16.   idSet = 0
  17.   files: seq[string] = sys_get_directory_content("data/namegen", "*.cfg")
  18.   key: TKey
  19.  
  20. # Libtcod init
  21.  
  22. console_set_custom_font(FONT, FLAGS, NB_ROW, NB_COL)
  23. console_init_root(COLS, ROWS, TITLE, false, RENDERER)
  24. console_set_default_foreground(nil, WHITE)
  25. console_set_default_background(nil, BLACK)
  26.  
  27. # Namegen init
  28.  
  29. for f in files:
  30.   namegen_parse(f, nil)
  31.  
  32. sets = namegen_get_sets()
  33.  
  34. for n in 0..ROWS-1:
  35.   names.add("")
  36.  
  37. # Main loop
  38.  
  39. while not console_is_window_closed():
  40.  
  41.   console_clear(nil)
  42.  
  43.   for s in 0..sets.high:
  44.     console_print(nil, 1, s, "%s", sets[s])
  45.  
  46.   console_print(nil, 0, idSet, ">")
  47.  
  48.   for n in 0..names.high:
  49.     console_print(nil, COLS div 2, n, "%s", names[n])
  50.  
  51.   console_flush()
  52.  
  53.   discard sys_check_for_event(EVENT_KEY_PRESS, addr(key), nil)
  54.  
  55.   if key.vk == K_DOWN:
  56.     inc idSet
  57.     if idSet > sets.high:
  58.       idSet = 0
  59.  
  60.   if key.vk == K_UP:
  61.     dec idSet
  62.     if idSet < 0:
  63.       idSet = sets.high
  64.  
  65.   if key.vk == K_ENTER:
  66.     for n in 0..ROWS-1:
  67.       names[n] = $namegen_generate(sets[idSet])
Advertisement
Add Comment
Please, Sign In to add comment