// Copyright Epic Games, Inc. All Rights Reserved.
#include "DataTableCreator.h"
#include "DataTableCreatorCommands.h"
#include "DataTableReader.h"
#include "DataTableWriter.h"
#include "Misc/MessageDialog.h"
#include "ToolMenus.h"
#include "LevelEditor.h"
#include "Runtime\Core\Public\Misc\FileHelper.h"
#include "Misc/FeedbackContext.h"
#include "EngineMenuExtender/Public/EngineMenuExtender.h"
#include "../DataTableConfig.h"
#define LOCTEXT_NAMESPACE "DataTableCreator"
void DataTableCreator::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
FDataTableCreatorCommands::Register();
PluginCommands = MakeShareable(new FUICommandList);
PluginCommands->MapAction(
FDataTableCreatorCommands::Get().Action_CreateDataTable,
FExecuteAction::CreateRaw(this, &DataTableCreator::OnCreateDRClicked),
FCanExecuteAction());
FEngineMenuExtender& GameFrameworkPluginModule = FModuleManager::LoadModuleChecked< FEngineMenuExtender >("EngineMenuExtender");
GameFrameworkPluginModule.OnCustomMenuCreated().AddRaw(this, &DataTableCreator::RegisterMenus);
}
void DataTableCreator::ShutdownModule()
{
UToolMenus::UnRegisterStartupCallback(this);
UToolMenus::UnregisterOwner(this);
FDataTableCreatorCommands::Unregister();
}
void DataTableCreator::RegisterMenus(UToolMenu* menu) {
FToolMenuSection& section = menu->FindOrAddSection("Cherry_Section2");
section.AddMenuEntry(FDataTableCreatorCommands::Get().Action_CreateDataTable).SetCommandList(PluginCommands);
}
void DataTableCreator::OnCreateDRClicked() {
//1.查找文件夹下所有的txt文件,得到所有的txt名,以及路径。
//2.遍历txt,进行读取,在source目录下生成对应.h文件。
//3.删除多余的文件
//4.对操作者进行提示。
//读取UDataTableConfig配置
FString sourcePath = GetDefault<UDataTableConfig>()->dataTableSourcePath;
FString targetPath = GetDefault<UDataTableConfig>()->dataRowScriptPath;
const FString dataTablePath(FPaths::ProjectDir() + *sourcePath);
const FString scriptFilePath(FPaths::GameSourceDir() + *targetPath);
CreateDRScripts(dataTablePath, scriptFilePath);
}
void DataTableCreator::CreateDRScripts(const FString sourceDataTablePath, const FString targetScriptFilePath)
{
TArray<FString> createScriptFilePaths;
TArray<FString> deleteScriptFilePaths;
TArray<FString> updateScriptFilePaths;
TArray<FString> errorDataTableFilePaths;
//FString使用Equal保证大小写
TArray<FString> beingDeleteScriptPaths;
FDataTableWriter::ClearCachedBPScriptStr();
{
TArray<FString> txtPaths;
TArray<FString> txtNames;
TArray<FString> curScriptPaths;
IPlatformFile& fileManager = FPlatformFileManager::Get().GetPlatformFile();
fileManager.FindFiles(txtPaths, *sourceDataTablePath, TEXT(".txt"));
fileManager.FindFiles(curScriptPaths, *targetScriptFilePath, TEXT(".h"));
for (int32 i = 0; i < txtPaths.Num(); ++i)
{
FString txtName = FPaths::GetBaseFilename(txtPaths[i]);
txtNames.Add(txtName);
}
for (int32 i = 0; i < curScriptPaths.Num(); ++i)
{
FString& scriptPath = curScriptPaths[i];
bool hasSameScript = false;
for (int j = 0; j < txtPaths.Num(); ++j)
{
FString txtName = FPaths::GetBaseFilename(txtPaths[j]);
FString targetPath = targetScriptFilePath + "/DR" + txtName + ".h";
//大小写敏感,相同则说明是旧的txt文件。
if (targetPath.Equals(scriptPath, ESearchCase::CaseSensitive))
{
hasSameScript = true;
break;
}
}
if (!hasSameScript)
{
beingDeleteScriptPaths.Add(*scriptPath);
}
}
int32 deleteScriptFileNum = beingDeleteScriptPaths.Num();
if (deleteScriptFileNum != 0)
{
for (auto scriptPath : beingDeleteScriptPaths)
{
fileManager.DeleteFile(*FString(scriptPath));
deleteScriptFilePaths.Add(scriptPath);
}
}
GWarn->BeginSlowTask(INVTEXT("更新配置表头文件中"), true, false);
for (int32 i = 0; i < txtPaths.Num(); ++i)
{
GWarn->UpdateProgress(i, txtPaths.Num());
FString& sourcePath = txtPaths[i];
FString& txtName = txtNames[i];
FString targetPath = FPaths::GameSourceDir() + "/Project_UnrealEngine/GameLogic/DataTable/DataRow/DR" + txtName + ".h";
TArray<TArray<FString>> datas = FDataTableReader::ReadTxt(*sourcePath);
if (datas.Num() != 3)
{
//读取配置表出错
errorDataTableFilePaths.Add(FPaths::GetCleanFilename(sourcePath));
continue;
}
//这里也会处理蓝图函数库代码,保证进入蓝图函数库的接口都是能够正确调用的
FString scriptStr = FDataTableWriter::WriteDRScript(datas, txtName, sourcePath);
//不存在文件
if (!fileManager.FileExists(*targetPath))
{
createScriptFilePaths.Add(FPaths::GetCleanFilename(targetPath));
FFileHelper::SaveStringToFile(scriptStr, *targetPath);
}
else
{
if (SaveFileStr(scriptStr, targetPath))
{
updateScriptFilePaths.Add(FPaths::GetCleanFilename(targetPath));
}
}
}
}
//todo 生成蓝图函数库代码,后续用配置读
bool isChange = false;
FString tempPath = FPaths::GameSourceDir() + "/Project_UnrealEngine/GameLogic/DataTable/";
FString headerScriptPath = tempPath + "DataTableBPLibrary.h";
FString sourceScriptPath = tempPath + "DataTableBPLibrary.cpp";
FString headerStr = FDataTableWriter::WriteBPHeaderScript();
FString sourceStr = FDataTableWriter::WriteBPSourceScript();
if (SaveFileStr(headerStr, headerScriptPath))
{
isChange = true;
}
if (SaveFileStr(sourceStr, sourceScriptPath))
{
isChange = true;
}
GWarn->EndSlowTask();
FDataTableWriter::ClearCachedBPScriptStr();
//提示
ShowMessage(createScriptFilePaths, deleteScriptFilePaths, updateScriptFilePaths, errorDataTableFilePaths, isChange);
}
void DataTableCreator::ShowMessage(TArray<FString>& createScriptFilePaths, TArray<FString>& deleteScriptFilePaths, TArray<FString>& updateScriptFilePaths, TArray<FString>& errorDataTableFilePaths, bool isBPScriptChange)
{
FString resultMessage;
FString createFileMessage = TEXT("---------生成的数据表头文件列表---------\n");
if (createScriptFilePaths.Num() == 0)
{
createFileMessage += TEXT("本次未生成数据表头文件\n");
}
else
{
for (auto path : createScriptFilePaths)
{
createFileMessage += FString::Printf(TEXT("路径:%s\n"), *path);
}
}
FString deleteFileMessage = TEXT("\n---------删除的数据表头文件列表---------\n");
if (deleteScriptFilePaths.Num() == 0)
{
deleteFileMessage += TEXT("本次未删除数据表头文件\n");
}
else
{
for (auto path : deleteScriptFilePaths)
{
deleteFileMessage += FString::Printf(TEXT("路径:%s\n"), *FPaths::GetCleanFilename(path));
}
}
FString errorFileMessage = TEXT("\n---------错误结构的数据表文件列表---------\n");
if (errorDataTableFilePaths.Num() == 0)
{
errorFileMessage += TEXT("本次无错误结构的数据表文件\n");
}
else
{
for (auto path : errorDataTableFilePaths)
{
errorFileMessage += FString::Printf(TEXT("路径:%s\n"), *path);
}
}
FString updateFileMessage = TEXT("\n---------更新的数据表头文件列表---------\n");
if (updateScriptFilePaths.Num() == 0)
{
updateFileMessage += TEXT("本次未更新数据表头文件\n");
}
else
{
for (auto path : updateScriptFilePaths)
{
updateFileMessage += FString::Printf(TEXT("路径:%s\n"), *path);
}
}
FString bpScriptMessage = TEXT("\n---------蓝图函数库代码更新信息---------\n");
if (isBPScriptChange)
{
bpScriptMessage += TEXT("代码有变动!\n");
}
else
{
bpScriptMessage += TEXT("代码无变动!\n");
}
resultMessage += createFileMessage;
resultMessage += deleteFileMessage;
resultMessage += updateFileMessage;
resultMessage += errorFileMessage;
resultMessage += bpScriptMessage;
if (updateScriptFilePaths.Num() == 0 && createScriptFilePaths.Num() == 0 && deleteScriptFilePaths.Num() == 0 && errorDataTable
程序员张小妍
- 粉丝: 1w+
- 资源: 3690
最新资源
- 鼠标连点器,最高350CPS
- 恒压供水图纸程序 西门子 恒压供水图纸 程序仅供参考 2. HMI画面,一拖二加一,一拖三加一,一拖四加一,一拖五加一; 3.程序设计,一拖三加一,一拖五加一 4.西门子默认sm
- video_250111_202128.mp4
- 该套程序是正压检漏机程序,总共有9个 A6总线伺服电机,6个总线步进电机,采用EtherCAT总线控制, PLC:基恩士KV-8000,伺服:松下A6总线型伺服,这是已经在量产的程序,标准程序框架可以
- video_250111_062526.mp4
- 西门子1200PLC加KTP触摸屏画面博途程序案例,博图版本V16,程序具体为电池涂布机浆料输送系统新能源项目 程序结构分: 1.配料系统物料分配输送 2.模拟量转,监测
- 西门子1200PLC博途程序,博图版本V14及以上,具体为双行星动力搅拌桨混合机项目,有画面案例,硬件采用-S7-1200PLC加西门子KTP触摸屏 程序结构包括: 1.配料系统物料分
- 西门子1200博途程序与威纶触摸屏画面实例 ,博图版本V15及以上,内容涉及上位机通讯,modbus485,伺服等 具体有: 1,西门子1200控制4台步进电机; 2,西门子1200与4台MS300
- Labview屏幕分辨率判断
- 多目标粒子群算法CCHP联供综合能源系统 说明书MATLAB代码:基于多目标粒子群算法冷热电联供综合能源系统运行优化关键词:综合能源 冷热电三联供 粒子群算法 多目标优化参考文档:基于多目标算法的
- 威纶通触摸屏配方管理模板(送电气助手) 文件内包含全部图库、原图、PS原文件 威纶通触摸屏例子、宏程序(带详细注释)
- 三相有源电力滤器APF仿真 波形从上到下分别是: 电网电流 APF电流 整流性负载电流 APF能够保证电网电流成正弦
- matlab运用遗传算法求解多配送中心选址问题(可以考虑备选地容量,备选地储存费用,备选地固定建设成本,运输成本等)(可代做类似的算法代码 保证打开就能运行,数据可任意修改
- 2023-04-06-项目笔记 - 第三百七十六阶段 - 4.4.2.374全局变量的作用域-374 -2025.01.12
- No.1025 基于S7-200 PLC和MCGS组态洗衣机控制系统 带解释的梯形图程序,接线图原理图图纸,io分配,组态画面
- 高频注入 STM32永磁同步电机Simulink自动代码生成 霍尔FOC 模型+Keil集成工程+生成代码教学视频
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页