|
| 1 | +local gui = require('gui') |
| 2 | +local gui_notes = reqscript('gui/notes') |
| 3 | +local utils = require('utils') |
| 4 | + |
| 5 | +-- local guidm = require('gui.dwarfmode') |
| 6 | + |
| 7 | +config = { |
| 8 | + target = 'gui/notes', |
| 9 | + mode = 'fortress' |
| 10 | +} |
| 11 | + |
| 12 | +local waypoints = df.global.plotinfo.waypoints |
| 13 | +local map_points = df.global.plotinfo.waypoints.points |
| 14 | + |
| 15 | +local map_points_backup = nil |
| 16 | + |
| 17 | +local function arrange_notes(notes) |
| 18 | + map_points_backup = utils.clone(map_points) |
| 19 | + map_points:resize(0) |
| 20 | + |
| 21 | + for _, note in ipairs(notes or {}) do |
| 22 | + map_points:insert("#", { |
| 23 | + new=true, |
| 24 | + |
| 25 | + id = waypoints.next_point_id, |
| 26 | + tile=88, |
| 27 | + fg_color=7, |
| 28 | + bg_color=0, |
| 29 | + name=note.name, |
| 30 | + comment=note.comment, |
| 31 | + pos=note.pos |
| 32 | + }) |
| 33 | + end |
| 34 | +end |
| 35 | + |
| 36 | +local function arrange_gui_notes(options) |
| 37 | + options = options or {} |
| 38 | + |
| 39 | + arrange_notes(options.notes) |
| 40 | + |
| 41 | + gui_notes.main() |
| 42 | + |
| 43 | + local gui_notes = gui_notes.view |
| 44 | + |
| 45 | + gui_notes:updateLayout() |
| 46 | + gui_notes:onRender() |
| 47 | + |
| 48 | + return gui_notes |
| 49 | +end |
| 50 | + |
| 51 | +local function cleanup(gui_notes) |
| 52 | + gui_notes:dismiss() |
| 53 | + |
| 54 | + df.global.plotinfo.waypoints.points:resize(#map_points_backup) |
| 55 | + for ind, map_point in ipairs(map_points_backup) do |
| 56 | + df.global.plotinfo.waypoints.points[ind - 1] = map_point |
| 57 | + end |
| 58 | + map_points_backup = nil |
| 59 | +end |
| 60 | + |
| 61 | +function test.load_gui_notes() |
| 62 | + local gui_notes = arrange_gui_notes() |
| 63 | + expect.eq(gui_notes.visible, true) |
| 64 | + cleanup(gui_notes) |
| 65 | +end |
| 66 | + |
| 67 | +function test.provide_notes_list() |
| 68 | + local notes = { |
| 69 | + {name='note 1', comment='comment 1', pos={x=1, y=1, z=1}}, |
| 70 | + {name='note 2', comment='comment 2', pos={x=2, y=2, z=2}}, |
| 71 | + {name='note 3', comment='comment 3', pos={x=3, y=3, z=3}}, |
| 72 | + } |
| 73 | + |
| 74 | + local gui_notes = arrange_gui_notes({ notes=notes }) |
| 75 | + local note_list = gui_notes.subviews.note_list:getChoices() |
| 76 | + |
| 77 | + for ind, note in ipairs(notes) do |
| 78 | + local gui_note = note_list[ind] |
| 79 | + expect.eq(gui_note.text, note.name) |
| 80 | + expect.eq(gui_note.point.comment, note.comment) |
| 81 | + expect.table_eq(gui_note.point.pos, note.pos) |
| 82 | + end |
| 83 | + |
| 84 | + expect.eq(gui_notes.visible, true) |
| 85 | + cleanup(gui_notes) |
| 86 | +end |
0 commit comments