Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import libtcod/libtcod
- const
- COLS = 80
- ROWS = 50
- FONT = "data/fonts/consolas12x12_gs_tc.png"
- FLAGS = FONT_TYPE_GREYSCALE or FONT_LAYOUT_TCOD
- NB_ROW = 32
- NB_COL = 8
- TITLE = "namegen"
- RENDERER = RENDERER_SDL
- var
- sets: seq[string] = @[]
- names: seq[string] = @[]
- idSet = 0
- files: seq[string] = sys_get_directory_content("data/namegen", "*.cfg")
- key: TKey
- # Libtcod init
- console_set_custom_font(FONT, FLAGS, NB_ROW, NB_COL)
- console_init_root(COLS, ROWS, TITLE, false, RENDERER)
- console_set_default_foreground(nil, WHITE)
- console_set_default_background(nil, BLACK)
- # Namegen init
- for f in files:
- namegen_parse(f, nil)
- sets = namegen_get_sets()
- for n in 0..ROWS-1:
- names.add("")
- # Main loop
- while not console_is_window_closed():
- console_clear(nil)
- for s in 0..sets.high:
- console_print(nil, 1, s, "%s", sets[s])
- console_print(nil, 0, idSet, ">")
- for n in 0..names.high:
- console_print(nil, COLS div 2, n, "%s", names[n])
- console_flush()
- discard sys_check_for_event(EVENT_KEY_PRESS, addr(key), nil)
- if key.vk == K_DOWN:
- inc idSet
- if idSet > sets.high:
- idSet = 0
- if key.vk == K_UP:
- dec idSet
- if idSet < 0:
- idSet = sets.high
- if key.vk == K_ENTER:
- for n in 0..ROWS-1:
- names[n] = $namegen_generate(sets[idSet])
Advertisement
Add Comment
Please, Sign In to add comment