2 Commits

Author SHA1 Message Date
lostluna1
a9b10b88c0 增加文档 2025-10-17 23:37:16 +08:00
f00a65e2f8 20251017 2025-10-17 22:52:16 +08:00
11 changed files with 476 additions and 166 deletions

View File

@@ -5,48 +5,67 @@
文件用途:角色移动脚本 文件用途:角色移动脚本
*/ */
/**
*
* @function
* @param {ActiveObject} obj
* @returns {void}
*/
function checkCanChangeState_Character_Move(obj) { function checkCanChangeState_Character_Move(obj) {
//获取当前状态 //获取当前状态
local CurState = obj.GetState(); local CurState = obj.GetState();
//得到摇杆的数据 X 和 Y的范围 -1.0 ~ 1.0 //得到摇杆的数据 X 和 Y的范围 -1.0 ~ 1.0
local arr = obj.GetVars("_move_data_", "float"); local arr = obj.GetVars("_move_data_", "float");
if (fabs(arr[0]) > 0.35 || fabs(arr[1]) > 0.35) { if (fabs(arr[0]) > 0.35 || fabs(arr[1]) > 0.35) {
return true; return true;
} else return false; } else return false;
} }
/**
*
* @function
* @param {ActiveObject} obj
* @returns {void}
*/
function SetState_Character_Move(obj) { function SetState_Character_Move(obj) {
//获取移动数据 //获取移动数据
local arr = obj.GetVars("_move_data_", "float"); local arr = obj.GetVars("_move_data_", "float");
//设置人物朝向 摇杆X轴大于0则朝右小于0则朝左 //设置人物朝向 摇杆X轴大于0则朝右小于0则朝左
local SetValue = arr[0] > 0 ? 0 : 1; local SetValue = arr[0] > 0 ? 0 : 1;
if (SetValue != obj.GetDirection()) { if (SetValue != obj.GetDirection()) {
if (fabs(arr[0]) > 0.35) obj.SetDirection(SetValue); if (fabs(arr[0]) > 0.35) obj.SetDirection(SetValue);
//设置动作 //设置动作
obj.SetAction("move"); obj.SetAction("move");
} else { } else {
if (obj.GetState() != 1) obj.SetAction("move"); if (obj.GetState() != 1) obj.SetAction("move");
} }
local Speed = 250; local Speed = 250;
local Dir = obj.GetDirection(); local Dir = obj.GetDirection();
local Pos = obj.GetPosition(); local Pos = obj.GetPosition();
local XOffset = null; local XOffset = null;
if (fabs(arr[0]) > 0.35) XOffset = ((arr[0] > 0 ? Speed : -Speed)); if (fabs(arr[0]) > 0.35) XOffset = arr[0] > 0 ? Speed : -Speed;
else XOffset = 0; else XOffset = 0;
local YOffset = null; local YOffset = null;
//当摇杆Y轴大于0.35或小于-0.35时设置Y轴偏移量 //当摇杆Y轴大于0.35或小于-0.35时设置Y轴偏移量
if (fabs(arr[1]) > 0.35) YOffset = (arr[1] > 0 ? Speed : -Speed); if (fabs(arr[1]) > 0.35) YOffset = arr[1] > 0 ? Speed : -Speed;
else YOffset = 0; 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) { function ProcState_Character_Move(obj, DeltaTime) {
//获取移动数据 //获取移动数据
local arr = obj.GetVars("_move_data_", "float"); local arr = obj.GetVars("_move_data_", "float");
if (arr[0] == 0 && arr[1] == 0) { if (arr[0] == 0 && arr[1] == 0) {
obj.SetState(0); obj.SetState(0);
} }
} }

View File

@@ -1,25 +1,35 @@
/* /**
文件名:ActiveObject.nut * Description placeholder
路径:Game/ObjectClass/ActiveObject.nut * @global
创建日期:2025-10-03 02:50 * @param {*} Object
文件用途: */
*/
class ActiveObject extends BaseObject { 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; * @function
if (y == null) y = CurSpeed.y; * @returns {any}
if (z == null) z = CurSpeed.z; */
sq_SetSpeed(C_Object, x, y, z); function GetSpeed() {
} return sq_GetSpeed(C_Object);
}
function GetSpeed() { }
return sq_GetSpeed(C_Object);
}
}

View File

