Skip to content

Commit

Permalink
Merge pull request #272 from Ellypse/feature/msp_fields_update
Browse files Browse the repository at this point in the history
MSP fields updates
  • Loading branch information
Ellypse committed Feb 11, 2019
2 parents ed9200b + 6baa0ba commit 22bdbd3
Show file tree
Hide file tree
Showing 13 changed files with 339 additions and 53 deletions.
36 changes: 32 additions & 4 deletions totalRP3/core/Models/Player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,21 @@ function Player:IsInCharacter()
return self:GetInfo("character/RP") ~= 2
end

function Player:GetAccountType()
local characterInfo = TRP3_API.register.getUnitIDCharacter(self:GetCharacterID());
return characterInfo.isTrial
end

function Player:IsOnATrialAccount()
local accountType = self:GetAccountType()
if type(accountType) == "number" then
return accountType == AddOn_TotalRP3.Enums.ACCOUNT_TYPE.TRIAL or accountType == AddOn_TotalRP3.Enums.ACCOUNT_TYPE.VETERAN
else
-- Backward compatible check, for versions where the trial flag was true or false
return accountType == true
end
end

-- TODO Deprecate GetInfo(path) in favor of proper type safe methods to access profile data
function Player:GetInfo(path)
return TRP3_API.profile.getData(path, self:GetProfile())
Expand Down Expand Up @@ -176,20 +191,33 @@ end
end

