[Editor] Enable generating constant with UID in MapHandler classes
This commit is contained in:
@@ -30,7 +30,12 @@ class JavaClassService {
|
|||||||
fun ofPath(path: String): String = ofPath(Path.of(path))
|
fun ofPath(path: String): String = ofPath(Path.of(path))
|
||||||
fun ofPath(path: Path): String = path.joinToString(".")
|
fun ofPath(path: Path): String = path.joinToString(".")
|
||||||
|
|
||||||
fun createClassFile(name: String, directory: FileSystemNode, classTemplate: String) {
|
fun createClassFile(
|
||||||
|
name: String,
|
||||||
|
directory: FileSystemNode,
|
||||||
|
classTemplate: String,
|
||||||
|
inflate: (MutableMap<String, String>) -> Unit = {}
|
||||||
|
) {
|
||||||
projectContext.project?.let { project ->
|
projectContext.project?.let { project ->
|
||||||
val template = config.getTemplate(classTemplate)
|
val template = config.getTemplate(classTemplate)
|
||||||
|
|
||||||
@@ -42,7 +47,7 @@ class JavaClassService {
|
|||||||
|
|
||||||
project.codeFSNode.createNode(classFile.toRelativeString(project.codeFSNode.file))
|
project.codeFSNode.createNode(classFile.toRelativeString(project.codeFSNode.file))
|
||||||
|
|
||||||
val model = mapOf("className" to className, "package" to classPackage)
|
val model = mutableMapOf("className" to className, "package" to classPackage).apply(inflate).toMap()
|
||||||
template.process(model, classFile.writer())
|
template.process(model, classFile.writer())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import tornadofx.setValue
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
class DefaultProjectContext : ProjectContext {
|
class DefaultProjectContext : ProjectContext {
|
||||||
@@ -102,7 +103,11 @@ class DefaultProjectContext : ProjectContext {
|
|||||||
it.maps += asset
|
it.maps += asset
|
||||||
|
|
||||||
save()
|
save()
|
||||||
javaClassService.createClassFile(map.handler, it.codeFSNode, "map_handler.ftl")
|
|
||||||
|
javaClassService.createClassFile(map.handler, it.codeFSNode, "map_handler.ftl") { model ->
|
||||||
|
model["mapUid"] = uid
|
||||||
|
}
|
||||||
|
|
||||||
File(it.mapsDirectory, asset.source).outputStream().use { fos -> mapSerializer.serialize(map, fos) }
|
File(it.mapsDirectory, asset.source).outputStream().use { fos -> mapSerializer.serialize(map, fos) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,7 +255,7 @@ class DefaultProjectContext : ProjectContext {
|
|||||||
override fun loadScript(fileNode: FileNode, execute: ((String) -> Unit)?, saveable: Boolean): Code {
|
override fun loadScript(fileNode: FileNode, execute: ((String) -> Unit)?, saveable: Boolean): Code {
|
||||||
val typeProperty = SimpleObjectProperty<CodeType>().apply {
|
val typeProperty = SimpleObjectProperty<CodeType>().apply {
|
||||||
bind(createObjectBinding({
|
bind(createObjectBinding({
|
||||||
when (fileNode.extension.toLowerCase()) {
|
when (fileNode.extension.lowercase(Locale.getDefault())) {
|
||||||
"java" -> CodeType.JAVA
|
"java" -> CodeType.JAVA
|
||||||
"xml" -> CodeType.XML
|
"xml" -> CodeType.XML
|
||||||
"sql" -> CodeType.SQL
|
"sql" -> CodeType.SQL
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.bartlomiejpluta.base.api.map.handler.MapHandler;
|
|||||||
import com.bartlomiejpluta.base.api.screen.Screen;
|
import com.bartlomiejpluta.base.api.screen.Screen;
|
||||||
|
|
||||||
public class ${className} implements MapHandler {
|
public class ${className} implements MapHandler {
|
||||||
|
public static final String UID = "${mapUid}";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Context context, GameMap map) {
|
public void onCreate(Context context, GameMap map) {
|
||||||
|
|||||||
Reference in New Issue
Block a user