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