-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
102 changed files
with
2,397 additions
and
104 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/org/gitanimals/guild/app/DrawGuildProxy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.gitanimals.guild.app | ||
|
||
import org.gitanimals.guild.domain.GuildService | ||
import org.gitanimals.guild.domain.GuildService.Companion.loadMembers | ||
import org.gitanimals.render.app.DrawGuildFacade | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class DrawGuildProxy( | ||
private val guildService: GuildService, | ||
private val renderDrawGuildFacade: DrawGuildFacade, | ||
) { | ||
|
||
fun drawGuild(id: Long): String { | ||
val guild = guildService.getGuildById(id, loadMembers) | ||
|
||
return renderDrawGuildFacade.drawGuild( | ||
title = guild.getTitle(), | ||
totalContributions = guild.getTotalContributions(), | ||
guildFarmType = guild.getGuildFarmType(), | ||
userIds = guild.getMembers().map { it.userId } + guild.getLeaderUserId(), | ||
personaIds = guild.getMembers().map { it.personaId } + guild.getLeaderPersonaId(), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.gitanimals.guild.domain | ||
|
||
import org.springframework.core.io.ClassPathResource | ||
import java.nio.charset.Charset | ||
|
||
val dummyGuildFieldSvg: String = ClassPathResource("persona/field/white-field.svg") | ||
.getContentAsString(Charset.defaultCharset()) | ||
|
||
val largeTextSvgs = lazy { | ||
val map = mutableMapOf<String, String>() | ||
for (i in 'A'..'Z') { | ||
val path = "persona/text/large/$i.svg" | ||
map[i.toString()] = ClassPathResource(path) | ||
.getContentAsString(Charset.defaultCharset()) | ||
} | ||
for (i in 'a'..'z') { | ||
val path = "persona/text/large/_$i.svg" | ||
map[i.toString()] = ClassPathResource(path) | ||
.getContentAsString(Charset.defaultCharset()) | ||
} | ||
for (i in 0..9) { | ||
val path = "persona/text/large/$i.svg" | ||
map[i.toString()] = ClassPathResource(path) | ||
.getContentAsString(Charset.defaultCharset()) | ||
} | ||
map["-"] = ClassPathResource("persona/text/large/hyphens.svg") | ||
.getContentAsString(Charset.defaultCharset()) | ||
map | ||
}.value | ||
|
||
val mediumNumberSvgs = lazy { | ||
val list = mutableListOf<String>() | ||
for (i in 0..9) { | ||
val path = "persona/text/medium/$i.svg" | ||
list.add( | ||
ClassPathResource(path) | ||
.getContentAsString(Charset.defaultCharset()) | ||
) | ||
} | ||
list | ||
}.value | ||
|
||
val numberSvgs = lazy { | ||
val list = mutableListOf<String>() | ||
for (i in 0..9) { | ||
val path = "persona/text/small/$i.svg" | ||
list.add( | ||
ClassPathResource(path) | ||
.getContentAsString(Charset.defaultCharset()) | ||
) | ||
} | ||
list | ||
}.value | ||
|
49 changes: 49 additions & 0 deletions
49
src/main/kotlin/org/gitanimals/render/app/DrawGuildFacade.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.gitanimals.render.app | ||
|
||
import org.gitanimals.guild.domain.GuildFarmType | ||
import org.gitanimals.render.domain.Mode | ||
import org.gitanimals.render.domain.UserService | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class DrawGuildFacade( | ||
private val userService: UserService, | ||
) { | ||
|
||
fun drawGuild( | ||
title: String, | ||
totalContributions: Long, | ||
guildFarmType: GuildFarmType, | ||
userIds: List<Long>, | ||
personaIds: List<Long>, | ||
): String { | ||
val users = userService.findAllUsersByIdWithContributions(userIds.toSet()) | ||
|
||
val svgBuilder = StringBuilder().openGuild() | ||
.append(guildFarmType.fillBackground()) | ||
|
||
val personaSvgs = users.flatMap { user -> | ||
user.personas.filter { persona -> | ||
persona.id in personaIds | ||
}.map { persona -> | ||
persona.toSvgForce(Mode.NAME_WITH_LEVEL) | ||
} | ||
} | ||
|
||
personaSvgs.forEach { svgBuilder.append(it) } | ||
|
||
return svgBuilder.append(guildFarmType.loadComponent(title, totalContributions)) | ||
.append(guildFarmType.drawBorder()) | ||
.closeGuild() | ||
} | ||
|
||
private fun StringBuilder.openGuild(): StringBuilder = | ||
this.append("<svg width=\"600\" height=\"300\" viewBox=\"0 0 600 300\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">") | ||
|
||
private fun StringBuilder.closeGuild(): String = this | ||
.append("</svg>") | ||
.toString() | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ enum class Mode { | |
FARM, | ||
LINE, | ||
LINE_NO_CONTRIBUTION, | ||
NAME_WITH_LEVEL, | ||
; | ||
} |
Oops, something went wrong.