aboutsummaryrefslogtreecommitdiff
path: root/src/objs/room_editor.lua
blob: baee368d3b5faa58f6a4bda3500f7b2d9aa1b45d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
register_input("Next_Tileset", {{"key", "t"}})
register_input("Prev_Tileset", {{"key", "r"}})

register_comp("Room_Editor", function(ent)
  ent.room_editor = {
    tile = 1,
  }
end)

function tile_place_sys(ent)
  local room_editor = ent.room_editor

  if not im.has_focus() then
    if is_input_pressed("Right_Click") then
      local scn = get_current_scene()
      assert(scn, "no scene set.")

      local mx, my = get_mouse_pos()
      local tx, ty = to_tile_coords(mx, my)
      set_tile(scn.tilemap, tx, ty, room_editor.tile)
    end
    if is_input_pressed("Left_Click") then
      local scn = get_current_scene()
      assert(scn, "no scene set.")

      local mx, my = get_mouse_pos()
      local tx, ty = to_tile_coords(mx, my)
      remove_tile(scn.tilemap, tx, ty)
    end
  end

  if is_input_just_pressed("Next_Tileset") then
    room_editor.tile = math.min(room_editor.tile + 1, get_tileset_count())
  end
  if is_input_just_pressed("Prev_Tileset") then
    room_editor.tile = math.max(room_editor.tile - 1, 1)
  end
end

function room_editor_ui_sys(ent)
  local room_editor = ent.room_editor
  im.begin_window("Room Editor", 120, 5, 180, 320, {})
    -- im.layout({0.5, 0.75, 1})
    im.text("Tile: " .. tostring(room_editor.tile))
    -- if im.button(" - ") then
    --   tile = math.max(tile - 1, 1)
    -- end
    -- if im.button("+ ") then
    --   tile = tile + 1
    -- end
    im.layout({0.1, 0.6, 1})

    for tileset_id=1, get_tileset_count() do
      local text = " "
      if tileset_id == room_editor.tile then
        text = "*"
      elseif tileset_id == room_editor.tile - 1 then
        text = "r"
      elseif tileset_id == room_editor.tile + 1 then
        text = "t"
      end
      im.text(text)
      if im.button("select") then
        room_editor.tile = tileset_id
      end
      im.image(TILE_TEX, get_tileset_quad(tileset_id))
    end

    im.layout()
  im.end_window()
end