2024-12-11 15:08:57 +08:00
|
|
|
/*
|
|
|
|
|
文件名:ScriptManager.nut
|
|
|
|
|
路径:Core/BaseClass/ScriptManager/ScriptManager.nut
|
|
|
|
|
创建日期:2024-10-11 12:24
|
|
|
|
|
文件用途:pvf 管理器
|
|
|
|
|
*/
|
|
|
|
|
class Script {
|
|
|
|
|
|
|
|
|
|
C_Object = null;
|
|
|
|
|
|
|
|
|
|
constructor(Path = "Script.pvf") {
|
|
|
|
|
print("正在初始化PVF...");
|
|
|
|
|
local StartTime = time();
|
|
|
|
|
|
|
|
|
|
C_Object = Asset_LoadScript(Path);
|
|
|
|
|
|
|
|
|
|
print("PVF初始化完毕!!!");
|
|
|
|
|
print("用时: " + (time() - StartTime) + "秒");
|
|
|
|
|
getroottable()._Script_Data_ <- this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function GetFileInfo(Path) {
|
|
|
|
|
local size = Asset_GetPvfFileSize(C_Object, Path);
|
|
|
|
|
if (size) {
|
|
|
|
|
local blobobj = blobex(size);
|
|
|
|
|
Asset_GetPvfFile(C_Object, Path, blobobj);
|
|
|
|
|
return blobobj;
|
|
|
|
|
} else return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function GetBinString(Key) {
|
|
|
|
|
return Asset_GetPvfBinString(C_Object, Key);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-20 13:53:36 +08:00
|
|
|
function GetLoadString(Type, Key) {
|
|
|
|
|
return Asset_GetPvfLoadString(C_Object, Type, Key);
|
2024-12-11 15:08:57 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _PVF_Data_ {
|
|
|
|
|
//数据
|
|
|
|
|
Data = null;
|
|
|
|
|
//位置
|
|
|
|
|
Pos = 0;
|
|
|
|
|
//最大值
|
|
|
|
|
Max = 0;
|
|
|
|
|
|
|
|
|
|
function _typeof() {
|
|
|
|
|
return "pvf_data";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(gData) {
|
|
|
|
|
Data = gData;
|
|
|
|
|
Max = gData.len();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Last() {
|
|
|
|
|
if (Pos > 0) {
|
|
|
|
|
Pos--;
|
|
|
|
|
return Get();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Seek(i) {
|
|
|
|
|
if (Pos > 0 && Pos<(Max - 1)) {
|
|
|
|
|
Pos = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Get() {
|
|
|
|
|
local Ret = Data[Pos];
|
|
|
|
|
if (Pos<(Max - 1)) {
|
|
|
|
|
Pos++;
|
|
|
|
|
}
|
|
|
|
|
return Ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Eof() {
|
|
|
|
|
if (Pos == Max - 1)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Next() {
|
|
|
|
|
if (Pos<(Max - 1)) {
|
|
|
|
|
Pos++;
|
|
|
|
|
return Get();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GlobaData {
|
|
|
|
|
//动画文件Map
|
|
|
|
|
Ani = null;
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
Ani = {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取文件的IO
|
|
|
|
|
function GetFile(Path) {
|
|
|
|
|
return getroottable()._Script_Data_.GetFileInfo(Path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取文件并处理
|
|
|
|
|
function GetFileData(Path, Func) {
|
|
|
|
|
local IO = GetFile(Path);
|
|
|
|
|
if (IO) {
|
|
|
|
|
return ResolvingData(IO, Func, Path);
|
|
|
|
|
} else {
|
|
|
|
|
print(Path + "找不到文件!");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取动画文件
|
|
|
|
|
function GetAni(Path) {
|
|
|
|
|
if (Path in Ani)
|
|
|
|
|
return Ani[Path];
|
|
|
|
|
else {
|
|
|
|
|
local IO = GetFile(Path);
|
|
|
|
|
if (IO) {
|
|
|
|
|
Ani[Path] <- InitPvfAni(IO);
|
2024-12-13 20:52:30 +08:00
|
|
|
Ani[Path].filepath <- Path;
|
2024-12-11 15:08:57 +08:00
|
|
|
return Ani[Path];
|
|
|
|
|
} else {
|
|
|
|
|
print(Path + "找不到文件!");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ResolvingData(IO, Func, Path) {
|
|
|
|
|
local DataTable = {};
|
|
|
|
|
DataTable.filepath <- Path;
|
2025-02-20 13:53:36 +08:00
|
|
|
local Type = Path.slice(0, Path.find("/")).tolower();
|
2024-12-11 15:08:57 +08:00
|
|
|
local DataArr = [];
|
|
|
|
|
local Length = IO.len();
|
|
|
|
|
if (Length >= 7) {
|
|
|
|
|
local i = 2;
|
|
|
|
|
while (true) {
|
|
|
|
|
if (i< Length && Length - i >= 5) {
|
2025-02-20 13:53:36 +08:00
|
|
|
local str = UnpackData(IO, i, Type);
|
2024-12-11 15:08:57 +08:00
|
|
|
i += 5;
|
|
|
|
|
DataArr.push(str);
|
|
|
|
|
} else break;
|
|
|
|
|
}
|
|
|
|
|
Func(DataTable, _PVF_Data_(DataArr));
|
|
|
|
|
return DataTable;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-20 13:53:36 +08:00
|
|
|
function UnpackData(IO, i, Type) {
|
2024-12-11 15:08:57 +08:00
|
|
|
IO.seek(i); //内容指示位
|
|
|
|
|
local currentByte = IO.readn('c'); //内容指示位
|
|
|
|
|
local after = IO.GetInt();
|
|
|
|
|
switch (currentByte) {
|
2025-01-04 20:03:17 +08:00
|
|
|
case 9: {
|
|
|
|
|
local NewcurrentByte = IO.readn('c'); //内容指示位
|
|
|
|
|
local Newafter = IO.GetInt();
|
|
|
|
|
local Buf = getroottable()._Script_Data_.GetBinString(Newafter);
|
|
|
|
|
if (!Buf) {
|
|
|
|
|
Buf = "";
|
|
|
|
|
} else {
|
2025-02-20 13:53:36 +08:00
|
|
|
Buf = getroottable()._Script_Data_.GetLoadString(Type, Buf);
|
2025-01-04 20:03:17 +08:00
|
|
|
}
|
|
|
|
|
return Buf;
|
|
|
|
|
}
|
2024-12-11 15:08:57 +08:00
|
|
|
case 10: {
|
|
|
|
|
local Buf = getroottable()._Script_Data_.GetBinString(after);
|
|
|
|
|
if (!Buf) {
|
|
|
|
|
Buf = "";
|
|
|
|
|
} else {
|
2025-02-20 13:53:36 +08:00
|
|
|
Buf = getroottable()._Script_Data_.GetLoadString(Type, Buf);
|
2024-12-11 15:08:57 +08:00
|
|
|
}
|
2025-01-02 19:19:36 +08:00
|
|
|
return Buf;
|
2024-12-11 15:08:57 +08:00
|
|
|
}
|
|
|
|
|
case 2: {
|
|
|
|
|
IO.seek(-4, 'c');
|
|
|
|
|
local ret = IO.readn('i');
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
case 4: {
|
2025-02-20 13:53:36 +08:00
|
|
|
local Bbuf = blob(4);
|
|
|
|
|
Bbuf.writen(after, 'i');
|
|
|
|
|
Bbuf.seek(0);
|
|
|
|
|
local Buf = Bbuf.readn('f');
|
|
|
|
|
return Buf.tofloat();
|
2024-12-11 15:08:57 +08:00
|
|
|
}
|
|
|
|
|
case 6:
|
|
|
|
|
case 8:
|
|
|
|
|
case 7:
|
|
|
|
|
case 5: {
|
|
|
|
|
local Buf = getroottable()._Script_Data_.GetBinString(after);
|
|
|
|
|
if (!Buf) Buf = "";
|
|
|
|
|
return Buf;
|
|
|
|
|
}
|
|
|
|
|
default:
|
2025-01-04 20:03:17 +08:00
|
|
|
return "";
|
2024-12-11 15:08:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
getroottable().ScriptData <- GlobaData();
|