Style fixes

For consistency with the rest of the MR.
This commit is contained in:
Fingercomp
2023-06-11 17:04:16 +07:00
parent 98dea7bbaf
commit 7d407a1677
12 changed files with 34 additions and 32 deletions

View File

@@ -36,7 +36,7 @@ trait Item {
}
/**
* The name of the item displayed in the tooltip.
* The name of the item (as shown in the tooltip).
*/
def name: String = factory.name
@@ -46,7 +46,7 @@ trait Item {
def icon: IconDef = factory.icon
/**
* The tier of the item, if it has one.
* The tier of the item (if it has one).
*
* This affects the color of the item name in the tooltip.
*/

View File

@@ -20,7 +20,7 @@ trait ItemFactory {
/**
* The runtime class of the [[Item]] built by the factory.
*
* It's expected that `build().getClass == itemClass`.
* @note It's expected that `build().getClass == itemClass`.
*/
def itemClass: Class[I]
@@ -36,7 +36,7 @@ trait ItemFactory {
/**
* The tier of an item this factory will construct in its [[build]] method.
*
* It's expected that `build().tier == tier`.
* @note It's expected that `build().tier == tier`.
*/
def tier: Option[Tier]

View File

@@ -19,7 +19,8 @@ object Items extends Logging {
// this is just to force load the class during initialization
def init(): Unit = {}
/** Registers a recoverer for [[ItemRecoverer.sourceClass]].
/**
* Registers a recoverer for [[ItemRecoverer.sourceClass]].
*/
def registerRecoverer(recoverer: ItemRecoverer[_, _]): Unit = {
if (!_recoverers.contains(recoverer.sourceClass)) {
@@ -70,7 +71,8 @@ object Items extends Logging {
def groups: Iterable[ItemGroup] = _groups
/** Attempts to recover an [[Item]] from `source`.
/**
* Attempts to recover an [[Item]] from `source`.
*
* Checks superclasses and traits while looking for a recoverer.
*/

View File

@@ -141,7 +141,7 @@ trait SyncedInventory extends PersistedInventory with Logging {
} else if (syncFuel == 0) {
logger.error(
s"Got trapped in an infinite loop while trying to synchronize the slot $slotIndex " +
s"in $this (of class ${this.getClass.getName})!",
s"in $this (class ${this.getClass.getName})!",
)
logger.error(
"The item in the slot: " +
@@ -175,12 +175,12 @@ trait SyncedInventory extends PersistedInventory with Logging {
case None =>
logger.error(
s"An entity ($entity of class ${entity.getClass.getName}) was inserted into a slot " +
s"An entity ($entity class ${entity.getClass.getName}) was inserted into a slot " +
s"(index: $slotIndex) of a brain inventory $brainInventory, " +
s"but we were unable to recover an Item from it.",
)
logger.error(
s"A Desktop inventory $this (of class ${getClass.getName}) could not recover the item. Removing.",
s"A Desktop inventory $this (class ${getClass.getName}) could not recover the item. Removing.",
)
logEntityLoss(slotIndex, entity)
@@ -207,12 +207,8 @@ trait SyncedInventory extends PersistedInventory with Logging {
case (Some(entity), Some(item)) =>
logger.error(
s"Encountered an inventory conflict for slot $slotIndex! " +
s"The Desktop inventory believes the slot contains $item (of class ${item.getClass.getName}), " +
s"but the brain inventory believes the slot contains $entity (of class ${
entity
.getClass
.getName
}).",
s"The Desktop inventory believes the slot contains $item (class ${item.getClass.getName}), " +
s"but the brain inventory believes the slot contains $entity (class ${entity.getClass.getName}).",
)
logger.error("Resolving the conflict in favor of Ocelot Desktop.")
@@ -232,8 +228,8 @@ trait SyncedInventory extends PersistedInventory with Logging {
private def logEntityLoss(slotIndex: Int, entity: Entity): Unit = {
logger.error(
s"Encountered a data loss! " +
s"In the brain inventory $brainInventory (of class ${brainInventory.getClass.getName}), " +
s"the entity $entity (of class ${entity.getClass.getName}) is deleted from the slot $slotIndex.",
s"In the brain inventory $brainInventory (class ${brainInventory.getClass.getName}), " +
s"the entity $entity (class ${entity.getClass.getName}) is deleted from the slot $slotIndex.",
)
}

View File

@@ -20,7 +20,7 @@ object DataCardItem {
class Tier1(val dataCard: DataCard.Tier1) extends DataCardItem {
override def component: Entity with Environment = dataCard
override val factory: Factory = Tier1.Factory
override val factory: Factory = DataCardItem.Tier1.Factory
}
object Tier1 {
@@ -40,7 +40,7 @@ object DataCardItem {
class Tier2(val dataCard: DataCard.Tier2) extends DataCardItem {
override def component: Entity with Environment = dataCard
override val factory: Factory = Tier2.Factory
override val factory: Factory = DataCardItem.Tier2.Factory
}
object Tier2 {
@@ -60,7 +60,7 @@ object DataCardItem {
class Tier3(val dataCard: DataCard.Tier3) extends DataCardItem {
override def component: Entity with Environment = dataCard
override val factory: Factory = Tier3.Factory
override val factory: Factory = DataCardItem.Tier3.Factory
}
object Tier3 {

View File

@@ -1,10 +1,10 @@
package ocelot.desktop.inventory.item
import totoro.ocelot.brain.entity.traits.Disk
import totoro.ocelot.brain.entity.traits.{Disk, Entity}
import totoro.ocelot.brain.entity.{HDDManaged, HDDUnmanaged}
sealed trait Hdd {
def hdd: Disk
def hdd: Disk with Entity
}
object Hdd {

View File

@@ -19,10 +19,7 @@ class HddItem(val hdd: Hdd) extends Item with ComponentItem with PersistableItem
this(Hdd.Unmanaged(hdd))
}
override def component: Entity with Environment = hdd match {
case Hdd.Managed(hdd) => hdd
case Hdd.Unmanaged(hdd) => hdd
}
override def component: Entity with Environment = hdd.hdd
override def fillTooltipBody(body: Widget): Unit = {
super.fillTooltipBody(body)

View File

@@ -38,7 +38,7 @@ object RedstoneCardItem {
super.fillRmbMenu(menu)
}
override val factory: Factory = Tier1.Factory
override val factory: Factory = RedstoneCardItem.Tier1.Factory
}
object Tier1 {
@@ -69,7 +69,7 @@ object RedstoneCardItem {
bundledIoWindow.fillRmbMenu(menu)
}
override val factory: Factory = Tier2.Factory
override val factory: Factory = RedstoneCardItem.Tier2.Factory
}
object Tier2 {

View File

@@ -25,7 +25,7 @@ object WirelessNetworkCardItem {
}
class Tier1(override val card: WirelessNetworkCard.Tier1) extends WirelessNetworkCardItem(card) {
override val factory: Factory = Tier1.Factory
override val factory: Factory = WirelessNetworkCardItem.Tier1.Factory
}
object Tier1 {
@@ -44,7 +44,7 @@ object WirelessNetworkCardItem {
}
class Tier2(override val card: WirelessNetworkCard.Tier2) extends WirelessNetworkCardItem(card) {
override val factory: Factory = Tier2.Factory
override val factory: Factory = WirelessNetworkCardItem.Tier2.Factory
}
object Tier2 {

View File

@@ -22,7 +22,11 @@ import totoro.ocelot.brain.util.Direction
import scala.collection.mutable.ArrayBuffer
abstract class Node(val entity: Entity with Environment)
extends Widget with DragHandler with ClickHandler with HoverHandler {
extends Widget
with DragHandler
with ClickHandler
with HoverHandler {
if (!OcelotDesktop.workspace.getEntitiesIter.contains(entity))
OcelotDesktop.workspace.add(entity)

View File

@@ -21,7 +21,7 @@ object NodeRegistry {
}
register(NodeType("Disk Drive", "nodes/DiskDrive", None) {
new DiskDriveNode(new FloppyDiskDrive(), true)
new DiskDriveNode(new FloppyDiskDrive(), initDisk = true)
})
for (tier <- Tier.One to Tier.Creative) {

View File

@@ -27,6 +27,9 @@ object ReflectionUtils {
merged.reverseIterator
}
/**
* Finds a (most specific) unary constructor of `constructedClass` that accepts `argumentClass` (or its subtype).
*/
def findUnaryConstructor[A](constructedClass: Class[A], argumentClass: Class[_]): Option[Constructor[A]] = {
try {
// happy case: just grab the constructor directly