[Editor] Improve initial Java code comment in map object
This commit is contained in:
@@ -14,7 +14,7 @@ class CodeSnippetFragment : Fragment("Enter code") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override val root = borderpane {
|
override val root = borderpane {
|
||||||
setPrefSize(640.0, 480.0)
|
setPrefSize(800.0, 600.0)
|
||||||
|
|
||||||
center = editor.root
|
center = editor.root
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.bartlomiejpluta.base.editor.map.model.layer.TileLayer
|
|||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.BrushVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.BrushVM
|
||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM
|
||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
||||||
|
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||||
import com.bartlomiejpluta.base.editor.render.input.MapMouseEvent
|
import com.bartlomiejpluta.base.editor.render.input.MapMouseEvent
|
||||||
import com.bartlomiejpluta.base.editor.render.input.MapMouseEventHandler
|
import com.bartlomiejpluta.base.editor.render.input.MapMouseEventHandler
|
||||||
import com.bartlomiejpluta.base.editor.render.model.Renderable
|
import com.bartlomiejpluta.base.editor.render.model.Renderable
|
||||||
@@ -14,6 +15,7 @@ import javafx.scene.canvas.GraphicsContext
|
|||||||
import javafx.scene.input.MouseEvent
|
import javafx.scene.input.MouseEvent
|
||||||
|
|
||||||
class MapPainter(
|
class MapPainter(
|
||||||
|
private val projectContext: ProjectContext,
|
||||||
private val mapVM: GameMapVM,
|
private val mapVM: GameMapVM,
|
||||||
private val brushVM: BrushVM,
|
private val brushVM: BrushVM,
|
||||||
private val editorStateVM: EditorStateVM,
|
private val editorStateVM: EditorStateVM,
|
||||||
@@ -66,7 +68,7 @@ class MapPainter(
|
|||||||
currentTrace = when (editorStateVM.selectedLayer) {
|
currentTrace = when (editorStateVM.selectedLayer) {
|
||||||
is TileLayer -> TilePaintingTrace(mapVM, "Paint trace")
|
is TileLayer -> TilePaintingTrace(mapVM, "Paint trace")
|
||||||
is ObjectLayer -> when (brushVM.tool) {
|
is ObjectLayer -> when (brushVM.tool) {
|
||||||
BrushTool.DEFAULT -> ObjectPaintingTrace(mapVM, "Update object")
|
BrushTool.DEFAULT -> ObjectPaintingTrace(projectContext, mapVM, "Update object")
|
||||||
else -> PassageAbilityPaintingTrace(mapVM, "Toggle passage")
|
else -> PassageAbilityPaintingTrace(mapVM, "Toggle passage")
|
||||||
}
|
}
|
||||||
is ImageLayer -> ImagePositionPaintingTrace(mapVM, "Move Image Layer")
|
is ImageLayer -> ImagePositionPaintingTrace(mapVM, "Move Image Layer")
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import com.bartlomiejpluta.base.editor.map.model.obj.MapObject
|
|||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.BrushVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.BrushVM
|
||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM
|
||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
||||||
|
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||||
import com.bartlomiejpluta.base.editor.render.input.MapMouseEvent
|
import com.bartlomiejpluta.base.editor.render.input.MapMouseEvent
|
||||||
import javafx.collections.ObservableList
|
import javafx.collections.ObservableList
|
||||||
import javafx.scene.input.MouseButton
|
import javafx.scene.input.MouseButton
|
||||||
@@ -19,7 +20,11 @@ import tornadofx.find
|
|||||||
import tornadofx.setInScope
|
import tornadofx.setInScope
|
||||||
import tornadofx.toProperty
|
import tornadofx.toProperty
|
||||||
|
|
||||||
class ObjectPaintingTrace(val map: GameMapVM, override val commandName: String) : PaintingTrace {
|
class ObjectPaintingTrace(
|
||||||
|
private val projectContext: ProjectContext,
|
||||||
|
private val map: GameMapVM,
|
||||||
|
override val commandName: String
|
||||||
|
) : PaintingTrace {
|
||||||
private lateinit var objects: ObservableList<MapObject>
|
private lateinit var objects: ObservableList<MapObject>
|
||||||
private lateinit var event: MapMouseEvent
|
private lateinit var event: MapMouseEvent
|
||||||
|
|
||||||
@@ -77,16 +82,19 @@ class ObjectPaintingTrace(val map: GameMapVM, override val commandName: String)
|
|||||||
|
|
||||||
private val initialCode: String
|
private val initialCode: String
|
||||||
get() = """
|
get() = """
|
||||||
// In this place you can implement some logic
|
/*
|
||||||
// that will be evaluated for selected location.
|
* Following final parameters are available to use:
|
||||||
// Following references are available:
|
* x: int - the x coordinate of tile the object has been created on
|
||||||
// int x - the x coordinate
|
* y: int - the y coordinate of tile the object has been created on
|
||||||
// int y - the y coordinate
|
* handler: ${className(map.handler)} - current map handler
|
||||||
// Runner runner - the game runner
|
* runner: ${className(projectContext.project?.runner)} - the game runner of the project
|
||||||
// Context context - the game context
|
* context: Context - the game context
|
||||||
// Handler handler - current map handler
|
*/
|
||||||
|
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
|
private fun className(canonical: String?) = canonical?.substringAfterLast(".") ?: ""
|
||||||
|
|
||||||
private fun moveObject(newX: Int, newY: Int) {
|
private fun moveObject(newX: Int, newY: Int) {
|
||||||
if (newY >= map.rows || newX >= map.columns || newY < 0 || newX < 0) {
|
if (newY >= map.rows || newX >= map.columns || newY < 0 || newX < 0) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -6,18 +6,20 @@ import com.bartlomiejpluta.base.editor.map.canvas.PaintingTrace
|
|||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.BrushVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.BrushVM
|
||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM
|
||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
||||||
|
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||||
import com.bartlomiejpluta.base.editor.render.input.MapMouseEvent
|
import com.bartlomiejpluta.base.editor.render.input.MapMouseEvent
|
||||||
import javafx.event.EventHandler
|
import javafx.event.EventHandler
|
||||||
import javafx.scene.canvas.Canvas
|
import javafx.scene.canvas.Canvas
|
||||||
import javafx.scene.input.MouseEvent
|
import javafx.scene.input.MouseEvent
|
||||||
|
|
||||||
class MapPane(
|
class MapPane(
|
||||||
|
projectContext: ProjectContext,
|
||||||
private val mapVM: GameMapVM,
|
private val mapVM: GameMapVM,
|
||||||
brushVM: BrushVM,
|
brushVM: BrushVM,
|
||||||
editorStateVM: EditorStateVM,
|
editorStateVM: EditorStateVM,
|
||||||
paintingCallback: (PaintingTrace) -> Unit
|
paintingCallback: (PaintingTrace) -> Unit
|
||||||
) : Canvas(), EventHandler<MouseEvent> {
|
) : Canvas(), EventHandler<MouseEvent> {
|
||||||
private val painter = MapPainter(mapVM, brushVM, editorStateVM, paintingCallback)
|
private val painter = MapPainter(projectContext, mapVM, brushVM, editorStateVM, paintingCallback)
|
||||||
private val mapCanvas = MapCanvas(mapVM, editorStateVM, painter)
|
private val mapCanvas = MapCanvas(mapVM, editorStateVM, painter)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.bartlomiejpluta.base.editor.map.component.MapPane
|
|||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.BrushVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.BrushVM
|
||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM
|
||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
||||||
|
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||||
import javafx.scene.input.MouseButton
|
import javafx.scene.input.MouseButton
|
||||||
import javafx.scene.input.MouseEvent
|
import javafx.scene.input.MouseEvent
|
||||||
import javafx.scene.transform.Scale
|
import javafx.scene.transform.Scale
|
||||||
@@ -20,6 +21,8 @@ import tornadofx.scrollpane
|
|||||||
class MapView : View() {
|
class MapView : View() {
|
||||||
private val undoRedoService: UndoRedoService by di()
|
private val undoRedoService: UndoRedoService by di()
|
||||||
|
|
||||||
|
private val projectContext: ProjectContext by di()
|
||||||
|
|
||||||
override val scope = super.scope as UndoableScope
|
override val scope = super.scope as UndoableScope
|
||||||
|
|
||||||
private val mapVM = find<GameMapVM>()
|
private val mapVM = find<GameMapVM>()
|
||||||
@@ -28,7 +31,8 @@ class MapView : View() {
|
|||||||
|
|
||||||
private val editorStateVM = find<EditorStateVM>()
|
private val editorStateVM = find<EditorStateVM>()
|
||||||
|
|
||||||
private val mapPane = MapPane(mapVM, brushVM, editorStateVM, this::pushPaintingTraceToUndoRedoService)
|
private val mapPane =
|
||||||
|
MapPane(projectContext, mapVM, brushVM, editorStateVM, this::pushPaintingTraceToUndoRedoService)
|
||||||
|
|
||||||
private val zoom = Scale(1.0, 1.0, 0.0, 0.0).apply {
|
private val zoom = Scale(1.0, 1.0, 0.0, 0.0).apply {
|
||||||
xProperty().bind(editorStateVM.zoomProperty)
|
xProperty().bind(editorStateVM.zoomProperty)
|
||||||
|
|||||||
Reference in New Issue
Block a user