diff --git a/Game/CharacterScript/Common/Move.nut b/Game/CharacterScript/Common/Move.nut index 134ba22..9aa8e7c 100644 --- a/Game/CharacterScript/Common/Move.nut +++ b/Game/CharacterScript/Common/Move.nut @@ -5,48 +5,67 @@ 文件用途:角色移动脚本 */ +/** + * + * @function + * @param {ActiveObject} obj + * @returns {void} + */ function checkCanChangeState_Character_Move(obj) { - //获取当前状态 - local CurState = obj.GetState(); - //得到摇杆的数据 X 和 Y的范围 -1.0 ~ 1.0 - local arr = obj.GetVars("_move_data_", "float"); - if (fabs(arr[0]) > 0.35 || fabs(arr[1]) > 0.35) { - return true; - } else return false; + //获取当前状态 + local CurState = obj.GetState(); + //得到摇杆的数据 X 和 Y的范围 -1.0 ~ 1.0 + local arr = obj.GetVars("_move_data_", "float"); + if (fabs(arr[0]) > 0.35 || fabs(arr[1]) > 0.35) { + return true; + } else return false; } +/** + * + * @function + * @param {ActiveObject} obj + * @returns {void} + */ function SetState_Character_Move(obj) { - //获取移动数据 - local arr = obj.GetVars("_move_data_", "float"); + //获取移动数据 + local arr = obj.GetVars("_move_data_", "float"); - //设置人物朝向 摇杆X轴大于0则朝右,小于0则朝左 - local SetValue = arr[0] > 0 ? 0 : 1; - if (SetValue != obj.GetDirection()) { - if (fabs(arr[0]) > 0.35) obj.SetDirection(SetValue); - //设置动作 - obj.SetAction("move"); - } else { - if (obj.GetState() != 1) obj.SetAction("move"); - } + //设置人物朝向 摇杆X轴大于0则朝右,小于0则朝左 + local SetValue = arr[0] > 0 ? 0 : 1; + if (SetValue != obj.GetDirection()) { + if (fabs(arr[0]) > 0.35) obj.SetDirection(SetValue); + //设置动作 + obj.SetAction("move"); + } else { + if (obj.GetState() != 1) obj.SetAction("move"); + } - local Speed = 250; - local Dir = obj.GetDirection(); - local Pos = obj.GetPosition(); - local XOffset = null; - if (fabs(arr[0]) > 0.35) XOffset = ((arr[0] > 0 ? Speed : -Speed)); - else XOffset = 0; - local YOffset = null; - //当摇杆Y轴大于0.35或小于-0.35时,设置Y轴偏移量 - if (fabs(arr[1]) > 0.35) YOffset = (arr[1] > 0 ? Speed : -Speed); - else YOffset = 0; + local Speed = 250; + local Dir = obj.GetDirection(); + local Pos = obj.GetPosition(); + local XOffset = null; + if (fabs(arr[0]) > 0.35) XOffset = arr[0] > 0 ? Speed : -Speed; + else XOffset = 0; + local YOffset = null; + //当摇杆Y轴大于0.35或小于-0.35时,设置Y轴偏移量 + if (fabs(arr[1]) > 0.35) YOffset = arr[1] > 0 ? Speed : -Speed; + else YOffset = 0; - obj.SetSpeed(XOffset, YOffset, null); + obj.SetSpeed(XOffset, YOffset, null); } +/** + * + * @function + * @param {ActiveObject} obj + * @param {integer} DeltaTime + * @returns {void} + */ function ProcState_Character_Move(obj, DeltaTime) { - //获取移动数据 - local arr = obj.GetVars("_move_data_", "float"); - if (arr[0] == 0 && arr[1] == 0) { - obj.SetState(0); - } -} \ No newline at end of file + //获取移动数据 + local arr = obj.GetVars("_move_data_", "float"); + if (arr[0] == 0 && arr[1] == 0) { + obj.SetState(0); + } +} diff --git a/Game/ObjectClass/ActiveObject.nut b/Game/ObjectClass/ActiveObject.nut index 3ae04cd..8bcfd35 100644 --- a/Game/ObjectClass/ActiveObject.nut +++ b/Game/ObjectClass/ActiveObject.nut @@ -1,25 +1,35 @@ -/* -文件名:ActiveObject.nut -路径:Game/ObjectClass/ActiveObject.nut -创建日期:2025-10-03 02:50 -文件用途: -*/ - +/** + * Description placeholder + * @global + * @param {*} Object + */ class ActiveObject extends BaseObject { + constructor(Object) { + base.constructor(Object); + } - constructor(Object) { - base.constructor(Object); - } + /** + * + * @function + * @param {integer} x + * @param {integer} y + * @param {integer} z + * @returns {void} + */ + function SetSpeed(x, y, z) { + local CurSpeed = sq_GetSpeed(C_Object); + if (x == null) x = CurSpeed.x; + if (y == null) y = CurSpeed.y; + if (z == null) z = CurSpeed.z; + sq_SetSpeed(C_Object, x, y, z); + } - function SetSpeed(x, y, z) { - local CurSpeed = sq_GetSpeed(C_Object); - if (x == null) x = CurSpeed.x; - if (y == null) y = CurSpeed.y; - if (z == null) z = CurSpeed.z; - sq_SetSpeed(C_Object, x, y, z); - } - - function GetSpeed() { - return sq_GetSpeed(C_Object); - } -} \ No newline at end of file + /** + * + * @function + * @returns {any} + */ + function GetSpeed() { + return sq_GetSpeed(C_Object); + } +} diff --git a/Game/ObjectClass/BaseObject.nut b/Game/ObjectClass/BaseObject.nut index e339537..fe8b21b 100644 --- a/Game/ObjectClass/BaseObject.nut +++ b/Game/ObjectClass/BaseObject.nut @@ -1,32 +1,75 @@ +/** + * Description placeholder + * @param {*} Object + */ class BaseObject { - //c++对象指针 - C_Object = null; + //c++对象指针 + C_Object = null; - constructor(Object) { - C_Object = Object; - } + constructor(Object) { + C_Object = Object; + } - function GetPosition() { - return sq_GetPosition(C_Object); - } + /** + * + * @function + * @returns {any} + */ + function GetPosition() { + return sq_GetPosition(C_Object); + } + // + /** + * + * @function + * @param {integer} x + * @param {integer} y + * @param {integer} z + * @returns {void} + */ + function SetPosition(x, y, z) { + sq_SetPosition(C_Object, x, y, z); + } - function SetPosition(x, y, z) { - sq_SetPosition(C_Object, x, y, z); - } + /** + * + * @function + * @param {string} Name + * @param {any} Type + * @returns {any} + */ + function GetVars(Name, Type) { + return sq_GetVars(C_Object, Name, Type); + } - function GetVars(Name, Type) { - return sq_GetVars(C_Object, Name, Type); - } + /** + * + * @function + * @param {string} Name + * @param {any} Type + * @param {any} Value + * @returns {void} + */ + function SetVars(Name, Type, Value) { + sq_SetVars(C_Object, Name, Type, Value); + } - function SetVars(Name, Type, Value) { - sq_SetVars(C_Object, Name, Type, Value); - } + /** + * + * @function + * @returns {integer} + */ + function GetDirection() { + return sq_GetDirection(C_Object); + } - function GetDirection() { - return sq_GetDirection(C_Object); - } - - function SetDirection(Dir) { - sq_SetDirection(C_Object, Dir); - } -} \ No newline at end of file + /** + * + * @function + * @param {integer} Dir + * @returns {void} + */ + function SetDirection(Dir) { + sq_SetDirection(C_Object, Dir); + } +} diff --git a/Game/ObjectClass/CharacterObject.nut b/Game/ObjectClass/CharacterObject.nut index 1c3a68b..010dbe2 100644 --- a/Game/ObjectClass/CharacterObject.nut +++ b/Game/ObjectClass/CharacterObject.nut @@ -1,23 +1,38 @@ -/* -文件名:CharacterObject.nut -路径:Game/ObjectClass/CharacterObject.nut -创建日期:2025-10-03 02:50 -文件用途: -*/ +/** + * Description placeholder + * @param {*} Object + */ class CharacterObject extends ActiveObject { - constructor(Object) { - base.constructor(Object); - } + constructor(Object) { + base.constructor(Object); + } - function GetState() { - return sq_GetState(C_Object); - } + /** + * + * @function + * @returns {*} + */ + function GetState() { + return sq_GetState(C_Object); + } - function SetState(State) { - sq_SetState(C_Object, State); - } + /** + * + * @function + * @param {integer} State + * @returns {void} + */ + function SetState(State) { + sq_SetState(C_Object, State); + } - function SetAction(key) { - sq_SetAction(C_Object, key); - } -} \ No newline at end of file + /** + * + * @function + * @param {any} key + * @returns {void} + */ + function SetAction(key) { + sq_SetAction(C_Object, key); + } +} diff --git a/Game/StateMachine/StateMachine.nut b/Game/StateMachine/StateMachine.nut index f41ef81..73145a8 100644 --- a/Game/StateMachine/StateMachine.nut +++ b/Game/StateMachine/StateMachine.nut @@ -5,81 +5,101 @@ 文件用途: */ +/** 状态机 + * @global + */ class StateMachine { - //状态注册表 - StatusRegistry = null; + //状态注册表 + StatusRegistry = null; - constructor() { - if (getroottable().rawin("__StateMachine__")) { - // 防止重复实例化 - throw "StateMachine 不能重复实例化!"; - } - //初始化状态注册表 - StatusRegistry = {}; - foreach(JobIndex in getconsttable().CHARACTERJOB) { - StatusRegistry[JobIndex] <- {}; - } - } + constructor() { + if (getroottable().rawin("__StateMachine__")) { + // 防止重复实例化 + throw "StateMachine 不能重复实例化!"; + } + //初始化状态注册表 + StatusRegistry = {}; + foreach (JobIndex in getconsttable().CHARACTERJOB) { + StatusRegistry[JobIndex] <- {}; + } + } - // 静态方法:获取唯一实例 - function GetInstance() { - if (!getroottable().rawin("__StateMachine__")) { - // 首次调用时创建实例 - getroottable()["__StateMachine__"] <- StateMachine(); - } - return getroottable()["__StateMachine__"]; - } + /** + * 静态方法:获取唯一实例 + * @function + * @returns {table} + */ + function GetInstance() { + if (!getroottable().rawin("__StateMachine__")) { + // 首次调用时创建实例 + getroottable()["__StateMachine__"] <- StateMachine(); + } + return getroottable()["__StateMachine__"]; + } - //注册状态 - function RegisterState(Job, StateName, StateIndex) { - StatusRegistry[Job][StateIndex] <- { - StateName = StateName, - StateIndex = StateIndex - } - print("注册了状态" + StateName + ",状态索引为" + StateIndex); - } + /** + * 注册状态 + * @function + * @param {integer} Job + * @param {any} StateName + * @param {integer} StateIndex + * @returns {void} + */ + function RegisterState(Job, StateName, StateIndex) { + StatusRegistry[Job][StateIndex] <- { + StateName = StateName, + StateIndex = StateIndex + }; + print("注册了状态" + StateName + ",状态索引为" + StateIndex); + } - //获取状态信息 - function GetStateInfo(Job, State) { - return StatusRegistry[Job][State]; - } + /** + * 获取状态信息 + * @function + * @param {integer} Job + * @param {integer} State + * @returns {integer} + */ + function GetStateInfo(Job, State) { + return StatusRegistry[Job][State]; + } } function StateMachine_checkCanChangeState(C_Object, Job, State) { - //获取状态信息 - local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State); - //判断是否有 检查能否切换状态函数 - local FuncName = "checkCanChangeState_" + StateInfo.StateName; - if (getroottable().rawin(FuncName)) { - return getroottable()[FuncName](CharacterObject(C_Object)); - } else { - error("没有找到" + FuncName + "函数"); - } - return false; + //获取状态信息 + local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State); + //判断是否有 检查能否切换状态函数 + local FuncName = "checkCanChangeState_" + StateInfo.StateName; + if (getroottable().rawin(FuncName)) { + return getroottable()[FuncName](CharacterObject(C_Object)); + } else { + error("没有找到" + FuncName + "函数"); + } + return false; } function StateMachine_SetState(C_Object, Job, State) { - //获取状态信息 - local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State); - //判断是否有 设置状态函数 - local FuncName = "SetState_" + StateInfo.StateName; - if (getroottable().rawin(FuncName)) { - getroottable()[FuncName](CharacterObject(C_Object)); - } else { - error("没有找到" + FuncName + "函数"); - } - return false; + //获取状态信息 + local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State); + //判断是否有 设置状态函数 + local FuncName = "SetState_" + StateInfo.StateName; + if (getroottable().rawin(FuncName)) { + getroottable()[FuncName](CharacterObject(C_Object)); + } else { + error("没有找到" + FuncName + "函数"); + } + return false; } function StateMachine_ProcState(C_Object, Job, State, DeltaTime) { - //获取状态信息 - local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State); - //判断是否有 设置状态函数 - local FuncName = "ProcState_" + StateInfo.StateName; - if (getroottable().rawin(FuncName)) { - getroottable()[FuncName](CharacterObject(C_Object), DeltaTime); - } else { - error("没有找到" + FuncName + "函数"); - } - return false; -} \ No newline at end of file + //获取状态信息 + local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State); + //判断是否有 设置状态函数 + local FuncName = "ProcState_" + StateInfo.StateName; + if (getroottable().rawin(FuncName)) { + getroottable()[FuncName](CharacterObject(C_Object), DeltaTime); + } else { + error("没有找到" + FuncName + "函数"); + } + return false; +} diff --git a/internalInterfaceDoc/character/chr_class.nut b/internalInterfaceDoc/character/chr_class.nut new file mode 100644 index 0000000..e69de29 diff --git a/internalInterfaceDoc/func.nut b/internalInterfaceDoc/func.nut new file mode 100644 index 0000000..ddb07c3 --- /dev/null +++ b/internalInterfaceDoc/func.nut @@ -0,0 +1,95 @@ +/** + * + * @function + * @param {any} C_Object + * @param {integer} state + * @returns {void} + */ +function sq_SetState(C_Object, state) {} + +/** + * + * @function + * @param {any} C_Object + * @param {any} key + * + * @returns {void} + */ +function sq_SetAction(C_Object, key) {} + +/** + * + * @function + * @param {any} C_Object + * @returns {void} + */ +function sq_GetSpeed(C_Object) {} + +/** + * + * @function + * @param {any} C_Object + * @param {integer} x + * @param {integer} y + * @param {integer} z + * @returns {void} + */ +function sq_SetSpeed(C_Object, x, y, z) {} + +/** + * + * @function + * @param {any} C_Object + * @returns {void} + */ +function sq_GetPosition(C_Object) {} + +/** + * + * @function + * @param {any} C_Object + * @param {integer} x + * @param {integer} y + * @param {integer} z + * @returns {void} + */ +function sq_SetPosition(C_Object, x, y, z) {} + +/** + * + * @function + * @param {any} C_Object + * @param {string} Name + * @param {any} Type + * @returns {void} + */ +function sq_GetVars(C_Object, Name, Type) {} + +/** + * + * @function + * @param {any} C_Object + * @param {string} Name + * @param {any} Type + * @param {any} Value + * @returns {void} + */ +function sq_SetVars(C_Object, Name, Type, Value) {} + +/** + * + * @function + * @param {any} C_Object + * @returns {void} + */ +function sq_GetDirection(C_Object) { + +} +/** + * + * @function + * @param {any} C_Object + * @param {integer} Dir + * @returns {void} + */ +function sq_SetDirection(C_Object, Dir) {} diff --git a/internalInterfaceDoc/文档注释须知.nut b/internalInterfaceDoc/文档注释须知.nut new file mode 100644 index 0000000..b876d3c --- /dev/null +++ b/internalInterfaceDoc/文档注释须知.nut @@ -0,0 +1,83 @@ +//Type Squirrel的类型名称与squirrel一致 + +//integer->整数 +//float->浮点数 +//array或者[]代表任意类型数组 +//table->{} +//string->字符串 +//boolean->布尔值 + +//文档注释中指定类型的数组应该这么做 + +/** + * Description placeholder + * @param {array(integer)} args + */ +function arrayExample(args) {} + +//任意类型的数组应该这么做 + +/** + * + * @function + * @param {array} args + * @returns {void} //如果不写@returns 代表返回null,{void}或{*}代表返回any + */ +function anyArrayExample(args) {} + +//以下是其他类型的文档注释示例 +/** + * + * @function + * @param {integer} args + * @returns {void} + */ +function intExample(args) {} + +/** + * + * @function + * @param {float} args + * @returns {void} + */ +function floatExample(args) {} + +/** + * Description placeholder + * @param {string} args + */ +function stringExample(args) {} + +/** + * + * @function + * @param {boolean} args + * @returns {void} + */ +function boolExample(args) {} + +/** + * + * @function + * @param {table} args + * @returns {void} + */ +function tableExample(args) {} + +//以下是内联提示与hover +local a = 1; +local b = "1"; +local c = 1.1; +local d = false; +local t = {}; +local arr = []; +local intArr = [1]; +local floatArr = [1.1]; +local strArr = ["str"]; +local anyArr = []; + +//以下是二元表达式类型推断 +local x = 1 + 1; +local x1 = 1 / 1; +local x2 = 1 * 0.1; +local x3 = (1 + 1).tofloat() + (1 / 2).tofloat();