Added some fields in score components to track more data. Added some logic to the ScoreSystem class

This commit is contained in:
Tleety
2016-03-03 09:49:20 +01:00
parent 40c66f76ae
commit 27d3ec4118
6 changed files with 81 additions and 7 deletions
+13 -2
View File
@@ -14,9 +14,20 @@ public:
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt) override;
EventRelay<ScoreScreenSystem, Events::PlayerDeath> m_EPlayerDeath;
void OnPlayerDeath(const Events::PlayerDeath& e);
bool OnPlayerDeath(const Events::PlayerDeath& e);
EventRelay<ScoreScreenSystem, Events::PlayerSpawned> m_EPlayerSpawned;
void OnPlayerSpawn(const Events::PlayerSpawned& e);
bool OnPlayerSpawn(const Events::PlayerSpawned& e);
private:
struct PlayerData {
int ID = -1;
std::string Name = "";
int Team = -1;
EntityWrapper Player = EntityWrapper::Invalid;
};
int m_PlayerCounter = 0;
std::unordered_map<std::string, PlayerData> m_PlayerIdentities;
};
#endif
@@ -1,3 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<ScoreIdentity xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ScoreIdentity.xsd">
<Name></Name>
<ID>-1</ID>
<KD>0.0</KD>
<Kills>0</Kills>
<Deaths>0</Deaths>
<Ping>0</Ping>
<Connected>true</Connected>
</ScoreIdentity>
@@ -4,6 +4,9 @@
<xs:element name="ScoreIdentity">
<xs:annotation><xs:documentation>A component tracking data for the score of a player.</xs:documentation></xs:annotation>
<xs:element name="Name" type="t:string" minOccurs="0"/>
<xs:element name="ID" type="t:int" minOccurs="0">
<xs:annotation><xs:documentation>A unique id for tracking identities</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="KD" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>The Kills per death score.</xs:documentation></xs:annotation>
</xs:element>
@@ -16,5 +19,8 @@
<xs:element name="Ping" type="t:int" minOccurs="0">
<xs:annotation><xs:documentation>Ping of a player.</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="Connected" type="t:Bool" minOccurs="0">
<xs:annotation><xs:documentation>If the player is currently connected or not</xs:documentation></xs:annotation>
</xs:element>
</xs:element>
</xs:schema>
@@ -1,3 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<ScoreScreen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ScoreScreen.xsd">
<TotalIdentities>0</TotalIdentities>
<NextPosition>0</NextPosition>
</ScoreScreen>
+7 -4
View File
@@ -1,10 +1,13 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="ScoreScreen">
<xs:annotation>
<xs:documentation>The screen where player scores will be shown.</xs:documentation>
</xs:annotation>
<xs:annotation><xs:documentation>The screen where player scores will be shown.</xs:documentation></xs:annotation>
<xs:element name="TotalIdentities" type="t:int" minOccurs="0">
<xs:annotation><xs:documentation>The amount of score identities this scoreboard hold</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="NextPosition" type="t:int" minOccurs="0">
<xs:annotation><xs:documentation>Where the next scoreIdentity should be placed.</xs:documentation></xs:annotation>
</xs:element>
</xs:element>
</xs:schema>
+46 -1
View File
@@ -11,7 +11,30 @@ ScoreScreenSystem::ScoreScreenSystem(SystemParams params)
void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt)
{
//Logic here
if(!entity.Valid() || !entity.HasComponent("ScoreScreen")){
return;
}
auto children = entity.ChildrenWithComponent("ScoreIdentity");
for (auto it = m_PlayerIdentities.begin(); it != m_PlayerIdentities.end(); ++it) {
bool found = false;
for (auto child : children) {
std::string name = (std::string)child["ScoreIdentity"]["Name"];
if (it->first == name) {
found = true;
break;
}
}
if(found == false) {
//There is no entry for this player, create one.
}
}
//For each scoreboard, go through children and see if they have all of the ones needed.
//Also need to take into account the order so they dont flicker.
//If they do not have all children we need to add them.
//Just add a new component to the scorescreen entity, the "ScoreIdentity" component.
}
void ScoreScreenSystem::OnPlayerDeath(const Events::PlayerDeath& e)
@@ -22,4 +45,26 @@ void ScoreScreenSystem::OnPlayerDeath(const Events::PlayerDeath& e)
void ScoreScreenSystem::OnPlayerSpawn(const Events::PlayerSpawned& e)
{
//When a player spawn, add a new entry to the score screen.
if(!e.Player.Valid()) {
return;
}
EntityWrapper entity = e.Player;
std::unordered_map<std::string, PlayerData>::const_iterator got;
got = m_PlayerIdentities.find(e.PlayerName);
if (got == m_PlayerIdentities.end()) {
PlayerData data;
data.ID = m_PlayerCounter;
data.Name = e.PlayerName;
data.Player = e.Player;
if(!entity.HasComponent("Team")) {
return;
}
data.Team = (int)entity["Team"]["Team"];
std::pair<std::string, PlayerData> list (data.Name, data);
m_PlayerIdentities.insert(list);
m_PlayerCounter++;
}
}