mirror of https://github.com/bra1n/townsquare.git
handle empty image urls correctly (fixes #42)
This commit is contained in:
parent
d3d4b0d338
commit
b158230fce
|
@ -329,7 +329,7 @@ ul {
|
||||||
|
|
||||||
.night {
|
.night {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: start;
|
align-items: flex-start;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
> *:first-child {
|
> *:first-child {
|
||||||
margin-right: 2vh;
|
margin-right: 2vh;
|
||||||
|
|
|
@ -104,6 +104,8 @@ export default new Vuex.Store({
|
||||||
* @param roles Array of role IDs or full role definitions
|
* @param roles Array of role IDs or full role definitions
|
||||||
*/
|
*/
|
||||||
setCustomRoles(state, roles) {
|
setCustomRoles(state, roles) {
|
||||||
|
const imageBase =
|
||||||
|
"https://raw.githubusercontent.com/bra1n/townsquare/main/src/assets/icons/";
|
||||||
const customRole = {
|
const customRole = {
|
||||||
image: "",
|
image: "",
|
||||||
edition: "custom",
|
edition: "custom",
|
||||||
|
@ -121,12 +123,21 @@ export default new Vuex.Store({
|
||||||
role =>
|
role =>
|
||||||
rolesJSONbyId.get(role.id) || Object.assign({}, customRole, role)
|
rolesJSONbyId.get(role.id) || Object.assign({}, customRole, role)
|
||||||
)
|
)
|
||||||
|
// default empty icons to good / evil / traveler
|
||||||
|
.map(role => {
|
||||||
|
if (role.team === "townsfolk" || role.team === "outsider") {
|
||||||
|
role.image = role.image || imageBase + "good.png";
|
||||||
|
} else if (role.team === "demon" || role.team === "minion") {
|
||||||
|
role.image = role.image || imageBase + "evil.png";
|
||||||
|
} else {
|
||||||
|
role.image = role.image || imageBase + "custom.png";
|
||||||
|
}
|
||||||
|
return role;
|
||||||
|
})
|
||||||
// filter out roles that don't match an existing role and also don't have name/ability/team
|
// filter out roles that don't match an existing role and also don't have name/ability/team
|
||||||
.filter(role => role.name && role.ability && role.team)
|
.filter(role => role.name && role.ability && role.team)
|
||||||
// sort by team
|
// sort by team
|
||||||
.sort((a, b) =>
|
.sort((a, b) => b.team.localeCompare(a.team))
|
||||||
b.team.localeCompare(a.team)
|
|
||||||
)
|
|
||||||
// convert to Map
|
// convert to Map
|
||||||
.map(role => [role.id, role])
|
.map(role => [role.id, role])
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue