Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

206 support cleanup #15

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ sources

# Ignore Gradle build output directory
build
.idea
.idea
paths.txt
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ buildscript {
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version "$kotlin_version"
id 'application'
}

archivesBaseName = 'cs2-editor'
Expand All @@ -35,6 +36,8 @@ compileTestKotlin {
}
}

mainClassName = 'com.displee.editor.Editor'

dependencies {
compile fileTree(dir: 'lib', include: '*.jar')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
Expand Down
96 changes: 91 additions & 5 deletions src/main/java/com/displee/editor/controller/MainController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.fxmisc.richtext.model.StyleSpansBuilder
import java.io.File
import java.io.PrintWriter
import java.io.StringWriter
import java.lang.StringBuilder
import java.net.URL
import java.text.SimpleDateFormat
import java.time.Instant
Expand All @@ -48,6 +49,18 @@ class MainController : Initializable {
@FXML
private lateinit var openMenuItem: MenuItem

@FXML
private lateinit var openRecentPaths: Menu

@FXML
private lateinit var path1: MenuItem

@FXML
private lateinit var path2: MenuItem

@FXML
private lateinit var path3: MenuItem

@FXML
private lateinit var saveMenuItem: MenuItem

Expand Down Expand Up @@ -92,6 +105,7 @@ class MainController : Initializable {

private val cachedScripts = mutableMapOf<Int, String>()

private final val fileName = System.getProperty("user.dir") + "/paths.txt"
private var temporaryAssemblyPane: Node? = null

lateinit var cacheLibrary: CacheLibrary
Expand All @@ -104,6 +118,21 @@ class MainController : Initializable {
private var currentScript: CS2? = null

override fun initialize(location: URL?, resources: ResourceBundle?) {
var file = File(fileName)
if (!file.exists()) file.createNewFile()
else {
var readLines = file.readLines()
if (readLines != null && !readLines.isEmpty()) {
path1.text = readLines.get(0)
if (readLines.size > 1) {
path2.text = readLines.get(1)
}
if (readLines.size > 2) {
path3.text = readLines.get(2)
}
}
}

rootPane.addEventHandler(KeyEvent.KEY_PRESSED) { e: KeyEvent ->
if (e.isControlDown && e.code == KeyCode.N) {
if (!this::cacheLibrary.isInitialized) {
Expand All @@ -112,9 +141,17 @@ class MainController : Initializable {
newScript(notifyChooseScriptId(cacheLibrary.index(SCRIPTS_INDEX).nextId()))
}
}

openMenuItem.setOnAction {
openCache()
}

path1.setOnAction { openCacheFromRecentPaths(1) }

path2.setOnAction { openCacheFromRecentPaths(2) }

path3.setOnAction { openCacheFromRecentPaths(3) }

saveMenuItem.setOnAction {
compileScript()
}
Expand Down Expand Up @@ -208,12 +245,56 @@ class MainController : Initializable {
AutoCompleteUtils
}

private fun openCacheFromRecentPaths(lineNumber: Int) {
val fileName = System.getProperty("user.dir") + "/paths.txt"
var file = File(fileName)
if (file.exists()) {
if (file.readLines() == null || file.readLines().isEmpty()) {
Platform.runLater {
Notification.error("No recent paths saved, open a new cache")
clearCache()
}
} else {
openCache(File(file.readLines()[lineNumber-1]))
}
}
}

private fun shiftLines() {
if (path1.text.isEmpty()) return;
path3.text = path2.text
path2.text = path1.text
}

private fun savePaths() {
var file = File(fileName)
if (!file.exists()) file.createNewFile()
val string = StringBuilder()
string.append(path1.text).append("\n").append(path2.text).append("\n").append(path3.text)

file.writeText(string.toString())
}

private fun openCache(f: File? = null) {
var mehFile = f
if (mehFile == null) {
val chooser = DirectoryChooser()
mehFile = chooser.showDialog(mainWindow()) ?: return
shiftLines()
path1.text = mehFile!!.path
}
savePaths()
// val string = StringBuilder()
// if (file.readLines() != null && file.readLines().isNotEmpty()) {
// for ((index, readLine) in file.readLines().withIndex()) {
// string.append(readLine)
// if (index == 2) break;
// string.append("\n")
// }
// file.writeText(string.toString())
// }


scriptList.isDisable = true
GlobalScope.launch {
try {
Expand Down Expand Up @@ -354,7 +435,6 @@ class MainController : Initializable {
}
}
}
println("config: ${config.version} $error")
error < 2
}
var configuration: ScriptConfiguration? = null
Expand Down Expand Up @@ -462,7 +542,7 @@ class MainController : Initializable {
}
var list: MutableList<AutoCompleteItem>? = AutoCompleteUtils.dynamicItems
if (FlowBlocksGenerator.isObjectOpcode(opcode) || FlowBlocksGenerator.isObjectWidgetOpcode(opcode)) {
list = AutoCompleteUtils.getObject(WIDGET_PTR, true)?.dynamicChildren
list = AutoCompleteUtils.getObject(COMPONENT, true)?.dynamicChildren
}
val name = split[1]
val returnTypes = if (split[2].contains("|")) {
Expand All @@ -488,6 +568,12 @@ class MainController : Initializable {
if (list != null && list.firstOrNull { it.name == name } == null) {
list.add(function)
}

if (list != null) {
run {
list.add(function);
}
}
}
}

Expand Down Expand Up @@ -649,11 +735,11 @@ class MainController : Initializable {
SPRITE,
MODEL,
MIDI,
DATAMAP,
ENUM,
ATTRIBUTEMAP,
CONTAINER,
WIDGET_PTR,
LOCATION,
COMPONENT,
COORD,
ITEM,
COLOR,
IDENTIKIT,
Expand Down
Loading