@@ -1,32 +1,75 @@
/**
* Description placeholder
* @param {*} Object
*/
class BaseObject { class BaseObject {
//c++对象指针 //c++对象指针
C_Object = null; C_Object = null;
constructor(Object) { constructor(Object) {
C_Object = 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
* @param {integer} Dir
function SetDirection(Dir) { * @returns {void}
sq_SetDirection(C_Object, Dir); */
} function SetDirection(Dir) {
} sq_SetDirection(C_Object, Dir);
}
}

View File

@@ -1,23 +1,38 @@
/* /**
文件名:CharacterObject.nut * Description placeholder
路径:Game/ObjectClass/CharacterObject.nut * @param {*} Object
创建日期:2025-10-03 02:50 */
文件用途:
*/
class CharacterObject extends ActiveObject { class CharacterObject extends ActiveObject {
constructor(Object) { constructor(Object) {
base.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); *
} * @function
} * @param {any} key
* @returns {void}
*/
function SetAction(key) {
sq_SetAction(C_Object, key);
}
}

View File

@@ -5,81 +5,101 @@
文件用途: 文件用途:
*/ */
/** 状态机
* @global
*/
class StateMachine { class StateMachine {
//状态注册表 //状态注册表
StatusRegistry = null; StatusRegistry = null;
constructor() { constructor() {
if (getroottable().rawin("__StateMachine__")) { if (getroottable().rawin("__StateMachine__")) {
// 防止重复实例化 // 防止重复实例化
throw "StateMachine 不能重复实例化!"; throw "StateMachine 不能重复实例化!";
} }
//初始化状态注册表 //初始化状态注册表
StatusRegistry = {}; StatusRegistry = {};
foreach(JobIndex in getconsttable().CHARACTERJOB) { foreach (JobIndex in getconsttable().CHARACTERJOB) {
StatusRegistry[JobIndex] <- {}; StatusRegistry[JobIndex] <- {};
} }
} }
// 静态方法:获取唯一实例 /**
function GetInstance() { * 静态方法:获取唯一实例
if (!getroottable().rawin("__StateMachine__")) { * @function
// 首次调用时创建实例 * @returns {table}
getroottable()["__StateMachine__"] <- StateMachine(); */
} function GetInstance() {
return getroottable()["__StateMachine__"]; if (!getroottable().rawin("__StateMachine__")) {
} // 首次调用时创建实例
getroottable()["__StateMachine__"] <- StateMachine();
}
return getroottable()["__StateMachine__"];
}
//注册状态 /**
function RegisterState(Job, StateName, StateIndex) { * 注册状态
StatusRegistry[Job][StateIndex] <- { * @function
StateName = StateName, * @param {integer} Job
StateIndex = StateIndex * @param {any} StateName
} * @param {integer} StateIndex
print("注册了状态" + StateName + ",状态索引为" + 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) { function StateMachine_checkCanChangeState(C_Object, Job, State) {
//获取状态信息 //获取状态信息
local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State); local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State);
//判断是否有 检查能否切换状态函数 //判断是否有 检查能否切换状态函数
local FuncName = "checkCanChangeState_" + StateInfo.StateName; local FuncName = "checkCanChangeState_" + StateInfo.StateName;
if (getroottable().rawin(FuncName)) { if (getroottable().rawin(FuncName)) {
return getroottable()[FuncName](CharacterObject(C_Object)); return getroottable()[FuncName](CharacterObject(C_Object));
} else { } else {
error("没有找到" + FuncName + "函数"); error("没有找到" + FuncName + "函数");
} }
return false; return false;
} }
function StateMachine_SetState(C_Object, Job, State) { function StateMachine_SetState(C_Object, Job, State) {
//获取状态信息 //获取状态信息
local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State); local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State);
//判断是否有 设置状态函数 //判断是否有 设置状态函数
local FuncName = "SetState_" + StateInfo.StateName; local FuncName = "SetState_" + StateInfo.StateName;
if (getroottable().rawin(FuncName)) { if (getroottable().rawin(FuncName)) {
getroottable()[FuncName](CharacterObject(C_Object)); getroottable()[FuncName](CharacterObject(C_Object));
} else { } else {
error("没有找到" + FuncName + "函数"); error("没有找到" + FuncName + "函数");
} }
return false; return false;
} }
function StateMachine_ProcState(C_Object, Job, State, DeltaTime) { function StateMachine_ProcState(C_Object, Job, State, DeltaTime) {
//获取状态信息 //获取状态信息
local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State); local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State);
//判断是否有 设置状态函数 //判断是否有 设置状态函数
local FuncName = "ProcState_" + StateInfo.StateName; local FuncName = "ProcState_" + StateInfo.StateName;
if (getroottable().rawin(FuncName)) { if (getroottable().rawin(FuncName)) {
getroottable()[FuncName](CharacterObject(C_Object), DeltaTime); getroottable()[FuncName](CharacterObject(C_Object), DeltaTime);
} else { } else {
error("没有找到" + FuncName + "函数"); error("没有找到" + FuncName + "函数");
} }
return false; return false;
} }

View File

@@ -12,5 +12,5 @@ Game/CharacterScript/Common/Rest.nut
Game/CharacterScript/Common/Move.nut Game/CharacterScript/Common/Move.nut
UI/asd.nut UI/MainUI.nut
main.nut main.nut

22
UI/MainUI.nut Normal file
View File

@@ -0,0 +1,22 @@
/*
文件名:MainUI.nut
路径:UI/MainUI.nut
创建日期:2025-10-11 11:21
文件用途:主界面UI
*/
//主界面UI初始化回调
function _MainUI_Enter_()
{
}
//主界面UI事件回调
function _MainUI_HandleEvents_(event)
{
}
//主界面UI更新回调
function _MainUI_Update_(deltaTime)
{
}
//主界面UI退出回调
function _MainUI_Exit_()
{
}

View File

@@ -28,5 +28,8 @@
}, },
"Game/ObjectClass/CharacterObject.nut": { "Game/ObjectClass/CharacterObject.nut": {
"description": "角色对象" "description": "角色对象"
},
"UI/MainUI.nut": {
"description": "UI入口"
} }
} }

View File

@@ -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) {}

View File

@@ -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();