Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,45 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local held =
{
Properties =
{
IncomingInputEventName = "",
OutgoingGameplayEventName = "",
},
}
function held:OnActivate()
local inputBusId = InputEventNotificationId(self.Properties.IncomingInputEventName)
self.inputBus = InputEventNotificationBus.Connect(self, inputBusId)
end
function held:OnPressed(floatValue)
GameplayNotificationBus.Event.OnEventBegin(GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName, "float"), floatValue)
end
function held:OnHeld(floatValue)
GameplayNotificationBus.Event.OnEventUpdating(GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName, "float"), floatValue)
end
function held:OnReleased(floatValue)
GameplayNotificationBus.Event.OnEventEnd(GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName, "float"), floatValue)
end
function held:OnDeactivate()
self.inputBus:Disconnect()
end
return held
@@ -0,0 +1,110 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local gameplayMultiHandler = require('Scripts.Utils.Components.GameplayUtils')
local ordered_event_combination =
{
Properties =
{
IncomingGameplayEventNames = {"",},
OutgoingGameplayEventName = "",
TimeToCompleteAllEvents = 1,
},
BusIds = {},
DeprecatedBusIds = {},
Handlers = {},
DeprecatedHandlers = {},
}
function ordered_event_combination:OnActivate()
for nameCount = 1, #self.Properties.IncomingGameplayEventNames do
self.BusIds[nameCount] = GameplayNotificationId(self.entityId, self.Properties.IncomingGameplayEventNames[nameCount], "float")
self.Handlers[nameCount] = gameplayMultiHandler.ConnectMultiHandlers{
[self.BusIds[nameCount]] = {
OnEventBegin = function(floatValue) self:OnEventBegin(floatValue) end,
},
}
-- support for deprecated APIs. This will be removed in 1.12
self.DeprecatedBusIds[nameCount] = GameplayNotificationId(self.entityId, self.Properties.IncomingGameplayEventNames[nameCount])
self.DeprecatedHandlers[nameCount] = gameplayMultiHandler.ConnectMultiHandlers{
[self.DeprecatedBusIds[nameCount]] = {
OnEventBegin = function(floatValue) self:OnDeprecatedHandlerEventBegin(floatValue) end,
},
}
end
self.nextExpectedEventIndex = 1
self.nextExpectedDeprecatedEventIndex = 1
self.accumulatedTime = 0
end
function ordered_event_combination:OnDeactivate()
for nameCount = 1, #self.Properties.IncomingGameplayEventNames do
self.Handlers[nameCount]:Disconnect()
self.DeprecatedHandlers[nameCount]:Disconnect()
end
self.TickHandler:Disconnect()
end
function ordered_event_combination:OnDeprecatedHandlerEventBegin(floatValue)
self.TickHandler = TickBus.Connect(self, 0)
if GameplayNotificationBus.GetCurrentBusId() == self.DeprecatedBusIds[self.nextExpectedDeprecatedEventIndex] then
self.nextExpectedDeprecatedEventIndex = self.nextExpectedDeprecatedEventIndex + 1
if (self.nextExpectedDeprecatedEventIndex > #self.Properties.IncomingGameplayEventNames) then
self:Reset(true, floatValue)
end
elseif self.nextExpectedDeprecatedEventIndex > 1 then
self:Reset(false, 0)
end
end
function ordered_event_combination:OnEventBegin(floatValue)
self.TickHandler = TickBus.Connect(self, 0)
if GameplayNotificationBus.GetCurrentBusId() == self.BusIds[self.nextExpectedEventIndex] then
self.nextExpectedEventIndex = self.nextExpectedEventIndex + 1
if (self.nextExpectedEventIndex > #self.Properties.IncomingGameplayEventNames) then
self:Reset(true, floatValue)
end
elseif self.nextExpectedEventIndex > 1 then
self:Reset(false, 0)
end
end
function ordered_event_combination:OnTick(dt, scriptTime)
if self.nextExpectedEventIndex == 1 then
self.TickHandler:Disconnect()
return
end
self.accumulatedTime = self.accumulatedTime + dt
if self.accumulatedTime > self.Properties.TimeToCompleteAllEvents then
self:Reset(false, 0)
end
end
function ordered_event_combination:Reset(success, floatValue)
self.TickHandler:Disconnect()
self.nextExpectedEventIndex = 1
self.nextExpectedDeprecatedEventIndex = 1
self.accumulatedTime = 0
if success then
GameplayNotificationBus.Event.OnEventBegin(GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName), floatValue)
GameplayNotificationBus.Event.OnEventBegin(GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName, "float"), floatValue)
else
GameplayNotificationBus.Event.OnEventEnd(GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName), floatValue)
GameplayNotificationBus.Event.OnEventEnd(GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName, "float"), floatValue)
end
end
return ordered_event_combination
@@ -0,0 +1,43 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local pressed =
{
Properties =
{
IncomingInputEventName = "",
OutgoingGameplayEventName = "",
},
}
function pressed:OnActivate()
local inputBusId = InputEventNotificationId(self.Properties.IncomingInputEventName)
self.inputBus = InputEventNotificationBus.Connect(self, inputBusId)
end
function pressed:OnPressed(floatValue)
GameplayNotificationBus.Event.OnEventBegin(GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName, "float"), floatValue)
end
function pressed:OnHeld(floatValue)
end
function pressed:OnReleased(floatValue)
GameplayNotificationBus.Event.OnEventEnd(GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName, "float"), floatValue)
end
function pressed:OnDeactivate()
self.inputBus:Disconnect()
end
return pressed
@@ -0,0 +1,43 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local released =
{
Properties =
{
IncomingInputEventName = "",
OutgoingGameplayEventName = "",
},
}
function released:OnActivate()
local inputBusId = InputEventNotificationId(self.Properties.IncomingInputEventName)
self.inputBus = InputEventNotificationBus.Connect(self, inputBusId)
end
function released:OnPressed(floatValue)
GameplayNotificationBus.Event.OnEventEnd(GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName, "float"), floatValue)
end
function released:OnHeld(floatValue)
end
function released:OnReleased(floatValue)
GameplayNotificationBus.Event.OnEventBegin(GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName, "float"), floatValue)
end
function released:OnDeactivate()
self.inputBus:Disconnect()
end
return released
@@ -0,0 +1,144 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local gameplayMultiHandler = require('Scripts.Utils.Components.GameplayUtils')
local vectorized_combination =
{
Properties =
{
XCoordEventName = "",
YCoordEventName = "",
ZCoordEventName = "",
OutgoingGameplayEventName = "",
DeadZoneLength = 0.2,
},
}
function vectorized_combination:OnActivate()
self.vectorizedValue = Vector3(0,0,0)
self.active = false
self.outgoingId = GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName, "Vector3")
self.vectorizedHandlers = gameplayMultiHandler.ConnectMultiHandlers{
[GameplayNotificationId(self.entityId, self.Properties.XCoordEventName, "float")] = {
OnEventBegin = function(floatValue) self:UpdateX(floatValue) end,
OnEventUpdating = function(floatValue) self:UpdateX(floatValue) end,
OnEventEnd = function(floatValue) self:UpdateX(0) end,
},
[GameplayNotificationId(self.entityId, self.Properties.YCoordEventName, "float")] = {
OnEventBegin = function(floatValue) self:UpdateY(floatValue) end,
OnEventUpdating = function(floatValue) self:UpdateY(floatValue) end,
OnEventEnd = function(floatValue) self:UpdateY(0) end,
},
[GameplayNotificationId(self.entityId, self.Properties.ZCoordEventName, "float")] = {
OnEventBegin = function(floatValue) self:UpdateZ(floatValue) end,
OnEventUpdating = function(floatValue) self:UpdateZ(floatValue) end,
OnEventEnd = function(floatValue) self:UpdateZ(0) end,
},
}
-- deprecated bus id's will be removed in 1.12
-------------------------------------------------------------------------
self.deprecatedOutgoingId = GameplayNotificationId(self.entityId, self.Properties.OutgoingGameplayEventName)
self.deprecatedVectorizedHandlers = gameplayMultiHandler.ConnectMultiHandlers{
[GameplayNotificationId(self.entityId, self.Properties.XCoordEventName)] = {
OnEventBegin = function(floatValue) self:UpdateX(floatValue) end,
OnEventUpdating = function(floatValue) self:UpdateX(floatValue) end,
OnEventEnd = function(floatValue) self:UpdateX(0) end,
},
[GameplayNotificationId(self.entityId, self.Properties.YCoordEventName)] = {
OnEventBegin = function(floatValue) self:UpdateY(floatValue) end,
OnEventUpdating = function(floatValue) self:UpdateY(floatValue) end,
OnEventEnd = function(floatValue) self:UpdateY(0) end,
},
[GameplayNotificationId(self.entityId, self.Properties.ZCoordEventName)] = {
OnEventBegin = function(floatValue) self:UpdateZ(floatValue) end,
OnEventUpdating = function(floatValue) self:UpdateZ(floatValue) end,
OnEventEnd = function(floatValue) self:UpdateZ(0) end,
},
}
-------------------------------------------------------------------------
end
function vectorized_combination:OnDeactivate()
self.vectorizedHandlers:Disconnect()
self.deprecatedVectorizedHandlers:Disconnect()
end
function vectorized_combination:SendGameplayEvent()
local shouldBeActive = self.vectorizedValue:GetLength() > self.Properties.DeadZoneLength
if shouldBeActive and not self.active then
GameplayNotificationBus.Event.OnEventBegin(self.outgoingId, self.vectorizedValue, "float")
elseif shouldBeActive and self.active then
GameplayNotificationBus.Event.OnEventUpdating(self.outgoingId, self.vectorizedValue, "float")
elseif not shouldBeActive and self.active then
GameplayNotificationBus.Event.OnEventEnd(self.outgoingId, self.vectorizedValue, "float")
end
self.active = shouldBeActive
-- otherwise we were not active and shouldn't be active so do nothing
end
-- X coordinate handlers
function vectorized_combination:UpdateX(floatValue)
self.vectorizedValue.x = floatValue
self:SendGameplayEvent()
end
-- Y coordinate handlers
function vectorized_combination:UpdateY(floatValue)
self.vectorizedValue.y = floatValue
self:SendGameplayEvent()
end
-- Z coordinate handlers
function vectorized_combination:UpdateZ(floatValue)
self.vectorizedValue.z = floatValue
self:SendGameplayEvent()
end
--deprecated methods will be removed in 1.12
-------------------------------------------------------------------------
function vectorized_combination:DeprecatedSendGameplayEvent()
local shouldBeActive = self.vectorizedValue:GetLength() > self.Properties.DeadZoneLength
if shouldBeActive and not self.active then
GameplayNotificationBus.Event.OnEventBegin(self.deprecatedOutgoingId, self.vectorizedValue)
elseif shouldBeActive and self.active then
GameplayNotificationBus.Event.OnEventUpdating(self.deprecatedOutgoingId, self.vectorizedValue)
elseif not shouldBeActive and self.active then
GameplayNotificationBus.Event.OnEventEnd(self.deprecatedOutgoingId, self.vectorizedValue)
end
self.active = shouldBeActive
-- otherwise we were not active and shouldn't be active so do nothing
end
-- X coordinate handlers
function vectorized_combination:DeprecatedUpdateX(floatValue)
self.vectorizedValue.x = floatValue
self:DeprecatedSendGameplayEvent()
end
-- Y coordinate handlers
function vectorized_combination:DeprecatedUpdateY(floatValue)
self.vectorizedValue.y = floatValue
self:DeprecatedSendGameplayEvent()
end
-- Z coordinate handlers
function vectorized_combination:DeprecatedUpdateZ(floatValue)
self.vectorizedValue.z = floatValue
self:DeprecatedSendGameplayEvent()
end
-------------------------------------------------------------------------
return vectorized_combination