-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract Platforms to PlatformCategories for future Platforms
If/when we want to add Bukkit/Spigot/Paper or whatever else, adding a new platform is super simple. Signed-off-by: Jadon Fowler <[email protected]>
- Loading branch information
Showing
8 changed files
with
110 additions
and
85 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,13 +1,70 @@ | ||
package ore | ||
|
||
import scala.language.implicitConversions | ||
|
||
object Platforms extends Enumeration { | ||
|
||
val Sponge = Platform(0, "Sponge") | ||
val Forge = Platform(1, "Forge") | ||
|
||
case class Platform(override val id: Int, name: String) extends super.Val(id, name) | ||
implicit def convert(v: Value): Platform = v.asInstanceOf[Platform] | ||
|
||
} | ||
package ore | ||
|
||
import models.project.{Tag, TagColors} | ||
import models.project.TagColors.TagColor | ||
import ore.project.Dependency | ||
|
||
import scala.language.implicitConversions | ||
|
||
/** | ||
* The Platform a plugin/mod runs on | ||
* | ||
* @author phase | ||
*/ | ||
object Platforms extends Enumeration { | ||
|
||
val Sponge = Platform(0, "Sponge", SpongeCategory, 0, Dependency.SpongeApiId, TagColors.Sponge) | ||
val SpongeForge = Platform(2, "SpongeForge", SpongeCategory, 2, Dependency.SpongeForgeId, TagColors.Sponge) | ||
val SpongeVanilla = Platform(3, "SpongeVanilla", SpongeCategory, 1, Dependency.SpongeVanillaId, TagColors.Sponge) | ||
val Forge = Platform(1, "Forge", ForgeCategory, 0, Dependency.ForgeId, TagColors.Forge) | ||
|
||
case class Platform(override val id: Int, | ||
name: String, | ||
platformCategory: PlatformCategory, | ||
priority: Int, | ||
dependencyId: String, | ||
tagColor: TagColor | ||
) extends super.Val(id, name) { | ||
|
||
def toGhostTag(version: String): Tag = Tag(None, List(), name, version, tagColor) | ||
|
||
} | ||
|
||
implicit def convert(v: Value): Platform = v.asInstanceOf[Platform] | ||
|
||
def getPlatforms(dependencyIds: List[String]): List[Platform] = { | ||
Platforms.values | ||
.filter(p => dependencyIds.contains(p.dependencyId)) | ||
.groupBy[PlatformCategory](p => p.platformCategory) | ||
.map(map => map._2.toList.maxBy(p => p.priority)) | ||
.map(p => p.asInstanceOf[Platform]) | ||
.toList | ||
} | ||
|
||
def getPlatformGhostTags(dependencies: List[Dependency]): List[Tag] = { | ||
Platforms.values | ||
.filter(p => dependencies.map(_.pluginId).contains(p.dependencyId)) | ||
.groupBy[PlatformCategory](p => p.platformCategory) | ||
.map(map => map._2.toList.maxBy(p => p.priority)) | ||
.map(p => p.toGhostTag(dependencies.find(d => d.pluginId == p.dependencyId).get.version)) | ||
.toList | ||
} | ||
|
||
} | ||
|
||
/** | ||
* The category of a platform. | ||
* Examples would be | ||
* | ||
* Sponge <- SpongeAPI, SpongeForge, SpongeVanilla | ||
* Forge <- Forge (maybe Rift if that doesn't die?) | ||
* Bukkit <- Bukkit, Spigot, Paper | ||
* Canary <- Canary, Neptune | ||
* | ||
* @author phase | ||
*/ | ||
sealed trait PlatformCategory | ||
|
||
case object SpongeCategory extends PlatformCategory | ||
|
||
case object ForgeCategory extends PlatformCategory |
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