修复一些崩溃问题。
This commit is contained in:
parent
0fc4c85237
commit
46b94a576c
|
@ -22,7 +22,10 @@ class ModPageAdapter(
|
||||||
FileDataBase.getInstance(fragmentActivity, modClass.modName, openNewDataBase = true)
|
FileDataBase.getInstance(fragmentActivity, modClass.modName, openNewDataBase = true)
|
||||||
}
|
}
|
||||||
val allUnitsFragment: AllUnitsFragment by lazy {
|
val allUnitsFragment: AllUnitsFragment by lazy {
|
||||||
AllUnitsFragment(fragmentActivity, modClass, fileDataBase)
|
val fragment = AllUnitsFragment()
|
||||||
|
fragment.modClass = modClass
|
||||||
|
fragment.fileDatabase = fileDataBase
|
||||||
|
fragment
|
||||||
}
|
}
|
||||||
|
|
||||||
val historyUnitFragment: HistoryUnitFragment by lazy {
|
val historyUnitFragment: HistoryUnitFragment by lazy {
|
||||||
|
|
|
@ -43,11 +43,12 @@ import kotlin.collections.ArrayList
|
||||||
* @date 2022/1/13 21:32
|
* @date 2022/1/13 21:32
|
||||||
*/
|
*/
|
||||||
class AllUnitsFragment(
|
class AllUnitsFragment(
|
||||||
val fragmentActivity: FragmentActivity,
|
|
||||||
val modClass: ModClass,
|
|
||||||
val fileDatabase: FileDataBase
|
|
||||||
) :
|
) :
|
||||||
BaseFragment<FragmentAllUnitsBinding>() {
|
BaseFragment<FragmentAllUnitsBinding>() {
|
||||||
|
var fragmentActivity: FragmentActivity? = null
|
||||||
|
var modClass: ModClass? = null
|
||||||
|
var fileDatabase: FileDataBase? = null
|
||||||
var whenNumberChanged: ((Int) -> Unit)? = null
|
var whenNumberChanged: ((Int) -> Unit)? = null
|
||||||
val executorService = Executors.newSingleThreadExecutor()
|
val executorService = Executors.newSingleThreadExecutor()
|
||||||
val dataList: ArrayList<SourceFile> = ArrayList()
|
val dataList: ArrayList<SourceFile> = ArrayList()
|
||||||
|
@ -80,11 +81,11 @@ class AllUnitsFragment(
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
val path = file.file.absolutePath
|
val path = file.file.absolutePath
|
||||||
bundle.putString("path", path)
|
bundle.putString("path", path)
|
||||||
bundle.putString("modPath", modClass.modFile.absolutePath)
|
bundle.putString("modPath", modClass!!.modFile.absolutePath)
|
||||||
addFileToHistory(file, handler = handler, whenAddComplete = {
|
addFileToHistory(file, handler = handler, whenAddComplete = {
|
||||||
val intent = Intent(requireContext(), EditActivity::class.java)
|
val intent = Intent(requireContext(), EditActivity::class.java)
|
||||||
intent.putExtra("data", bundle)
|
intent.putExtra("data", bundle)
|
||||||
fragmentActivity.startActivityForResult(intent, 2)
|
fragmentActivity?.startActivityForResult(intent, 2)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +111,7 @@ class AllUnitsFragment(
|
||||||
)
|
)
|
||||||
) + " (" + file.file.name + ")"
|
) + " (" + file.file.name + ")"
|
||||||
val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
||||||
val historyDao = fileDatabase.getHistoryDao()
|
val historyDao = fileDatabase!!.getHistoryDao()
|
||||||
val newHistoryRecord = HistoryRecord(
|
val newHistoryRecord = HistoryRecord(
|
||||||
path,
|
path,
|
||||||
name,
|
name,
|
||||||
|
@ -140,7 +141,7 @@ class AllUnitsFragment(
|
||||||
* 加载列表
|
* 加载列表
|
||||||
* @param file File
|
* @param file File
|
||||||
*/
|
*/
|
||||||
fun loadFiles(file: File = modClass.modFile) {
|
fun loadFiles(file: File = modClass!!.modFile) {
|
||||||
val handler = Handler(Looper.getMainLooper())
|
val handler = Handler(Looper.getMainLooper())
|
||||||
executorService.submit {
|
executorService.submit {
|
||||||
handler.post {
|
handler.post {
|
||||||
|
@ -150,23 +151,27 @@ class AllUnitsFragment(
|
||||||
}
|
}
|
||||||
dataList.clear()
|
dataList.clear()
|
||||||
val fileFinder2 = FileFinder2(file)
|
val fileFinder2 = FileFinder2(file)
|
||||||
val data = modClass.modConfigurationManager?.readData()
|
val data = modClass!!.modConfigurationManager?.readData()
|
||||||
val sourceFileFilteringRule =
|
val sourceFileFilteringRule =
|
||||||
Regex(data?.sourceFileFilteringRule ?: ".+\\.ini|.+\\.template")
|
Regex(data?.sourceFileFilteringRule ?: ".+\\.ini|.+\\.template")
|
||||||
fileFinder2.setFinderListener(object : FileFinderListener {
|
fileFinder2.setFinderListener(object : FileFinderListener {
|
||||||
override fun whenFindFile(file: File): Boolean {
|
override fun whenFindFile(file: File): Boolean {
|
||||||
|
if (fileDatabase == null || modClass == null)
|
||||||
|
{
|
||||||
|
return false
|
||||||
|
}
|
||||||
//此处在这里判断的目的是将所有文件录入数据库
|
//此处在这里判断的目的是将所有文件录入数据库
|
||||||
if (file.name.matches(sourceFileFilteringRule)) {
|
if (file.name.matches(sourceFileFilteringRule)) {
|
||||||
val sourceFileClass = SourceFile(file, modClass)
|
val sourceFileClass = SourceFile(file, modClass!!)
|
||||||
fileDatabase.addValuesFromSourceFile(requireContext(), sourceFileClass)
|
fileDatabase!!.addValuesFromSourceFile(requireContext(), sourceFileClass)
|
||||||
dataList.add(sourceFileClass)
|
dataList.add(sourceFileClass)
|
||||||
}
|
}
|
||||||
val fileTable = FileDataBase.createFileInfoFromFile(file)
|
val fileTable = FileDataBase.createFileInfoFromFile(file)
|
||||||
if (fileDatabase.getFileInfoDao().findFileInfoByPath(file.absolutePath) == null
|
if (fileDatabase!!.getFileInfoDao().findFileInfoByPath(file.absolutePath) == null
|
||||||
) {
|
) {
|
||||||
fileDatabase.getFileInfoDao().insert(fileTable)
|
fileDatabase!!.getFileInfoDao().insert(fileTable)
|
||||||
} else {
|
} else {
|
||||||
fileDatabase.getFileInfoDao().update(fileTable)
|
fileDatabase!!.getFileInfoDao().update(fileTable)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -248,7 +253,7 @@ class AllUnitsFragment(
|
||||||
/**
|
/**
|
||||||
* 高级搜索
|
* 高级搜索
|
||||||
*/
|
*/
|
||||||
fun advancedSearch(file: File = modClass.modFile, configuration: SearchConfiguration) {
|
fun advancedSearch(file: File = modClass!!.modFile, configuration: SearchConfiguration) {
|
||||||
val handler = Handler(Looper.getMainLooper())
|
val handler = Handler(Looper.getMainLooper())
|
||||||
executorService.submit {
|
executorService.submit {
|
||||||
handler.post {
|
handler.post {
|
||||||
|
@ -257,7 +262,7 @@ class AllUnitsFragment(
|
||||||
viewBinding.unitError.isVisible = false
|
viewBinding.unitError.isVisible = false
|
||||||
}
|
}
|
||||||
dataList.clear()
|
dataList.clear()
|
||||||
val data = modClass.modConfigurationManager?.readData()
|
val data = modClass!!.modConfigurationManager?.readData()
|
||||||
val sourceFileFilteringRule = data?.sourceFileFilteringRule ?: ".+\\.ini|.+\\.template"
|
val sourceFileFilteringRule = data?.sourceFileFilteringRule ?: ".+\\.ini|.+\\.template"
|
||||||
val language = AppSettings
|
val language = AppSettings
|
||||||
.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language)
|
.getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language)
|
||||||
|
|
|
@ -44,7 +44,12 @@ class LocalTemplatePackage(val directest: File) : TemplatePackage {
|
||||||
*/
|
*/
|
||||||
fun getInfo(): TemplateInfo? {
|
fun getInfo(): TemplateInfo? {
|
||||||
val data = FileOperator.readFile(infoFile) ?: return null
|
val data = FileOperator.readFile(infoFile) ?: return null
|
||||||
|
try {
|
||||||
return gson.fromJson(data, TemplateInfo::class.java)
|
return gson.fromJson(data, TemplateInfo::class.java)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -275,7 +275,7 @@ object FileOperator {
|
||||||
outputStream.write(text.toByteArray())
|
outputStream.write(text.toByteArray())
|
||||||
outputStream.close()
|
outputStream.close()
|
||||||
true
|
true
|
||||||
} catch (e: IOException) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,6 +121,7 @@ class TurretSketchpadView(context: Context, attributeSet: AttributeSet? = null)
|
||||||
* @return CoordinateData
|
* @return CoordinateData
|
||||||
*/
|
*/
|
||||||
fun toGameCoordinate(androidCoordinateData: CoordinateData): CoordinateData {
|
fun toGameCoordinate(androidCoordinateData: CoordinateData): CoordinateData {
|
||||||
|
if (cellSize > 0) {
|
||||||
val x = (androidCoordinateData.x - centreX) / cellSize
|
val x = (androidCoordinateData.x - centreX) / cellSize
|
||||||
val y = (androidCoordinateData.y - centreY) / cellSize
|
val y = (androidCoordinateData.y - centreY) / cellSize
|
||||||
val game = CoordinateData(x, y)
|
val game = CoordinateData(x, y)
|
||||||
|
@ -129,6 +130,13 @@ class TurretSketchpadView(context: Context, attributeSet: AttributeSet? = null)
|
||||||
"转换游戏坐标,安卓坐标${androidCoordinateData} 游戏坐标${game}"
|
"转换游戏坐标,安卓坐标${androidCoordinateData} 游戏坐标${game}"
|
||||||
)
|
)
|
||||||
return game
|
return game
|
||||||
|
} else {
|
||||||
|
LogCat.d(
|
||||||
|
debug,
|
||||||
|
"转换游戏坐标,安卓坐标${androidCoordinateData} 单位尺寸为0 游戏坐标返回原点"
|
||||||
|
)
|
||||||
|
return CoordinateData()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user