--{{{ Current user
currentUser = Player();
---@class CurrentUser
local CurrentUser = Ellyb.Class("CurrentUser", Player)

function currentUser:GetProfile()
function CurrentUser:GetProfile()
return TRP3_API.profile.getPlayerCurrentProfile().player;
end

function currentUser:GetCharacterID()
function CurrentUser:GetCharacterID()
return TRP3_API.globals.player_id;
end

function currentUser:GetRelationshipWithPlayer()
function CurrentUser:GetRelationshipWithPlayer()
return TRP3_API.globals.RELATIONS.NONE;
end

function CurrentUser:GetAccountType()
if IsTrialAccount() then
return AddOn_TotalRP3.Enums.ACCOUNT_TYPE.TRIAL;
elseif IsVeteranTrialAccount() then
return AddOn_TotalRP3.Enums.ACCOUNT_TYPE.VETERAN;
else
return AddOn_TotalRP3.Enums.ACCOUNT_TYPE.REGULAR;
end
end

currentUser = CurrentUser()

--- Returns a reference to the current user as a Player model.
--- The current user has some specific behavior due to data not being stored in the same places.
---@return Player currentUser
Expand Down
132 changes: 132 additions & 0 deletions totalRP3/core/Models/_tests/Player.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
----------------------------------------------------------------------------------
--- Total RP 3
--- Player model tests
--- ---------------------------------------------------------------------------
--- Copyright 2014-2019 Renaud "Ellypse" Parize <ellypse@totalrp3.info> @EllypseCelwe
---
--- Licensed under the Apache License, Version 2.0 (the "License");
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
---
--- http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
----------------------------------------------------------------------------------


if not WoWUnit then
return
end

local Tests = WoWUnit("TRP3:E Character Operands", "PLAYER_ENTERING_WORLD");
local Player = AddOn_TotalRP3.Player;
local Enums = AddOn_TotalRP3.Enums;

--region Regular player tests
function Tests:GetAccountTypeFromCharacterInfo()
-- Given
WoWUnit.Replace(TRP3_API.register, "getUnitIDCharacter", function()
return { isTrial = AddOn_TotalRP3.Enums.ACCOUNT_TYPE.VETERAN }
end)
-- When
local player = Player.CreateFromCharacterID("any");
-- Then
WoWUnit.AreEqual(Enums.ACCOUNT_TYPE.VETERAN, player:GetAccountType());
end

function Tests:CheckIfPlayerIsOnTrialAccountFromCharacterInfo()
local player;
-- Given
WoWUnit.Replace(TRP3_API.register, "getUnitIDCharacter", function()
return { isTrial = AddOn_TotalRP3.Enums.ACCOUNT_TYPE.VETERAN }
end)
-- When
player = Player.CreateFromCharacterID("any");
-- Then
WoWUnit.IsTrue(player:IsOnATrialAccount());

-- Given
WoWUnit.Replace(TRP3_API.register, "getUnitIDCharacter", function()
return { isTrial = AddOn_TotalRP3.Enums.ACCOUNT_TYPE.TRIAL }
end)
-- When
player = Player.CreateFromCharacterID("any");
-- Then
WoWUnit.IsTrue(player:IsOnATrialAccount());

-- Given
WoWUnit.Replace(TRP3_API.register, "getUnitIDCharacter", function()
return { isTrial = AddOn_TotalRP3.Enums.ACCOUNT_TYPE.REGULAR }
end)
-- When
player = Player.CreateFromCharacterID("any");
-- Then
WoWUnit.IsFalse(player:IsOnATrialAccount());

-- Backward compatibility check

-- Given
WoWUnit.Replace(TRP3_API.register, "getUnitIDCharacter", function()
return { isTrial = true }
end)
-- When
player = Player.CreateFromCharacterID("any");
-- Then
WoWUnit.IsTrue(player:IsOnATrialAccount());

-- Given
WoWUnit.Replace(TRP3_API.register, "getUnitIDCharacter", function()
return { isTrial = false }
end)
-- When
player = Player.CreateFromCharacterID("any");
-- Then
WoWUnit.IsFalse(player:IsOnATrialAccount());
end
--endregion

--region Current player tests
function Tests:GetAccountTypeFromGameClient()
local player;

-- Given
WoWUnit.Replace("IsTrialAccount", function()
return true
end)
-- When
player = Player.GetCurrentUser();
-- Then
WoWUnit.AreEqual(Enums.ACCOUNT_TYPE.TRIAL, player:GetAccountType())

-- Given
WoWUnit.Replace("IsTrialAccount", function()
return false
end)
WoWUnit.Replace("IsVeteranTrialAccount", function()
return true
end)
-- When
player = Player.GetCurrentUser();
-- Then
WoWUnit.AreEqual(Enums.ACCOUNT_TYPE.VETERAN, player:GetAccountType())

-- Given
WoWUnit.Replace("IsTrialAccount", function()
return false
end)
WoWUnit.Replace("IsVeteranTrialAccount", function()
return false
end)
-- When
player = Player.GetCurrentUser();
-- Then
WoWUnit.AreEqual(Enums.ACCOUNT_TYPE.REGULAR, player:GetAccountType())

end
--endregion

WoWUnit:Show()
22 changes: 12 additions & 10 deletions totalRP3/core/core.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.blizzard.com/wow/ui/">

<!--
Total RP 3
Copyright 2014 Sylvain Cossement (telkostrasz@telkostrasz.be)
Expand All @@ -18,7 +18,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->

<!-- Please note that the loading order matters a lot -->
<GameTooltip name="TRP3_MainTooltip" frameStrata="TOOLTIP" hidden="false" parent="UIParent" inherits="GameTooltipTemplate"/>
<GameTooltip name="TRP3_Toast" frameStrata="TOOLTIP" hidden="false" parent="UIParent" inherits="GameTooltipTemplate">
Expand All @@ -43,36 +43,38 @@
</Layers>
</Frame>

<Script file="impl\Enums.lua" />
<Script file="Models\Player.lua" />

<Script file="Models\_tests\Player.lua" />

<Script file="impl\globals.lua"/>
<Script file="impl\events.lua"/>
<Script file="impl\utils.lua"/>
<Script file="impl\ui_tools.lua"/>
<Script file="impl\slash.lua"/>

<Include file="ui\widgets.xml"/>

<Include file="ui\main.xml"/>
<Script file="impl\main_structure.lua"/>

<Include file="ui\configuration.xml"/>
<Script file="impl\configuration.lua"/>
<Script file="impl\AdvancedSettings.lua"/>

<Script file="impl\Compression.lua"/>
<Script file="impl\CommunicationProtocol.lua"/>
<Script file="impl\communication_protocol_broadcast.lua"/>

<Script file="impl\ui_main.lua"/>

<Include file="ui\browsers\icons.xml"/>
<Include file="ui\browsers\companions.xml"/>
<Include file="ui\browsers\musics.xml"/>
<Include file="ui\browsers\colors.xml"/>
<Include file="ui\browsers\images.xml"/>
<Script file="impl\popup.lua"/>

<Include file="ui\profiles.xml"/>
<Script file="impl\profiles.lua"/>
<Script file="impl\ProfilesChatLinksModule.lua"/>
Expand Down
38 changes: 38 additions & 0 deletions totalRP3/core/impl/Enums.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
----------------------------------------------------------------------------------
--- Total RP 3
--- Enuls
--- ---------------------------------------------------------------------------
--- Copyright 2019 Renaud "Ellypse" Parize <ellypse@totalrp3.info> @EllypseCelwe
--
--- Licensed under the Apache License, Version 2.0 (the "License");
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
--
--- http://www.apache.org/licenses/LICENSE-2.0
--
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
----------------------------------------------------------------------------------

---@type AddOn_TotalRP3
local AddOn_TotalRP3 = AddOn_TotalRP3;

AddOn_TotalRP3.Enums = {};

AddOn_TotalRP3.Enums.ACCOUNT_TYPE = {
REGULAR = 0,
TRIAL = 1,
VETERAN = 2
}

AddOn_TotalRP3.Enums.RELATIONSHIP_STATUS = {
UNKNOWN = 0,
SINGLE = 1,
TAKEN = 2,
MARRIED = 3,
DIVORCED = 4,
WIDOWED = 5,
}
4 changes: 3 additions & 1 deletion totalRP3/core/impl/globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ local race_loc, race = UnitRace("player");
local class_loc, class, class_index = UnitClass("player");
local faction, faction_loc = UnitFactionGroup("player");

local Player = AddOn_TotalRP3.Player.GetCurrentUser();

-- Public accessor
TRP3_API.r = {};
TRP3_API.formats = {
Expand Down Expand Up @@ -70,7 +72,7 @@ TRP3_API.globals = {
class = class,
faction = faction
},
is_trial_account = IsTrialAccount() or IsVeteranTrialAccount(),
is_trial_account = Player:GetAccountType(),
clients = {
TRP3 = "trp3",
MSP = "msp",
Expand Down
21 changes: 21 additions & 0 deletions totalRP3/core/ui/widgets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1143,4 +1143,25 @@
</Layer>
</Layers>
</Frame>
<Frame name="TRP3_TitledDropdown" inherits="UIDropDownMenuTemplate" enableMouse="true" virtual="true">
<Layers>
<Layer level="OVERLAY">
<FontString name="$parentTitle" parentKey="title" text="" inherits="GameFontNormalSmall" justifyH="LEFT" justifyV="TOP">
<Anchors>
<Anchor point="TOPLEFT" x="27" y="4"/>
<Anchor point="TOPRIGHT" x="22" y="4"/>
</Anchors>
<Color r="0.95" g="0.75" b="0.1"/>
</FontString>
</Layer>
</Layers>
<Scripts>
<OnEnter>
TRP3_RefreshTooltipForFrame(self);
</OnEnter>
<OnLeave>
TRP3_MainTooltip:Hide();
</OnLeave>
</Scripts>
</Frame>
</Ui>
3 changes: 2 additions & 1 deletion totalRP3/modules/register/characters/ReportProfileButton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ TRP3_API.Events.registerCallback(TRP3_API.Events.WORKFLOW_ON_LOADED, function()
onClick = function()
local DATE_FORMAT = "%Y-%m-%d around %H:%M";
local playerID = TRP3_API.utils.str.getUnitID("target");
local player = AddOn_TotalRP3.Player.CreateFromCharacterID(playerID);
local profile = TRP3_API.register.getUnitIDProfile(playerID)
local characterInfo = TRP3_API.register.getUnitIDCharacter(playerID);

Expand All @@ -61,7 +62,7 @@ TRP3_API.Events.registerCallback(TRP3_API.Events.WORKFLOW_ON_LOADED, function()
end

-- Indicate if this was a trial account if we have that info
if characterInfo.isTrial then
if player:IsOnATrialAccount() then
commentText = commentText .. "\n" .. loc.REG_REPORT_PLAYER_TEMPLATE_TRIAL_ACCOUNT;
end
PlayerReportFrame.CommentBox:SetText(commentText);
Expand Down
Loading

0 comments on commit 22bdbd3

Please sign in to comment.