diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ModPageAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ModPageAdapter.kt index 8b04123..732bfbe 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ModPageAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ModPageAdapter.kt @@ -22,7 +22,10 @@ class ModPageAdapter( FileDataBase.getInstance(fragmentActivity, modClass.modName, openNewDataBase = true) } val allUnitsFragment: AllUnitsFragment by lazy { - AllUnitsFragment(fragmentActivity, modClass, fileDataBase) + val fragment = AllUnitsFragment() + fragment.modClass = modClass + fragment.fileDatabase = fileDataBase + fragment } val historyUnitFragment: HistoryUnitFragment by lazy { diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt index 1a13423..15bde47 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt @@ -43,11 +43,12 @@ import kotlin.collections.ArrayList * @date 2022/1/13 21:32 */ class AllUnitsFragment( - val fragmentActivity: FragmentActivity, - val modClass: ModClass, - val fileDatabase: FileDataBase + ) : BaseFragment() { + var fragmentActivity: FragmentActivity? = null + var modClass: ModClass? = null + var fileDatabase: FileDataBase? = null var whenNumberChanged: ((Int) -> Unit)? = null val executorService = Executors.newSingleThreadExecutor() val dataList: ArrayList = ArrayList() @@ -80,11 +81,11 @@ class AllUnitsFragment( val bundle = Bundle() val path = file.file.absolutePath bundle.putString("path", path) - bundle.putString("modPath", modClass.modFile.absolutePath) + bundle.putString("modPath", modClass!!.modFile.absolutePath) addFileToHistory(file, handler = handler, whenAddComplete = { val intent = Intent(requireContext(), EditActivity::class.java) intent.putExtra("data", bundle) - fragmentActivity.startActivityForResult(intent, 2) + fragmentActivity?.startActivityForResult(intent, 2) }) } } @@ -110,7 +111,7 @@ class AllUnitsFragment( ) ) + " (" + file.file.name + ")" val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") - val historyDao = fileDatabase.getHistoryDao() + val historyDao = fileDatabase!!.getHistoryDao() val newHistoryRecord = HistoryRecord( path, name, @@ -140,7 +141,7 @@ class AllUnitsFragment( * 加载列表 * @param file File */ - fun loadFiles(file: File = modClass.modFile) { + fun loadFiles(file: File = modClass!!.modFile) { val handler = Handler(Looper.getMainLooper()) executorService.submit { handler.post { @@ -150,23 +151,27 @@ class AllUnitsFragment( } dataList.clear() val fileFinder2 = FileFinder2(file) - val data = modClass.modConfigurationManager?.readData() + val data = modClass!!.modConfigurationManager?.readData() val sourceFileFilteringRule = Regex(data?.sourceFileFilteringRule ?: ".+\\.ini|.+\\.template") fileFinder2.setFinderListener(object : FileFinderListener { override fun whenFindFile(file: File): Boolean { + if (fileDatabase == null || modClass == null) + { + return false + } //此处在这里判断的目的是将所有文件录入数据库 if (file.name.matches(sourceFileFilteringRule)) { - val sourceFileClass = SourceFile(file, modClass) - fileDatabase.addValuesFromSourceFile(requireContext(), sourceFileClass) + val sourceFileClass = SourceFile(file, modClass!!) + fileDatabase!!.addValuesFromSourceFile(requireContext(), sourceFileClass) dataList.add(sourceFileClass) } 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 { - fileDatabase.getFileInfoDao().update(fileTable) + fileDatabase!!.getFileInfoDao().update(fileTable) } 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()) executorService.submit { handler.post { @@ -257,7 +262,7 @@ class AllUnitsFragment( viewBinding.unitError.isVisible = false } dataList.clear() - val data = modClass.modConfigurationManager?.readData() + val data = modClass!!.modConfigurationManager?.readData() val sourceFileFilteringRule = data?.sourceFileFilteringRule ?: ".+\\.ini|.+\\.template" val language = AppSettings .getValue(AppSettings.Setting.AppLanguage, Locale.getDefault().language) diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/LocalTemplatePackage.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/LocalTemplatePackage.kt index 0a8fa6e..bde2ce8 100644 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/LocalTemplatePackage.kt +++ b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/LocalTemplatePackage.kt @@ -44,7 +44,12 @@ class LocalTemplatePackage(val directest: File) : TemplatePackage { */ fun getInfo(): TemplateInfo? { val data = FileOperator.readFile(infoFile) ?: return null - return gson.fromJson(data, TemplateInfo::class.java) + try { + return gson.fromJson(data, TemplateInfo::class.java) + } catch (e: Exception) { + e.printStackTrace() + return null + } } /** diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/tool/FileOperator.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/tool/FileOperator.kt index 38a48d7..9c5a9e3 100644 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/tool/FileOperator.kt +++ b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/tool/FileOperator.kt @@ -275,7 +275,7 @@ object FileOperator { outputStream.write(text.toByteArray()) outputStream.close() true - } catch (e: IOException) { + } catch (e: Exception) { e.printStackTrace() false } diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/turret/TurretSketchpadView.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/turret/TurretSketchpadView.kt index be2c031..eb1e2b0 100644 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/turret/TurretSketchpadView.kt +++ b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/turret/TurretSketchpadView.kt @@ -121,14 +121,22 @@ class TurretSketchpadView(context: Context, attributeSet: AttributeSet? = null) * @return CoordinateData */ fun toGameCoordinate(androidCoordinateData: CoordinateData): CoordinateData { - val x = (androidCoordinateData.x - centreX) / cellSize - val y = (androidCoordinateData.y - centreY) / cellSize - val game = CoordinateData(x, y) - LogCat.d( - debug, - "转换游戏坐标,安卓坐标${androidCoordinateData} 游戏坐标${game}" - ) - return game + if (cellSize > 0) { + val x = (androidCoordinateData.x - centreX) / cellSize + val y = (androidCoordinateData.y - centreY) / cellSize + val game = CoordinateData(x, y) + LogCat.d( + debug, + "转换游戏坐标,安卓坐标${androidCoordinateData} 游戏坐标${game}" + ) + return game + } else { + LogCat.d( + debug, + "转换游戏坐标,安卓坐标${androidCoordinateData} 单位尺寸为0 游戏坐标返回原点" + ) + return CoordinateData() + } } /**