-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
158 lines (128 loc) · 3.61 KB
/
main.lua
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
local Signal = require 'ext.hump.signal'
require 'filefix'
require 'gamepadfix'
require 'utility'
local avatar = require 'avatar'
local audio = require 'audio'
local config = require 'config'
local server = require 'server'
local UI = require 'ui'
local lang = require 'lang'
local dragging = false
-- command to change selected slot
local function cmd_changeSlots(args)
local slot = args['slot']
if slot == nil or slot < 0 or slot > 10 then
print('cmd_changeSlots: Invalid slot number')
return
end
config:change_slot(slot)
avatar:update_offsets()
end
-- entry point
function love.load(args)
config:load()
lang:init()
avatar:init()
audio:init()
UI:init()
-- start websocket server
server:start(20501)
-- signal listeners
Signal.register('sleepToggle', avatar.sleepToggle)
Signal.register('changeSlot', cmd_changeSlots)
end
function love.update(dt)
server:update()
-- check preset selection hotkey
if love.keyboard.isDown('lctrl') and love.keyboard.isDown('lshift') then
for i = 9, 0, -1 do
local slot = i
if slot == 0 then slot = 10 end
if love.keyboard.isDown(i) and config.slot ~= slot then
config:change_slot(slot)
end
end
end
audio:update(dt)
avatar:update(dt)
UI:update(dt)
end
function love.draw()
love.graphics.setBackgroundColor(config.data.bg_color.r / 255,
config.data.bg_color.g / 255,
config.data.bg_color.b / 255, 0)
avatar:draw()
UI:draw()
end
function love.quit()
server:stop()
UI:shutdown()
avatar:shutdown()
audio:shutdown()
end
-- input forwarding
function love.keypressed(key, scancode, isrepeat)
UI:keypressed(key, scancode, isrepeat)
end
function love.keyreleased(key, scancode)
UI:keyreleased(key, scancode)
end
function love.mousepressed(x, y, button, istouch, presses)
if not UI:mousepressed(x, y, button, istouch, presses) then
-- start draging if not ui press and right click
if button == 2 and not avatar.isSleeping then
dragging = true
end
end
end
function love.mousereleased(x, y, button, istouch, presses)
if not UI:mousereleased(x, y, button, istouch, presses) then
end
-- stop dragging on right click release
-- we want this even if ui captures it so it doesnt get stuck dragging
if button == 2 then
dragging = false
end
end
function love.mousemoved(x, y, dx, dy, istouch)
if not UI:mousemoved(x, y, dx, dy, istouch) then
end
-- if not clicked on menu, drag menu
if dragging then
config.data.offsetx = config.data.offsetx - dx
config.data.offsety = config.data.offsety - dy
avatar:update_offsets()
end
end
function love.textinput(text)
UI:textinput(text)
end
function love.wheelmoved(x, y)
if not UI:windowIsAnyHovered() or not UI:wheelmoved(x, y) then
if y ~= 0 then
config.data.zoom = config.data.zoom + (y * 0.1)
if config.data.zoom < 0.1 then
config.data.zoom = 0.1
end
end
end
end
function love.gamepadpressed(joystick, button)
end
function love.filedropped(file)
if supportedFileType(file) then
file:open("r")
local data = file:read()
file:close()
local fileName = GetBaseFilename(file:getFilename())
local newFile = love.filesystem.newFile('images/' .. fileName)
newFile:open('w')
newFile:write(data)
newFile:flush()
newFile:close()
return
else
print('Unsupported file type ' .. ext)
end
end