-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputDetector
83 lines (65 loc) · 2.55 KB
/
InputDetector
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
--!strict
local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local modules = player.PlayerScripts.Scripts.Modules
--local handler = require(modules:WaitForChild("Skeleton"):WaitForChild("GameControllerHandler"))
local gameHandler = require(modules:WaitForChild("Skeleton"):WaitForChild("GameHandlerContainer")).getHandler()
local camera = require(modules:WaitForChild("WorldInteraction"):WaitForChild("Camera")).new()
local function uncoverMine(inputType : InputObject)
if not (inputType.UserInputType == Enum.UserInputType.MouseButton1 or inputType.UserInputType == Enum.UserInputType.Touch) then
warn("Unable to flag a mine with the current input type. Please contact a developer")
return
end
--Pass the position
gameHandler:RevealCell(inputType.Position)
end
local function flagMine(inputType : InputObject)
--Pass the position
if not (inputType.UserInputType == Enum.UserInputType.MouseButton2 or inputType.UserInputType == Enum.UserInputType.Touch) then
warn("Unable to flag a mine with the current input type. Please contact a developer")
return
end
--I can use mouse.target since I am no longer using a flag grid - math wouldn't work out too well for miss clicks.
local position = Vector3.zero
if inputType.UserInputType == Enum.UserInputType.MouseButton2 then
local mouse = player:GetMouse()
print(mouse.Target:GetFullName())
position = mouse.Target.Position
end
gameHandler:FlagCell(position)
end
local function checkInput(inputType : InputObject)
if inputType.UserInputType == Enum.UserInputType.Keyboard then
local key = inputType.KeyCode
for _key, vect in pairs(camera._keys) do
if key == _key then
camera:UpdateMovement(inputType)
end
end
if key == Enum.KeyCode.Z then
if inputType.UserInputState == Enum.UserInputState.Begin then
gameHandler:Start3D()
end
end
return
end
if inputType.UserInputType == Enum.UserInputType.MouseButton1 then
if inputType.UserInputState == Enum.UserInputState.End then
uncoverMine(inputType)
end
end
if inputType.UserInputType == Enum.UserInputType.MouseButton2 then
if inputType.UserInputState == Enum.UserInputState.End then
flagMine(inputType)
end
end
end
local function charAdded()
camera:setGridView()
end
userInputService.InputBegan:Connect(checkInput)
userInputService.InputEnded:Connect(checkInput)
--TODO: Set this up with a characterAdded event. Will allow the player to reset.
player.CharacterAdded:Connect(charAdded)