mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-20 02:59:19 +01:00
89 lines
2.6 KiB
Scala
89 lines
2.6 KiB
Scala
package ocelot.desktop.node.nodes
|
|
|
|
import ocelot.desktop.color.IntColor
|
|
import ocelot.desktop.graphics.Graphics
|
|
import ocelot.desktop.inventory.SyncedInventory
|
|
import ocelot.desktop.inventory.item.FloppyItem
|
|
import ocelot.desktop.node.{EntityNode, LabeledEntityNode}
|
|
import ocelot.desktop.ui.widget.slot.FloppySlotWidget
|
|
import ocelot.desktop.windows.DiskDriveWindow
|
|
import totoro.ocelot.brain.entity.FloppyDiskDrive
|
|
import totoro.ocelot.brain.entity.traits.Inventory
|
|
import totoro.ocelot.brain.loot.Loot
|
|
import totoro.ocelot.brain.nbt.NBTTagCompound
|
|
import totoro.ocelot.brain.util.DyeColor
|
|
|
|
class DiskDriveNode(val diskDrive: FloppyDiskDrive, initDisk: Boolean)
|
|
extends EntityNode(diskDrive)
|
|
with LabeledEntityNode
|
|
with SyncedInventory {
|
|
|
|
def this(diskDrive: FloppyDiskDrive) = {
|
|
this(diskDrive, false)
|
|
}
|
|
|
|
override type I = FloppyItem
|
|
|
|
override def brainInventory: Inventory = diskDrive.inventory.owner
|
|
|
|
val slot: FloppySlotWidget = new FloppySlotWidget(Slot(0))
|
|
|
|
if (initDisk) {
|
|
slot.item = new FloppyItem.Factory.Loot(Loot.OpenOsFloppy).build()
|
|
}
|
|
|
|
override def load(nbt: NBTTagCompound): Unit = {
|
|
super[EntityNode].load(nbt)
|
|
super[SyncedInventory].load(nbt)
|
|
}
|
|
|
|
override def save(nbt: NBTTagCompound): Unit = {
|
|
super[EntityNode].save(nbt)
|
|
super[SyncedInventory].save(nbt)
|
|
}
|
|
|
|
override def icon: String = "nodes/DiskDrive"
|
|
|
|
override protected val canOpen = true
|
|
|
|
private val colorMap: Map[DyeColor, Int] = Map(
|
|
DyeColor.Black -> 0x444444, // 0x1E1B1B
|
|
DyeColor.Red -> 0xB3312C,
|
|
DyeColor.Green -> 0x339911, // 0x3B511A
|
|
DyeColor.Brown -> 0x51301A,
|
|
DyeColor.Blue -> 0x6666FF, // 0x253192
|
|
DyeColor.Purple -> 0x7B2FBE,
|
|
DyeColor.Cyan -> 0x66FFFF, // 0x287697
|
|
DyeColor.Silver -> 0xABABAB,
|
|
DyeColor.Gray -> 0x666666, // 0x434343
|
|
DyeColor.Pink -> 0xD88198,
|
|
DyeColor.Lime -> 0x66FF66, // 0x41CD34
|
|
DyeColor.Yellow -> 0xFFFF66, // 0xDECF2A
|
|
DyeColor.LightBlue -> 0xAAAAFF, // 0x6689D3
|
|
DyeColor.Magenta -> 0xC354CD,
|
|
DyeColor.Orange -> 0xEB8844,
|
|
DyeColor.White -> 0xF0F0F0
|
|
)
|
|
|
|
override def draw(g: Graphics): Unit = {
|
|
super.draw(g)
|
|
|
|
if (System.currentTimeMillis() - diskDrive.lastDiskAccess < 400 && Math.random() > 0.1) {
|
|
g.sprite("nodes/DiskDriveActivity", position.x + 2, position.y + 2, size.width - 4, size.height - 4)
|
|
}
|
|
|
|
for (item <- slot.item) {
|
|
g.sprite(
|
|
"nodes/DiskDriveFloppy",
|
|
position.x + 2,
|
|
position.y + 2,
|
|
size.width - 4,
|
|
size.height - 4,
|
|
IntColor(colorMap(item.color)),
|
|
)
|
|
}
|
|
}
|
|
|
|
override val window: Option[DiskDriveWindow] = Some(new DiskDriveWindow(this))
|
|
}
|