Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Game Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Onuralp SEZER
Game Library
Commits
94e7f7d9
Commit
94e7f7d9
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
entity/token system from hexboard
parent
9e4e0b1d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/fggl/grid/hexgrid.hpp
+59
-1
59 additions, 1 deletion
include/fggl/grid/hexgrid.hpp
with
59 additions
and
1 deletion
include/fggl/grid/hexgrid.hpp
+
59
−
1
View file @
94e7f7d9
...
@@ -22,12 +22,67 @@
...
@@ -22,12 +22,67 @@
#include
<map>
#include
<map>
#include
<set>
#include
<set>
#include
<optional>
#include
<optional>
#include
<utility>
#include
"fggl/grid/hexagon.hpp"
#include
"fggl/grid/hexagon.hpp"
#include
"fggl/math/types.hpp"
#include
"fggl/math/types.hpp"
namespace
fggl
::
grid
{
namespace
fggl
::
grid
{
class
TokenType
{
public:
using
PropType
=
int64_t
;
inline
void
setProperty
(
util
::
GUID
name
,
PropType
newVal
)
{
m_properties
[
name
]
=
newVal
;
}
[[
nodiscard
]]
inline
PropType
getProperty
(
util
::
GUID
name
,
PropType
unsetVal
=
0
)
const
{
try
{
return
m_properties
.
at
(
name
);
}
catch
(
std
::
out_of_range
&
e
)
{
return
unsetVal
;
}
}
private
:
std
::
map
<
util
::
GUID
,
PropType
>
m_properties
;
std
::
map
<
util
::
GUID
,
uint64_t
>
m_cost
;
};
class
Token
{
public:
Token
()
=
default
;
explicit
Token
(
std
::
shared_ptr
<
TokenType
>
type
)
:
m_type
(
std
::
move
(
type
))
{}
inline
void
setProperty
(
util
::
GUID
name
,
TokenType
::
PropType
newVal
)
{
m_properties
[
name
]
=
newVal
;
}
[[
nodiscard
]]
inline
TokenType
::
PropType
getProperty
(
util
::
GUID
name
,
TokenType
::
PropType
unsetVal
=
0
)
const
{
try
{
auto
prop
=
m_properties
.
at
(
name
);
return
prop
;
}
catch
(
std
::
out_of_range
&
ex
)
{
return
m_type
->
getProperty
(
name
,
unsetVal
);
}
}
[[
nodiscard
]]
inline
TokenType
::
PropType
getPropertyDirect
(
util
::
GUID
name
,
TokenType
::
PropType
unsetVal
=
0
)
const
{
try
{
auto
prop
=
m_properties
.
at
(
name
);
return
prop
;
}
catch
(
std
::
out_of_range
&
ex
)
{
return
unsetVal
;
}
}
private
:
std
::
shared_ptr
<
TokenType
>
m_type
;
std
::
map
<
util
::
GUID
,
TokenType
::
PropType
>
m_properties
;
};
struct
MaterialData
{
struct
MaterialData
{
std
::
string
name
;
std
::
string
name
;
math
::
vec3
colour
;
math
::
vec3
colour
;
...
@@ -39,6 +94,7 @@ namespace fggl::grid {
...
@@ -39,6 +94,7 @@ namespace fggl::grid {
struct
HexTile
{
struct
HexTile
{
std
::
shared_ptr
<
MaterialData
>
terrain
;
std
::
shared_ptr
<
MaterialData
>
terrain
;
std
::
vector
<
std
::
shared_ptr
<
Token
>
>
m_tokens
;
[[
nodiscard
]]
[[
nodiscard
]]
inline
std
::
optional
<
const
MaterialData
>
data
()
const
{
inline
std
::
optional
<
const
MaterialData
>
data
()
const
{
...
@@ -46,10 +102,11 @@ namespace fggl::grid {
...
@@ -46,10 +102,11 @@ namespace fggl::grid {
{}
{}
}
}
return
*
terrain
.
get
()
;
return
*
terrain
;
}
}
};
};
class
HexGrid
{
class
HexGrid
{
public:
public:
inline
bool
isValidPos
(
const
IntHex
&
pos
)
const
{
inline
bool
isValidPos
(
const
IntHex
&
pos
)
const
{
...
@@ -82,6 +139,7 @@ namespace fggl::grid {
...
@@ -82,6 +139,7 @@ namespace fggl::grid {
private
:
private
:
std
::
map
<
IntHex
,
HexTile
>
m_tiles
;
std
::
map
<
IntHex
,
HexTile
>
m_tiles
;
std
::
map
<
uint64_t
,
std
::
shared_ptr
<
Token
>>
m_tokens
;
};
};
}
// namespace fggl::grid
}
// namespace fggl::grid
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment