From 3c8a1e6d5e76dc7f21c602722a98c302501f19e7 Mon Sep 17 00:00:00 2001 From: Martin Jakobsson Date: Fri, 7 Jun 2024 20:59:06 +0200 Subject: [PATCH] Refactor: Moved lots of files to the core module --- app/src/main/scala/tripaint/TriPaint.scala | 2 +- .../tripaint/{model => }/TriPaintModel.scala | 2 +- .../main/scala/tripaint/control/Actions.scala | 4 +-- .../tripaint/control/TriPaintController.scala | 6 ++-- .../tripaint/view/TriPaintViewFactory.scala | 2 +- .../tripaint/view/gui/ImageTabPane.scala | 19 +++++++++-- .../scala/tripaint/view/gui/MainStage.scala | 4 +-- .../view/image/TriImageForPreview.scala | 1 + .../ActionsTest.scala} | 31 ++++------------- .../control/action/NewActionTest.scala | 2 +- .../control/action/OpenActionTest.scala | 2 +- .../src/main/scala/tripaint}/Change.scala | 2 +- .../scala/tripaint}/effects/BlurEffect.scala | 2 +- .../scala/tripaint}/effects/CellEffect.scala | 2 +- .../main/scala/tripaint}/effects/Effect.scala | 2 +- .../scala/tripaint}/effects/LocalEffect.scala | 2 +- .../tripaint}/effects/MotionBlurEffect.scala | 2 +- .../tripaint}/effects/RandomNoiseEffect.scala | 2 +- .../tripaint}/effects/ScrambleEffect.scala | 2 +- .../main/scala/tripaint/grid/GridCell.scala | 34 +++++++++++++------ .../scala/tripaint/grid/ImageChange.scala | 2 +- .../main/scala/tripaint/grid/ImageGrid.scala | 1 + .../scala/tripaint/grid/ImageGridChange.scala | 2 +- .../tripaint/grid/ImageGridColorLookup.scala | 0 .../grid/ImageSaveCollisionHandler.scala | 0 .../scala/tripaint/grid/UndoManager.scala | 2 +- .../main/scala/tripaint/image/ImagePool.scala | 1 - .../tripaint}/effects/BlurEffectTest.scala | 2 +- .../tripaint}/effects/CellEffectTest.scala | 2 +- .../scala/tripaint/grid/GridCellTest.scala | 0 .../grid/ImageGridColorLookupTest.scala | 0 .../scala/tripaint/grid/ImageGridTest.scala | 8 ++--- .../scala/tripaint/image/ImagePoolTest.scala | 26 ++++++++++++++ 33 files changed, 104 insertions(+), 67 deletions(-) rename app/src/main/scala/tripaint/{model => }/TriPaintModel.scala (96%) rename app/src/test/scala/tripaint/{image/ImagePoolTest.scala => control/ActionsTest.scala} (78%) rename {app/src/main/scala/tripaint/model => core/src/main/scala/tripaint}/Change.scala (71%) rename {app/src/main/scala/tripaint/model => core/src/main/scala/tripaint}/effects/BlurEffect.scala (95%) rename {app/src/main/scala/tripaint/model => core/src/main/scala/tripaint}/effects/CellEffect.scala (94%) rename {app/src/main/scala/tripaint/model => core/src/main/scala/tripaint}/effects/Effect.scala (84%) rename {app/src/main/scala/tripaint/model => core/src/main/scala/tripaint}/effects/LocalEffect.scala (97%) rename {app/src/main/scala/tripaint/model => core/src/main/scala/tripaint}/effects/MotionBlurEffect.scala (95%) rename {app/src/main/scala/tripaint/model => core/src/main/scala/tripaint}/effects/RandomNoiseEffect.scala (96%) rename {app/src/main/scala/tripaint/model => core/src/main/scala/tripaint}/effects/ScrambleEffect.scala (94%) rename {app => core}/src/main/scala/tripaint/grid/GridCell.scala (62%) rename {app => core}/src/main/scala/tripaint/grid/ImageChange.scala (97%) rename {app => core}/src/main/scala/tripaint/grid/ImageGrid.scala (99%) rename {app => core}/src/main/scala/tripaint/grid/ImageGridChange.scala (90%) rename {app => core}/src/main/scala/tripaint/grid/ImageGridColorLookup.scala (100%) rename {app => core}/src/main/scala/tripaint/grid/ImageSaveCollisionHandler.scala (100%) rename {app => core}/src/main/scala/tripaint/grid/UndoManager.scala (95%) rename {app => core}/src/main/scala/tripaint/image/ImagePool.scala (97%) rename {app/src/test/scala/tripaint/model => core/src/test/scala/tripaint}/effects/BlurEffectTest.scala (99%) rename {app/src/test/scala/tripaint/model => core/src/test/scala/tripaint}/effects/CellEffectTest.scala (98%) rename {app => core}/src/test/scala/tripaint/grid/GridCellTest.scala (100%) rename {app => core}/src/test/scala/tripaint/grid/ImageGridColorLookupTest.scala (100%) rename {app => core}/src/test/scala/tripaint/grid/ImageGridTest.scala (98%) create mode 100644 core/src/test/scala/tripaint/image/ImagePoolTest.scala diff --git a/app/src/main/scala/tripaint/TriPaint.scala b/app/src/main/scala/tripaint/TriPaint.scala index 36c732f..49c77da 100644 --- a/app/src/main/scala/tripaint/TriPaint.scala +++ b/app/src/main/scala/tripaint/TriPaint.scala @@ -1,7 +1,7 @@ package tripaint +import tripaint.TriPaintModel import tripaint.control.TriPaintController -import tripaint.model.TriPaintModel import tripaint.view.gui.MainStage import scalafx.application.{JFXApp3, Platform} diff --git a/app/src/main/scala/tripaint/model/TriPaintModel.scala b/app/src/main/scala/tripaint/TriPaintModel.scala similarity index 96% rename from app/src/main/scala/tripaint/model/TriPaintModel.scala rename to app/src/main/scala/tripaint/TriPaintModel.scala index 4bc2ed3..cfa31b4 100644 --- a/app/src/main/scala/tripaint/model/TriPaintModel.scala +++ b/app/src/main/scala/tripaint/TriPaintModel.scala @@ -1,4 +1,4 @@ -package tripaint.model +package tripaint import tripaint.grid.ImageGrid import tripaint.image.ImagePool diff --git a/app/src/main/scala/tripaint/control/Actions.scala b/app/src/main/scala/tripaint/control/Actions.scala index 7c4eaf5..5d7205e 100644 --- a/app/src/main/scala/tripaint/control/Actions.scala +++ b/app/src/main/scala/tripaint/control/Actions.scala @@ -1,14 +1,14 @@ package tripaint.control import tripaint.{Color, ImageSaver} +import tripaint.TriPaintModel import tripaint.coords.{GridCoords, StorageCoords} +import tripaint.effects.Effect import tripaint.grid.{GridCell, ImageChange, ImageGrid, ImageGridChange, ImageSaveCollisionHandler} import tripaint.image.{ImagePool, ImageStorage, RegularImage} import tripaint.image.ImagePool.{SaveInfo, SaveLocation} import tripaint.image.format.StorageFormat import tripaint.infrastructure.FileSystem -import tripaint.model.TriPaintModel -import tripaint.model.effects.Effect import tripaint.util.CachedLoader import tripaint.view.{FileOpenSettings, FileSaveSettings} diff --git a/app/src/main/scala/tripaint/control/TriPaintController.scala b/app/src/main/scala/tripaint/control/TriPaintController.scala index 350ccf9..48c915f 100644 --- a/app/src/main/scala/tripaint/control/TriPaintController.scala +++ b/app/src/main/scala/tripaint/control/TriPaintController.scala @@ -1,15 +1,15 @@ package tripaint.control +import tripaint.TriPaintModel import tripaint.coords.GridCoords -import tripaint.grid.GridCell -import tripaint.model.TriPaintModel -import tripaint.model.effects.{ +import tripaint.effects.{ BlurEffect, CellEffect, MotionBlurEffect, RandomNoiseEffect, ScrambleEffect } +import tripaint.grid.GridCell import tripaint.view.{TriPaintView, TriPaintViewFactory, TriPaintViewListener} import tripaint.view.gui.UIAction diff --git a/app/src/main/scala/tripaint/view/TriPaintViewFactory.scala b/app/src/main/scala/tripaint/view/TriPaintViewFactory.scala index a8eec3a..bf71048 100644 --- a/app/src/main/scala/tripaint/view/TriPaintViewFactory.scala +++ b/app/src/main/scala/tripaint/view/TriPaintViewFactory.scala @@ -1,6 +1,6 @@ package tripaint.view -import tripaint.model.TriPaintModel +import tripaint.TriPaintModel trait TriPaintViewFactory { def createView(controls: TriPaintViewListener, model: TriPaintModel): TriPaintView diff --git a/app/src/main/scala/tripaint/view/gui/ImageTabPane.scala b/app/src/main/scala/tripaint/view/gui/ImageTabPane.scala index bfea7fd..89832f7 100644 --- a/app/src/main/scala/tripaint/view/gui/ImageTabPane.scala +++ b/app/src/main/scala/tripaint/view/gui/ImageTabPane.scala @@ -30,7 +30,16 @@ object ImageTabPane { val b = new ToggleButton b.graphic = preview b.tooltip = TriImageTooltip.fromImagePool(image, imagePool.locationOf) - b.selected <==> image.editableProperty + + image.trackChanges { + case GridCell.Event.StateUpdated(editable, _) => + b.selected = editable + case _ => + } + b.selected.onChange { (_, _, selected) => + image.setEditable(selected) + } + b } @@ -56,7 +65,13 @@ object ImageTabPane { star.image = new Image("/icons/star.png") star.alignmentInParent = Pos.TopLeft star.mouseTransparent = true - star.visible <== image.changedProperty + + image.trackChanges { + case GridCell.Event.StateUpdated(_, changed) => + star.visible = changed + case _ => + } + star } } diff --git a/app/src/main/scala/tripaint/view/gui/MainStage.scala b/app/src/main/scala/tripaint/view/gui/MainStage.scala index 806e8c5..85f5bb6 100644 --- a/app/src/main/scala/tripaint/view/gui/MainStage.scala +++ b/app/src/main/scala/tripaint/view/gui/MainStage.scala @@ -2,11 +2,11 @@ package tripaint.view.gui import tripaint.Color import tripaint.ScalaFxExt.{*, given} +import tripaint.TriPaintModel +import tripaint.effects.{BlurEffect, MotionBlurEffect, RandomNoiseEffect} import tripaint.grid.GridCell import tripaint.image.{ImagePool, ImageStorage} import tripaint.image.format.{RecursiveStorageFormat, SimpleStorageFormat} -import tripaint.model.TriPaintModel -import tripaint.model.effects.{BlurEffect, MotionBlurEffect, RandomNoiseEffect} import tripaint.view.{ EditMode, FileOpenSettings, diff --git a/app/src/main/scala/tripaint/view/image/TriImageForPreview.scala b/app/src/main/scala/tripaint/view/image/TriImageForPreview.scala index 379b685..4b81eeb 100644 --- a/app/src/main/scala/tripaint/view/image/TriImageForPreview.scala +++ b/app/src/main/scala/tripaint/view/image/TriImageForPreview.scala @@ -36,6 +36,7 @@ class TriImageForPreview(content: GridCell, previewWidth: Double) extends Pane { drawTriangle(coords) case ImageChangedALot => redraw() + case _ => } } diff --git a/app/src/test/scala/tripaint/image/ImagePoolTest.scala b/app/src/test/scala/tripaint/control/ActionsTest.scala similarity index 78% rename from app/src/test/scala/tripaint/image/ImagePoolTest.scala rename to app/src/test/scala/tripaint/control/ActionsTest.scala index 2881dfb..bb7a697 100644 --- a/app/src/test/scala/tripaint/image/ImagePoolTest.scala +++ b/app/src/test/scala/tripaint/control/ActionsTest.scala @@ -1,40 +1,23 @@ -package tripaint.image +package tripaint.control -import munit.FunSuite -import scalafx.scene.paint.Color as FXColor -import tripaint.Color import tripaint.ScalaFxExt.given -import tripaint.control.Actions +import tripaint.TriPaintModel import tripaint.coords.{GridCoords, StorageCoords} -import tripaint.image.{ImagePool, ImageStorage, RegularImage} +import tripaint.image.{ImageStorage, RegularImage} import tripaint.image.ImagePool.SaveLocation import tripaint.image.format.{SimpleStorageFormat, StorageFormat} import tripaint.infrastructure.FileSystem -import tripaint.model.TriPaintModel import tripaint.view.FileOpenSettings +import munit.FunSuite +import scalafx.scene.paint.Color as FXColor + import java.io.File import scala.language.implicitConversions -class ImagePoolTest extends FunSuite { +class ActionsTest extends FunSuite { val storageFormat: StorageFormat = SimpleStorageFormat - test("locationOf should return None if the image doesn't exist") { - val image = ImageStorage.fill(2, Color.Black) - assertEquals(new ImagePool().locationOf(image), None) - } - - test("locationOf should return the location of the image if it exists") { - val image = ImageStorage.fill(2, Color.Black) - val location = SaveLocation(null) - val info = ImagePool.SaveInfo(null) - - val f = new ImagePool() - f.set(image, location, info) - - assertEquals(f.locationOf(image), Some(location)) - } - test("Actions.openImage should do nothing if loading failed") { val location = SaveLocation(null) val imageSize = 16 diff --git a/app/src/test/scala/tripaint/control/action/NewActionTest.scala b/app/src/test/scala/tripaint/control/action/NewActionTest.scala index 47242c8..81a78d9 100644 --- a/app/src/test/scala/tripaint/control/action/NewActionTest.scala +++ b/app/src/test/scala/tripaint/control/action/NewActionTest.scala @@ -1,11 +1,11 @@ package tripaint.control.action import tripaint.Color +import tripaint.TriPaintModel import tripaint.control.Actions import tripaint.coords.GridCoords import tripaint.image.RegularImage import tripaint.image.format.SimpleStorageFormat -import tripaint.model.TriPaintModel import munit.FunSuite diff --git a/app/src/test/scala/tripaint/control/action/OpenActionTest.scala b/app/src/test/scala/tripaint/control/action/OpenActionTest.scala index 703e098..1328ab5 100644 --- a/app/src/test/scala/tripaint/control/action/OpenActionTest.scala +++ b/app/src/test/scala/tripaint/control/action/OpenActionTest.scala @@ -1,12 +1,12 @@ package tripaint.control.action import tripaint.Color +import tripaint.TriPaintModel import tripaint.control.Actions import tripaint.coords.{GridCoords, StorageCoords} import tripaint.image.RegularImage import tripaint.image.format.SimpleStorageFormat import tripaint.infrastructure.FileSystem -import tripaint.model.TriPaintModel import tripaint.view.FileOpenSettings import munit.FunSuite diff --git a/app/src/main/scala/tripaint/model/Change.scala b/core/src/main/scala/tripaint/Change.scala similarity index 71% rename from app/src/main/scala/tripaint/model/Change.scala rename to core/src/main/scala/tripaint/Change.scala index b8988dd..febfd0a 100644 --- a/app/src/main/scala/tripaint/model/Change.scala +++ b/core/src/main/scala/tripaint/Change.scala @@ -1,4 +1,4 @@ -package tripaint.model +package tripaint trait Change { def undo(): Unit diff --git a/app/src/main/scala/tripaint/model/effects/BlurEffect.scala b/core/src/main/scala/tripaint/effects/BlurEffect.scala similarity index 95% rename from app/src/main/scala/tripaint/model/effects/BlurEffect.scala rename to core/src/main/scala/tripaint/effects/BlurEffect.scala index eba91b8..8c3438e 100644 --- a/app/src/main/scala/tripaint/model/effects/BlurEffect.scala +++ b/core/src/main/scala/tripaint/effects/BlurEffect.scala @@ -1,4 +1,4 @@ -package tripaint.model.effects +package tripaint.effects import tripaint.{Color, ColorLookup} import tripaint.coords.GlobalPixCoords diff --git a/app/src/main/scala/tripaint/model/effects/CellEffect.scala b/core/src/main/scala/tripaint/effects/CellEffect.scala similarity index 94% rename from app/src/main/scala/tripaint/model/effects/CellEffect.scala rename to core/src/main/scala/tripaint/effects/CellEffect.scala index 2928935..bf2aea1 100644 --- a/app/src/main/scala/tripaint/model/effects/CellEffect.scala +++ b/core/src/main/scala/tripaint/effects/CellEffect.scala @@ -1,4 +1,4 @@ -package tripaint.model.effects +package tripaint.effects import tripaint.{Color, ColorLookup} import tripaint.coords.GlobalPixCoords diff --git a/app/src/main/scala/tripaint/model/effects/Effect.scala b/core/src/main/scala/tripaint/effects/Effect.scala similarity index 84% rename from app/src/main/scala/tripaint/model/effects/Effect.scala rename to core/src/main/scala/tripaint/effects/Effect.scala index f83dac6..849b6d6 100644 --- a/app/src/main/scala/tripaint/model/effects/Effect.scala +++ b/core/src/main/scala/tripaint/effects/Effect.scala @@ -1,4 +1,4 @@ -package tripaint.model.effects +package tripaint.effects import tripaint.coords.GridCoords import tripaint.grid.ImageGrid diff --git a/app/src/main/scala/tripaint/model/effects/LocalEffect.scala b/core/src/main/scala/tripaint/effects/LocalEffect.scala similarity index 97% rename from app/src/main/scala/tripaint/model/effects/LocalEffect.scala rename to core/src/main/scala/tripaint/effects/LocalEffect.scala index 6fc0248..84e5e83 100644 --- a/app/src/main/scala/tripaint/model/effects/LocalEffect.scala +++ b/core/src/main/scala/tripaint/effects/LocalEffect.scala @@ -1,4 +1,4 @@ -package tripaint.model.effects +package tripaint.effects import tripaint.{Color, ColorLookup, FloodFillSearcher} import tripaint.coords.{GlobalPixCoords, GridCoords, PixelCoords} diff --git a/app/src/main/scala/tripaint/model/effects/MotionBlurEffect.scala b/core/src/main/scala/tripaint/effects/MotionBlurEffect.scala similarity index 95% rename from app/src/main/scala/tripaint/model/effects/MotionBlurEffect.scala rename to core/src/main/scala/tripaint/effects/MotionBlurEffect.scala index 0198434..d2ac9b1 100644 --- a/app/src/main/scala/tripaint/model/effects/MotionBlurEffect.scala +++ b/core/src/main/scala/tripaint/effects/MotionBlurEffect.scala @@ -1,4 +1,4 @@ -package tripaint.model.effects +package tripaint.effects import tripaint.{Color, ColorLookup} import tripaint.coords.GlobalPixCoords diff --git a/app/src/main/scala/tripaint/model/effects/RandomNoiseEffect.scala b/core/src/main/scala/tripaint/effects/RandomNoiseEffect.scala similarity index 96% rename from app/src/main/scala/tripaint/model/effects/RandomNoiseEffect.scala rename to core/src/main/scala/tripaint/effects/RandomNoiseEffect.scala index b4c66e2..d6374af 100644 --- a/app/src/main/scala/tripaint/model/effects/RandomNoiseEffect.scala +++ b/core/src/main/scala/tripaint/effects/RandomNoiseEffect.scala @@ -1,4 +1,4 @@ -package tripaint.model.effects +package tripaint.effects import tripaint.{Color, HsbColor} import tripaint.coords.GridCoords diff --git a/app/src/main/scala/tripaint/model/effects/ScrambleEffect.scala b/core/src/main/scala/tripaint/effects/ScrambleEffect.scala similarity index 94% rename from app/src/main/scala/tripaint/model/effects/ScrambleEffect.scala rename to core/src/main/scala/tripaint/effects/ScrambleEffect.scala index fd506f3..30afc1f 100644 --- a/app/src/main/scala/tripaint/model/effects/ScrambleEffect.scala +++ b/core/src/main/scala/tripaint/effects/ScrambleEffect.scala @@ -1,4 +1,4 @@ -package tripaint.model.effects +package tripaint.effects import tripaint.coords.GridCoords import tripaint.grid.ImageGrid diff --git a/app/src/main/scala/tripaint/grid/GridCell.scala b/core/src/main/scala/tripaint/grid/GridCell.scala similarity index 62% rename from app/src/main/scala/tripaint/grid/GridCell.scala rename to core/src/main/scala/tripaint/grid/GridCell.scala index befb49b..f30258a 100644 --- a/app/src/main/scala/tripaint/grid/GridCell.scala +++ b/core/src/main/scala/tripaint/grid/GridCell.scala @@ -5,12 +5,13 @@ import tripaint.coords.{GridCoords, TriangleCoords} import tripaint.image.ImageStorage import tripaint.util.{EventDispatcher, Tracker} -import scalafx.beans.property.{BooleanProperty, ReadOnlyBooleanProperty, ReadOnlyBooleanWrapper} - -object GridCell: - enum Event: +object GridCell { + enum Event { case PixelChanged(coords: TriangleCoords, from: Color, to: Color) case ImageChangedALot + case StateUpdated(editable: Boolean, changed: Boolean) + } +} class GridCell(val coords: GridCoords, init_image: ImageStorage): private var _image: ImageStorage = init_image @@ -22,17 +23,25 @@ class GridCell(val coords: GridCoords, init_image: ImageStorage): def storage: ImageStorage = _image - val editableProperty: BooleanProperty = BooleanProperty(true) - def editable: Boolean = editableProperty.value + private var _editable = true + def editable: Boolean = _editable + def setEditable(editable: Boolean): Unit = { + _editable = editable + dispatcher.notify(GridCell.Event.StateUpdated(editable, changed)) + } def onImageChangedALot(): Unit = dispatcher.notify(GridCell.Event.ImageChangedALot) - private val _changed: ReadOnlyBooleanWrapper = ReadOnlyBooleanWrapper(false) - def changed: Boolean = _changed.value - def changedProperty: ReadOnlyBooleanProperty = _changed.readOnlyProperty + private var _changed = false + def changed: Boolean = _changed - def setImageSaved(): Unit = _changed.value = false + def setImageSaved(): Unit = { + if _changed then { + _changed = false + dispatcher.notify(GridCell.Event.StateUpdated(editable, changed)) + } + } def replaceImage(newImage: ImageStorage): Unit = _image = newImage @@ -42,5 +51,8 @@ class GridCell(val coords: GridCoords, init_image: ImageStorage): private def onStorageChanged(event: ImageStorage.Event): Unit = event match case ImageStorage.Event.PixelChanged(coords, from, to) => - _changed.value = true + if !_changed then { + _changed = true + dispatcher.notify(GridCell.Event.StateUpdated(editable, changed)) + } dispatcher.notify(GridCell.Event.PixelChanged(coords, from, to)) diff --git a/app/src/main/scala/tripaint/grid/ImageChange.scala b/core/src/main/scala/tripaint/grid/ImageChange.scala similarity index 97% rename from app/src/main/scala/tripaint/grid/ImageChange.scala rename to core/src/main/scala/tripaint/grid/ImageChange.scala index 901e411..062b129 100644 --- a/app/src/main/scala/tripaint/grid/ImageChange.scala +++ b/core/src/main/scala/tripaint/grid/ImageChange.scala @@ -1,9 +1,9 @@ package tripaint.grid +import tripaint.Change import tripaint.Color import tripaint.coords.TriangleCoords import tripaint.image.ImageStorage -import tripaint.model.Change import scala.collection.mutable.ArrayBuffer diff --git a/app/src/main/scala/tripaint/grid/ImageGrid.scala b/core/src/main/scala/tripaint/grid/ImageGrid.scala similarity index 99% rename from app/src/main/scala/tripaint/grid/ImageGrid.scala rename to core/src/main/scala/tripaint/grid/ImageGrid.scala index a06f126..c8de472 100644 --- a/app/src/main/scala/tripaint/grid/ImageGrid.scala +++ b/core/src/main/scala/tripaint/grid/ImageGrid.scala @@ -153,6 +153,7 @@ class ImageGrid(init_imageSize: Int) { dispatcher.notify(ImageGrid.Event.PixelChanged(PixelCoords(cell, pix), from, to)) case GridCell.Event.ImageChangedALot => dispatcher.notify(ImageGrid.Event.ImageChangedALot(cell)) + case _ => } } } diff --git a/app/src/main/scala/tripaint/grid/ImageGridChange.scala b/core/src/main/scala/tripaint/grid/ImageGridChange.scala similarity index 90% rename from app/src/main/scala/tripaint/grid/ImageGridChange.scala rename to core/src/main/scala/tripaint/grid/ImageGridChange.scala index 7737b7f..6b68fe9 100644 --- a/app/src/main/scala/tripaint/grid/ImageGridChange.scala +++ b/core/src/main/scala/tripaint/grid/ImageGridChange.scala @@ -1,7 +1,7 @@ package tripaint.grid +import tripaint.Change import tripaint.coords.GridCoords -import tripaint.model.Change class ImageGridChange(val changes: Map[GridCoords, ImageChange]) extends Change { override def undo(): Unit = for (_, change) <- changes do change.undo() diff --git a/app/src/main/scala/tripaint/grid/ImageGridColorLookup.scala b/core/src/main/scala/tripaint/grid/ImageGridColorLookup.scala similarity index 100% rename from app/src/main/scala/tripaint/grid/ImageGridColorLookup.scala rename to core/src/main/scala/tripaint/grid/ImageGridColorLookup.scala diff --git a/app/src/main/scala/tripaint/grid/ImageSaveCollisionHandler.scala b/core/src/main/scala/tripaint/grid/ImageSaveCollisionHandler.scala similarity index 100% rename from app/src/main/scala/tripaint/grid/ImageSaveCollisionHandler.scala rename to core/src/main/scala/tripaint/grid/ImageSaveCollisionHandler.scala diff --git a/app/src/main/scala/tripaint/grid/UndoManager.scala b/core/src/main/scala/tripaint/grid/UndoManager.scala similarity index 95% rename from app/src/main/scala/tripaint/grid/UndoManager.scala rename to core/src/main/scala/tripaint/grid/UndoManager.scala index cb2ef98..82cb103 100644 --- a/app/src/main/scala/tripaint/grid/UndoManager.scala +++ b/core/src/main/scala/tripaint/grid/UndoManager.scala @@ -1,6 +1,6 @@ package tripaint.grid -import tripaint.model.Change +import tripaint.Change import scala.collection.mutable.ArrayBuffer diff --git a/app/src/main/scala/tripaint/image/ImagePool.scala b/core/src/main/scala/tripaint/image/ImagePool.scala similarity index 97% rename from app/src/main/scala/tripaint/image/ImagePool.scala rename to core/src/main/scala/tripaint/image/ImagePool.scala index 4e1d65a..2a909e4 100644 --- a/app/src/main/scala/tripaint/image/ImagePool.scala +++ b/core/src/main/scala/tripaint/image/ImagePool.scala @@ -1,7 +1,6 @@ package tripaint.image import tripaint.coords.StorageCoords -import tripaint.image.ImageStorage import tripaint.image.format.StorageFormat import tripaint.util.{InjectiveHashMap, InjectiveMap} diff --git a/app/src/test/scala/tripaint/model/effects/BlurEffectTest.scala b/core/src/test/scala/tripaint/effects/BlurEffectTest.scala similarity index 99% rename from app/src/test/scala/tripaint/model/effects/BlurEffectTest.scala rename to core/src/test/scala/tripaint/effects/BlurEffectTest.scala index 6f3dfe2..5ce5bff 100644 --- a/app/src/test/scala/tripaint/model/effects/BlurEffectTest.scala +++ b/core/src/test/scala/tripaint/effects/BlurEffectTest.scala @@ -1,4 +1,4 @@ -package tripaint.model.effects +package tripaint.effects import tripaint.Color import tripaint.coords.{GlobalPixCoords, GridCoords, PixelCoords, TriangleCoords} diff --git a/app/src/test/scala/tripaint/model/effects/CellEffectTest.scala b/core/src/test/scala/tripaint/effects/CellEffectTest.scala similarity index 98% rename from app/src/test/scala/tripaint/model/effects/CellEffectTest.scala rename to core/src/test/scala/tripaint/effects/CellEffectTest.scala index 5eda378..d09d747 100644 --- a/app/src/test/scala/tripaint/model/effects/CellEffectTest.scala +++ b/core/src/test/scala/tripaint/effects/CellEffectTest.scala @@ -1,4 +1,4 @@ -package tripaint.model.effects +package tripaint.effects import tripaint.Color import tripaint.coords.{GridCoords, TriangleCoords} diff --git a/app/src/test/scala/tripaint/grid/GridCellTest.scala b/core/src/test/scala/tripaint/grid/GridCellTest.scala similarity index 100% rename from app/src/test/scala/tripaint/grid/GridCellTest.scala rename to core/src/test/scala/tripaint/grid/GridCellTest.scala diff --git a/app/src/test/scala/tripaint/grid/ImageGridColorLookupTest.scala b/core/src/test/scala/tripaint/grid/ImageGridColorLookupTest.scala similarity index 100% rename from app/src/test/scala/tripaint/grid/ImageGridColorLookupTest.scala rename to core/src/test/scala/tripaint/grid/ImageGridColorLookupTest.scala diff --git a/app/src/test/scala/tripaint/grid/ImageGridTest.scala b/core/src/test/scala/tripaint/grid/ImageGridTest.scala similarity index 98% rename from app/src/test/scala/tripaint/grid/ImageGridTest.scala rename to core/src/test/scala/tripaint/grid/ImageGridTest.scala index becb48d..e06f136 100644 --- a/app/src/test/scala/tripaint/grid/ImageGridTest.scala +++ b/core/src/test/scala/tripaint/grid/ImageGridTest.scala @@ -146,12 +146,12 @@ class ImageGridTest extends FunSuite with MockitoSugar { f.set(image2) assertEquals(f.selectedImages.sortBy(_.##), Seq(image, image2).sortBy(_.##)) - image.editableProperty() = false + image.setEditable(false) assertEquals(f.selectedImages.sortBy(_.##), Seq(image2).sortBy(_.##)) - image.editableProperty() = true - image2.editableProperty() = false + image.setEditable(true) + image2.setEditable(false) assertEquals(f.selectedImages.sortBy(_.##), Seq(image).sortBy(_.##)) - image2.editableProperty() = true + image2.setEditable(true) assertEquals(f.selectedImages.sortBy(_.##), Seq(image, image2).sortBy(_.##)) } diff --git a/core/src/test/scala/tripaint/image/ImagePoolTest.scala b/core/src/test/scala/tripaint/image/ImagePoolTest.scala new file mode 100644 index 0000000..3c6fd86 --- /dev/null +++ b/core/src/test/scala/tripaint/image/ImagePoolTest.scala @@ -0,0 +1,26 @@ +package tripaint.image + +import munit.FunSuite +import tripaint.Color +import tripaint.image.ImagePool.SaveLocation +import tripaint.image.format.{SimpleStorageFormat, StorageFormat} + +class ImagePoolTest extends FunSuite { + val storageFormat: StorageFormat = SimpleStorageFormat + + test("locationOf should return None if the image doesn't exist") { + val image = ImageStorage.fill(2, Color.Black) + assertEquals(new ImagePool().locationOf(image), None) + } + + test("locationOf should return the location of the image if it exists") { + val image = ImageStorage.fill(2, Color.Black) + val location = SaveLocation(null) + val info = ImagePool.SaveInfo(null) + + val f = new ImagePool() + f.set(image, location, info) + + assertEquals(f.locationOf(image), Some(location)) + } +}