Continue IconSource refactoring

This commit is contained in:
Fingercomp 2025-08-12 15:20:27 +03:00
parent b759846505
commit 9ce89c2b58
No known key found for this signature in database
GPG Key ID: BBC71CEE45D86E37
12 changed files with 127 additions and 123 deletions

View File

@ -14,99 +14,75 @@ case class IconSource(
) )
object IconSource { object IconSource {
val CardIcon: IconSource = IconSource("icons/Card")
val CpuIcon: IconSource = IconSource("icons/CPU")
val HddIcon: IconSource = IconSource("icons/HDD")
val EepromIcon: IconSource = IconSource("icons/EEPROM")
val FloppyIcon: IconSource = IconSource("icons/Floppy")
val MemoryIcon: IconSource = IconSource("icons/Memory")
val ServerIcon: IconSource = IconSource("icons/Server")
val ComponentBusIcon: IconSource = IconSource("icons/ComponentBus")
val TierIcon: Tier => IconSource = { tier =>
IconSource(s"icons/Tier${tier.id}")
}
val SideNoneIcon: IconSource = IconSource("icons/SideNone")
val SideAnyIcon: IconSource = IconSource("icons/SideAny")
val SideUndefinedIcon: IconSource = IconSource("icons/SideUndefined")
val SideIcon: Direction => IconSource = {
case Down => IconSource(s"icons/SideDown")
case Up => IconSource(s"icons/SideUp")
case North => IconSource(s"icons/SideNorth")
case South => IconSource(s"icons/SideSouth")
case West => IconSource(s"icons/SideWest")
case East => IconSource(s"icons/SideEast")
case _ => SideUndefinedIcon
}
object Items { object Items {
protected val prefix: String = "items"
val Cpu: Tier => IconSource = { tier => val Cpu: Tier => IconSource = { tier =>
IconSource(s"items/CPU${tier.id}") IconSource(s"$prefix/CPU${tier.id}")
} }
val Apu: Tier => IconSource = { tier => val Apu: Tier => IconSource = { tier =>
IconSource(s"items/APU${tier.id}", animation = Some(Animations.Apu)) IconSource(s"$prefix/APU${tier.id}", animation = Some(Animations.Apu))
} }
val GraphicsCard: Tier => IconSource = { tier => val GraphicsCard: Tier => IconSource = { tier =>
IconSource(s"items/GraphicsCard${tier.id}") IconSource(s"$prefix/GraphicsCard${tier.id}")
} }
val NetworkCard: IconSource = IconSource("items/NetworkCard") val NetworkCard: IconSource = IconSource(s"$prefix/NetworkCard")
val WirelessNetworkCard: Tier => IconSource = { tier => val WirelessNetworkCard: Tier => IconSource = { tier =>
IconSource(s"items/WirelessNetworkCard${tier.id}") IconSource(s"$prefix/WirelessNetworkCard${tier.id}")
} }
val LinkedCard: IconSource = IconSource("items/LinkedCard", animation = Some(Animations.LinkedCard)) val LinkedCard: IconSource = IconSource(s"$prefix/LinkedCard", animation = Some(Animations.LinkedCard))
val InternetCard: IconSource = IconSource("items/InternetCard", animation = Some(Animations.InternetCard)) val InternetCard: IconSource = IconSource(s"$prefix/InternetCard", animation = Some(Animations.InternetCard))
val RedstoneCard: Tier => IconSource = { tier => val RedstoneCard: Tier => IconSource = { tier =>
IconSource(s"items/RedstoneCard${tier.id}") IconSource(s"$prefix/RedstoneCard${tier.id}")
} }
val DataCard: Tier => IconSource = { tier => val DataCard: Tier => IconSource = { tier =>
IconSource(s"items/DataCard${tier.id}", animation = Some(Animations.DataCard)) IconSource(s"$prefix/DataCard${tier.id}", animation = Some(Animations.DataCard))
} }
val SoundCard: IconSource = IconSource("items/SoundCard", animation = Some(Animations.DataCard)) val SoundCard: IconSource = IconSource(s"$prefix/SoundCard", animation = Some(Animations.DataCard))
val SelfDestructingCard: IconSource = val SelfDestructingCard: IconSource =
IconSource("items/SelfDestructingCard", animation = Some(Animations.SelfDestructingCard)) IconSource(s"$prefix/SelfDestructingCard", animation = Some(Animations.SelfDestructingCard))
val OcelotCard: IconSource = IconSource("items/OcelotCard", animation = Some(Animations.OcelotCard)) val OcelotCard: IconSource = IconSource(s"$prefix/OcelotCard", animation = Some(Animations.OcelotCard))
val HardDiskDrive: Tier => IconSource = { tier => val HardDiskDrive: Tier => IconSource = { tier =>
IconSource(s"items/HardDiskDrive${tier.id}") IconSource(s"$prefix/HardDiskDrive${tier.id}")
} }
val Eeprom: IconSource = IconSource("items/EEPROM") val Eeprom: IconSource = IconSource(s"$prefix/EEPROM")
val FloppyDisk: DyeColor => IconSource = { color => val FloppyDisk: DyeColor => IconSource = { color =>
IconSource(s"items/FloppyDisk_${color.name}") IconSource(s"$prefix/FloppyDisk_${color.name}")
} }
val Memory: ExtendedTier => IconSource = { tier => val Memory: ExtendedTier => IconSource = { tier =>
IconSource(s"items/Memory${tier.id}") IconSource(s"$prefix/Memory${tier.id}")
} }
val Server: Tier => IconSource = { tier => val Server: Tier => IconSource = { tier =>
IconSource(s"items/Server${tier.id}") IconSource(s"$prefix/Server${tier.id}")
} }
val ComponentBus: Tier => IconSource = { tier => val ComponentBus: Tier => IconSource = { tier =>
IconSource(s"items/ComponentBus${tier.id}") IconSource(s"$prefix/ComponentBus${tier.id}")
} }
val Tape: TapeKind => IconSource = { val Tape: TapeKind => IconSource = {
case TapeKind.Golder => Tape(TapeKind.Gold) case TapeKind.Golder => Tape(TapeKind.Gold)
case TapeKind.NetherStarrer => Tape(TapeKind.NetherStar) case TapeKind.NetherStarrer => Tape(TapeKind.NetherStar)
case kind => IconSource(s"items/Tape$kind") case kind => IconSource(s"$prefix/Tape$kind")
} }
val DiskDriveMountable: IconSource = IconSource("items/DiskDriveMountable") val DiskDriveMountable: IconSource = IconSource(s"$prefix/DiskDriveMountable")
// noinspection ScalaWeakerAccess // noinspection ScalaWeakerAccess
object Animations { object Animations {
@ -138,75 +114,103 @@ object IconSource {
// ----------------------- Ocelot interface icons ----------------------- // ----------------------- Ocelot interface icons -----------------------
val Loading: IconSource = IconSource(
"Loading",
animation = Some(Animation(
Size2D(48, 32),
(0, 0.7f),
(1, 0.7f),
(2, 0.7f),
(3, 0.7f),
(4, 0.7f),
(5, 0.7f),
(6, 0.7f),
(7, 0.7f),
(8, 0.7f),
(9, 0.7f),
(10, 0.7f),
(11, 0.7f),
(12, 0.7f),
(13, 0.7f),
)),
)
object Icons { object Icons {
val Notification: NotificationType => IconSource = { notificationType => protected val prefix: String = "icons"
IconSource(s"icons/Notification$notificationType")
val Card: IconSource = IconSource(s"$prefix/Card")
val Cpu: IconSource = IconSource(s"$prefix/CPU")
val Hdd: IconSource = IconSource(s"$prefix/HDD")
val Eeprom: IconSource = IconSource(s"$prefix/EEPROM")
val Floppy: IconSource = IconSource(s"$prefix/Floppy")
val Memory: IconSource = IconSource(s"$prefix/Memory")
val Server: IconSource = IconSource(s"$prefix/Server")
val ComponentBus: IconSource = IconSource(s"$prefix/ComponentBus")
val Tier: Tier => IconSource = { tier =>
IconSource(s"$prefix/Tier${tier.id}")
} }
val Loading: IconSource = IconSource( val SideNone: IconSource = IconSource(s"$prefix/SideNone")
"Loading", val SideAny: IconSource = IconSource(s"$prefix/SideAny")
animation = Some(Animation( val SideUndefined: IconSource = IconSource(s"$prefix/SideUndefined")
Size2D(48, 32), val Side: Direction => IconSource = {
(0, 0.7f), case Down => IconSource(s"$prefix/SideDown")
(1, 0.7f), case Up => IconSource(s"$prefix/SideUp")
(2, 0.7f), case North => IconSource(s"$prefix/SideNorth")
(3, 0.7f), case South => IconSource(s"$prefix/SideSouth")
(4, 0.7f), case West => IconSource(s"$prefix/SideWest")
(5, 0.7f), case East => IconSource(s"$prefix/SideEast")
(6, 0.7f), case _ => SideUndefined
(7, 0.7f), }
(8, 0.7f),
(9, 0.7f),
(10, 0.7f),
(11, 0.7f),
(12, 0.7f),
(13, 0.7f),
)),
)
val SettingsKeymap: IconSource = IconSource("icons/SettingsKeymap") val Notification: NotificationType => IconSource = { notificationType =>
val SettingsSystem: IconSource = IconSource("icons/SettingsSystem") IconSource(s"$prefix/Notification$notificationType")
val SettingsSound: IconSource = IconSource("icons/SettingsSound") }
val SettingsUI: IconSource = IconSource("icons/SettingsUI")
val Delete: IconSource = IconSource("icons/Delete") val SettingsKeymap: IconSource = IconSource(s"$prefix/SettingsKeymap")
val Label: IconSource = IconSource("icons/Label") val SettingsSystem: IconSource = IconSource(s"$prefix/SettingsSystem")
val Copy: IconSource = IconSource("icons/Copy") val SettingsSound: IconSource = IconSource(s"$prefix/SettingsSound")
val AspectRatio: IconSource = IconSource("icons/AspectRatio") val SettingsUI: IconSource = IconSource(s"$prefix/SettingsUI")
val Eject: IconSource = IconSource("icons/Eject") val Delete: IconSource = IconSource(s"$prefix/Delete")
val Restart: IconSource = IconSource("icons/Restart") val Label: IconSource = IconSource(s"$prefix/Label")
val Edit: IconSource = IconSource("icons/Edit") val Copy: IconSource = IconSource(s"$prefix/Copy")
val Folder: IconSource = IconSource("icons/Folder") val AspectRatio: IconSource = IconSource(s"$prefix/AspectRatio")
val FolderSlash: IconSource = IconSource("icons/FolderSlash") val Eject: IconSource = IconSource(s"$prefix/Eject")
val Code: IconSource = IconSource("icons/Code") val Restart: IconSource = IconSource(s"$prefix/Restart")
val File: IconSource = IconSource("icons/File") val Edit: IconSource = IconSource(s"$prefix/Edit")
val Link: IconSource = IconSource("icons/Link") val Folder: IconSource = IconSource(s"$prefix/Folder")
val LinkSlash: IconSource = IconSource("icons/LinkSlash") val FolderSlash: IconSource = IconSource(s"$prefix/FolderSlash")
val Power: IconSource = IconSource("icons/Power") val Code: IconSource = IconSource(s"$prefix/Code")
val Save: IconSource = IconSource("icons/Save") val File: IconSource = IconSource(s"$prefix/File")
val SaveAs: IconSource = IconSource("icons/SaveAs") val Link: IconSource = IconSource(s"$prefix/Link")
val Plus: IconSource = IconSource("icons/Plus") val LinkSlash: IconSource = IconSource(s"$prefix/LinkSlash")
val Cross: IconSource = IconSource("icons/Cross") val Power: IconSource = IconSource(s"$prefix/Power")
val Microchip: IconSource = IconSource("icons/Microchip") val Save: IconSource = IconSource(s"$prefix/Save")
val Antenna: IconSource = IconSource("icons/Antenna") val SaveAs: IconSource = IconSource(s"$prefix/SaveAs")
val Window: IconSource = IconSource("icons/Window") val Plus: IconSource = IconSource(s"$prefix/Plus")
val Tiers: IconSource = IconSource("icons/Tiers") val Cross: IconSource = IconSource(s"$prefix/Cross")
val LinesHorizontal: IconSource = IconSource("icons/LinesHorizontal") val Microchip: IconSource = IconSource(s"$prefix/Microchip")
val ArrowRight: IconSource = IconSource("icons/ArrowRight") val Antenna: IconSource = IconSource(s"$prefix/Antenna")
val Book: IconSource = IconSource("icons/Book") val Window: IconSource = IconSource(s"$prefix/Window")
val Help: IconSource = IconSource("icons/Help") val Tiers: IconSource = IconSource(s"$prefix/Tiers")
val Ocelot: IconSource = IconSource("icons/Ocelot") val LinesHorizontal: IconSource = IconSource(s"$prefix/LinesHorizontal")
val Guitar: IconSource = IconSource("icons/Guitar") val ArrowRight: IconSource = IconSource(s"$prefix/ArrowRight")
val Keyboard: IconSource = IconSource("icons/Keyboard") val Book: IconSource = IconSource(s"$prefix/Book")
val KeyboardOff: IconSource = IconSource("icons/KeyboardOff") val Help: IconSource = IconSource(s"$prefix/Help")
val ButtonRandomize: IconSource = IconSource("icons/ButtonRandomize") val Ocelot: IconSource = IconSource(s"$prefix/Ocelot")
val ButtonClipboard: IconSource = IconSource("icons/ButtonClipboard") val Guitar: IconSource = IconSource(s"$prefix/Guitar")
val ButtonCheck: IconSource = IconSource("icons/ButtonCheck") val Keyboard: IconSource = IconSource(s"$prefix/Keyboard")
val Home: IconSource = IconSource("icons/Home") val KeyboardOff: IconSource = IconSource(s"$prefix/KeyboardOff")
val Pin: IconSource = IconSource("icons/Pin") val ButtonRandomize: IconSource = IconSource(s"$prefix/ButtonRandomize")
val Unpin: IconSource = IconSource("icons/Unpin") val ButtonClipboard: IconSource = IconSource(s"$prefix/ButtonClipboard")
val Close: IconSource = IconSource("icons/Close") val ButtonCheck: IconSource = IconSource(s"$prefix/ButtonCheck")
val Grid: IconSource = IconSource("icons/Grid") val Home: IconSource = IconSource(s"$prefix/Home")
val GridOff: IconSource = IconSource("icons/GridOff") val Pin: IconSource = IconSource(s"$prefix/Pin")
val Unpin: IconSource = IconSource(s"$prefix/Unpin")
val Close: IconSource = IconSource(s"$prefix/Close")
val Grid: IconSource = IconSource(s"$prefix/Grid")
val GridOff: IconSource = IconSource(s"$prefix/GridOff")
} }
// ----------------------- Node icons ----------------------- // ----------------------- Node icons -----------------------

View File

@ -17,8 +17,8 @@ case class NodePort(direction: Option[Direction.Value] = None) extends Ordered[N
} }
def getIcon: IconSource = direction match { def getIcon: IconSource = direction match {
case Some(direction) => IconSource.SideIcon(direction) case Some(direction) => IconSource.Icons.Side(direction)
case None => IconSource.SideAnyIcon case None => IconSource.Icons.SideAny
} }
override def compare(that: NodePort): Int = this.direction.compare(that.direction) override def compare(that: NodePort): Int = this.direction.compare(that.direction)

View File

@ -46,7 +46,7 @@ class UpdateCheckerDialog extends ModalDialog with Logging {
// loading screen // loading screen
container.children :+= new Label("Checking development news...") container.children :+= new Label("Checking development news...")
container.children :+= new PaddingBox(new Icon(IconSource.Icons.Loading, color = ColorScheme("Label")), container.children :+= new PaddingBox(new Icon(IconSource.Loading, color = ColorScheme("Label")),
Padding2D(16, 0, 0, 90)) Padding2D(16, 0, 0, 90))
// check the API // check the API

View File

@ -6,6 +6,6 @@ import ocelot.desktop.inventory.traits.CardItem
import totoro.ocelot.brain.util.Tier.Tier import totoro.ocelot.brain.util.Tier.Tier
class CardSlotWidget(slot: Inventory#Slot, _tier: Tier) extends SlotWidget[CardItem](slot) { class CardSlotWidget(slot: Inventory#Slot, _tier: Tier) extends SlotWidget[CardItem](slot) {
override def ghostIcon: Option[IconSource] = Some(IconSource.CardIcon) override def ghostIcon: Option[IconSource] = Some(IconSource.Icons.Card)
override def slotTier: Option[Tier] = Some(_tier) override def slotTier: Option[Tier] = Some(_tier)
} }

View File

@ -6,6 +6,6 @@ import ocelot.desktop.inventory.item.ComponentBusItem
import totoro.ocelot.brain.util.Tier.Tier import totoro.ocelot.brain.util.Tier.Tier
class ComponentBusSlotWidget(slot: Inventory#Slot, _tier: Tier) extends SlotWidget[ComponentBusItem](slot) { class ComponentBusSlotWidget(slot: Inventory#Slot, _tier: Tier) extends SlotWidget[ComponentBusItem](slot) {
override def ghostIcon: Option[IconSource] = Some(IconSource.ComponentBusIcon) override def ghostIcon: Option[IconSource] = Some(IconSource.Icons.ComponentBus)
override def slotTier: Option[Tier] = Some(_tier) override def slotTier: Option[Tier] = Some(_tier)
} }

View File

@ -6,6 +6,6 @@ import ocelot.desktop.inventory.traits.CpuLikeItem
import totoro.ocelot.brain.util.Tier.Tier import totoro.ocelot.brain.util.Tier.Tier
class CpuSlotWidget(slot: Inventory#Slot, _tier: Tier) extends SlotWidget[CpuLikeItem](slot) { class CpuSlotWidget(slot: Inventory#Slot, _tier: Tier) extends SlotWidget[CpuLikeItem](slot) {
override def ghostIcon: Option[IconSource] = Some(IconSource.CpuIcon) override def ghostIcon: Option[IconSource] = Some(IconSource.Icons.Cpu)
override def slotTier: Option[Tier] = Some(_tier) override def slotTier: Option[Tier] = Some(_tier)
} }

View File

@ -5,5 +5,5 @@ import ocelot.desktop.inventory.Inventory
import ocelot.desktop.inventory.item.EepromItem import ocelot.desktop.inventory.item.EepromItem
class EepromSlotWidget(slot: Inventory#Slot) extends SlotWidget[EepromItem](slot) { class EepromSlotWidget(slot: Inventory#Slot) extends SlotWidget[EepromItem](slot) {
override def ghostIcon: Option[IconSource] = Some(IconSource.EepromIcon) override def ghostIcon: Option[IconSource] = Some(IconSource.Icons.Eeprom)
} }

View File

@ -6,7 +6,7 @@ import ocelot.desktop.inventory.Inventory
import ocelot.desktop.inventory.item.FloppyItem import ocelot.desktop.inventory.item.FloppyItem
class FloppySlotWidget(slot: Inventory#Slot) extends SlotWidget[FloppyItem](slot) { class FloppySlotWidget(slot: Inventory#Slot) extends SlotWidget[FloppyItem](slot) {
override def ghostIcon: Option[IconSource] = Some(IconSource.FloppyIcon) override def ghostIcon: Option[IconSource] = Some(IconSource.Icons.Floppy)
override def onItemAdded(): Unit = { override def onItemAdded(): Unit = {
super.onItemAdded() super.onItemAdded()

View File

@ -6,6 +6,6 @@ import ocelot.desktop.inventory.item.HddItem
import totoro.ocelot.brain.util.Tier.Tier import totoro.ocelot.brain.util.Tier.Tier
class HddSlotWidget(slot: Inventory#Slot, _tier: Tier) extends SlotWidget[HddItem](slot) { class HddSlotWidget(slot: Inventory#Slot, _tier: Tier) extends SlotWidget[HddItem](slot) {
override def ghostIcon: Option[IconSource] = Some(IconSource.HddIcon) override def ghostIcon: Option[IconSource] = Some(IconSource.Icons.Hdd)
override def slotTier: Option[Tier] = Some(_tier) override def slotTier: Option[Tier] = Some(_tier)
} }

View File

@ -6,6 +6,6 @@ import ocelot.desktop.inventory.item.MemoryItem
import totoro.ocelot.brain.util.Tier.Tier import totoro.ocelot.brain.util.Tier.Tier
class MemorySlotWidget(slot: Inventory#Slot, _tier: Tier) extends SlotWidget[MemoryItem](slot) { class MemorySlotWidget(slot: Inventory#Slot, _tier: Tier) extends SlotWidget[MemoryItem](slot) {
override def ghostIcon: Option[IconSource] = Some(IconSource.MemoryIcon) override def ghostIcon: Option[IconSource] = Some(IconSource.Icons.Memory)
override def slotTier: Option[Tier] = Some(_tier) override def slotTier: Option[Tier] = Some(_tier)
} }

View File

@ -6,7 +6,7 @@ import ocelot.desktop.inventory.item.ServerItem
import ocelot.desktop.inventory.traits.RackMountableItem import ocelot.desktop.inventory.traits.RackMountableItem
class RackMountableSlotWidget(slot: Inventory#Slot) extends SlotWidget[RackMountableItem](slot) { class RackMountableSlotWidget(slot: Inventory#Slot) extends SlotWidget[RackMountableItem](slot) {
override def ghostIcon: Option[IconSource] = Some(IconSource.ServerIcon) override def ghostIcon: Option[IconSource] = Some(IconSource.Icons.Server)
override def onItemRemoved(removedItem: RackMountableItem, replacedBy: Option[RackMountableItem]): Unit = { override def onItemRemoved(removedItem: RackMountableItem, replacedBy: Option[RackMountableItem]): Unit = {
super.onItemRemoved(removedItem, replacedBy) super.onItemRemoved(removedItem, replacedBy)

View File

@ -57,7 +57,7 @@ class SlotWidget[I <: Item](private val slot: Inventory#Slot)(implicit slotItemT
def slotTier: Option[Tier] = None def slotTier: Option[Tier] = None
def tierIcon: Option[IconSource] = slotTier.map(IconSource.TierIcon) def tierIcon: Option[IconSource] = slotTier.map(IconSource.Icons.Tier)
def itemIcon: Option[IconSource] = item.map(_.icon) def itemIcon: Option[IconSource] = item.map(_.icon)