Skip to content

Commit

Permalink
Added API docs to Wa bindings. [skip CI]
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Dec 31, 2024
1 parent 8b6f353 commit 3c0aa4b
Show file tree
Hide file tree
Showing 65 changed files with 3,115 additions and 55 deletions.
46 changes: 23 additions & 23 deletions Tools/WasmGen/Dora.h
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ singleton class View
};

value class ActionDef {
/// Creates a new Action object to change a property of a node.
/// Creates a new action definition object to change a property of a node.
///
/// # Arguments
///
Expand All @@ -907,9 +907,9 @@ value class ActionDef {
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
static outside ActionDef ActionDef_Prop @ prop(float duration, float start, float stop, Property prop, EaseType easing);
/// Creates a new Action object to change the color of a node.
/// Creates a new action definition object to change the color of a node.
///
/// # Arguments
///
Expand All @@ -920,9 +920,9 @@ value class ActionDef {
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
static outside ActionDef ActionDef_Tint @ tint(float duration, Color3 start, Color3 stop, EaseType easing);
/// Creates a new Action object to rotate a node by smallest angle.
/// Creates a new action definition object to rotate a node by smallest angle.
///
/// # Arguments
///
Expand All @@ -933,43 +933,43 @@ value class ActionDef {
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
static outside ActionDef ActionDef_Roll @ roll(float duration, float start, float stop, EaseType easing);
/// Creates a new Action object to run a group of actions in parallel.
/// Creates a new action definition object to run a group of actions in parallel.
///
/// # Arguments
///
/// * `defs` - The actions to run in parallel.
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
static outside ActionDef ActionDef_Spawn @ spawn(VecActionDef defs);
/// Creates a new Action object to run a group of actions in sequence.
/// Creates a new action definition object to run a group of actions in sequence.
///
/// # Arguments
///
/// * `defs` - The actions to run in sequence.
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
static outside ActionDef ActionDef_Sequence @ sequence(VecActionDef defs);
/// Creates a new Action object to delay the execution of following action.
/// Creates a new action definition object to delay the execution of following action.
///
/// # Arguments
///
/// * `duration` - The duration of the delay.
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
static outside ActionDef ActionDef_Delay @ delay(float duration);
/// Creates a new Action object to show a node.
/// Creates a new action definition object to show a node.
static outside ActionDef ActionDef_Show @ show();
/// Creates a new Action object to hide a node.
/// Creates a new action definition object to hide a node.
static outside ActionDef ActionDef_Hide @ hide();
/// Creates a new Action object to emit an event.
/// Creates a new action definition object to emit an event.
///
/// # Arguments
///
Expand All @@ -978,9 +978,9 @@ value class ActionDef {
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
static outside ActionDef ActionDef_Emit @ event(string eventName, string msg);
/// Creates a new Action object to move a node.
/// Creates a new action definition object to move a node.
///
/// # Arguments
///
Expand All @@ -991,9 +991,9 @@ value class ActionDef {
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
static outside ActionDef ActionDef_Move @ move_to(float duration, Vec2 start, Vec2 stop, EaseType easing);
/// Creates a new Action object to scale a node.
/// Creates a new action definition object to scale a node.
///
/// # Arguments
///
Expand All @@ -1004,9 +1004,9 @@ value class ActionDef {
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
static outside ActionDef ActionDef_Scale @ scale(float duration, float start, float stop, EaseType easing);
/// Creates a new Action object to do a frame animation. Can only be performed on a Sprite node.
/// Creates a new action definition object to do a frame animation. Can only be performed on a Sprite node.
///
/// # Arguments
///
Expand All @@ -1015,9 +1015,9 @@ value class ActionDef {
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
static outside ActionDef ActionDef_Frame @ frame(string clipStr, float duration);
/// Creates a new Action object to do a frame animation with frames count for each frame. Can only be performed on a Sprite node.
/// Creates a new action definition object to do a frame animation with frames count for each frame. Can only be performed on a Sprite node.
///
/// # Arguments
///
Expand Down
32 changes: 23 additions & 9 deletions Tools/WasmGen/gen.yue
Original file line number Diff line number Diff line change
Expand Up @@ -1323,12 +1323,17 @@ func #{waNewName}.GetRaw() => i64 {
slf = isStatic and "" or "self.raw(), "
"#{docText}\t#{pub}fn #{rustSetterName}(#{slfDecl}val: #{rtTypeIn or rt}) {\n\t\tunsafe { #{cppSetterName}(#{slf}#{rtCast and rtCast('val') or 'val'}) };\n\t}"
waType = getWaType dataType, waName
waDocText = if #docs > 0
text = table.concat docs, '\n'
text\sub(1, 4) .. 'Sets' .. text\sub(4) .. '\n'
else
''
waBinding[] = if isSingleton
"func _#{waNewName}.#{waSetterName}(val: #{waType.argType}) {\n\t#{cppSetterName}(#{waType.convertTo 'val'})\n}"
"#{waDocText}func _#{waNewName}.#{waSetterName}(val: #{waType.argType}) {\n\t#{cppSetterName}(#{waType.convertTo 'val'})\n}"
elseif isStatic
"func #{waNewName}#{waSetterName}(val: #{waType.argType}) {\n\t#{cppSetterName}(#{waType.convertTo 'val'})\n}"
"#{waDocText}func #{waNewName}#{waSetterName}(val: #{waType.argType}) {\n\t#{cppSetterName}(#{waType.convertTo 'val'})\n}"
else
"func #{waNewName}.#{waSetterName}(val: #{waType.argType}) {\n\t#{cppSetterName}(*this.raw, #{waType.convertTo 'val'})\n}"
"#{waDocText}func #{waNewName}.#{waSetterName}(val: #{waType.argType}) {\n\t#{cppSetterName}(*this.raw, #{waType.convertTo 'val'})\n}"
docText = if #docs > 0
text = table.concat docs, '\n\t'
'\t' .. text\sub(1, 4) .. 'Gets' .. text\sub(4) .. '\n'
Expand Down Expand Up @@ -1386,15 +1391,20 @@ func #{waNewName}.GetRaw() => i64 {
return &obj_"
else
"\treturn #{waType.convertFrom item}"
waDocText = if #docs > 0
text = table.concat docs, '\n'
text\sub(1, 4) .. 'Gets' .. text\sub(4) .. '\n'
else
''
waBinding[] = if isSingleton
item = "#{cppGetterName}()"
"func _#{waNewName}.#{waGetterName}() => #{waReturnType} {\n#{waReturn item}\n}"
"#{waDocText}func _#{waNewName}.#{waGetterName}() => #{waReturnType} {\n#{waReturn item}\n}"
elseif isStatic
item = "#{cppGetterName}()"
"func #{waNewName}#{waGetterName}() => #{waReturnType} {\n#{waReturn item}\n}"
"#{waDocText}func #{waNewName}#{waGetterName}() => #{waReturnType} {\n#{waReturn item}\n}"
else
item = "#{cppGetterName}(*this.raw)"
"func #{waNewName}.#{waGetterName}() => #{waReturnType} {\n#{waReturn item}\n}"
"#{waDocText}func #{waNewName}.#{waGetterName}() => #{waReturnType} {\n#{waReturn item}\n}"
else
error "\"#{dataType}\" is not supported."
when "method"
Expand Down Expand Up @@ -1752,6 +1762,10 @@ func #{waNewName}.GetRaw() => i64 {
argsConverted = table.concat ["#{item.converted}" for item in *argItems], ", "
prepareStr = table.concat prepareArgs, "\n"
prepareStr = prepareStr == "" and "" or "#{prepareStr}\n"
waDocText = if #docs > 0
table.concat(docs, '\n') .. '\n'
else
''
waBinding[] = if isSingleton
item = "#{cppFuncName}(#{argsConverted})"
"func _#{waNewName}.#{waFuncName}(#{argsList})#{waReturnType} {
Expand All @@ -1760,7 +1774,7 @@ func #{waNewName}.GetRaw() => i64 {
elseif isCreate
dealOptional = isOptional and "if raw == 0 {\n\t\treturn nil\n\t}\n\tobject := #{waNewName}{}" or "object := #{waNewName}{}"
waFuncName = if funcNewName == "new" then "" else snakeToPascal funcNewName
"func New#{waNewName}#{waFuncName}(#{argsList})#{waReturnType} {
"#{waDocText}func New#{waNewName}#{waFuncName}(#{argsList})#{waReturnType} {
#{prepareStr} raw := #{cppFuncName}(#{argsConverted})
#{dealOptional}
object.raw = &raw
Expand All @@ -1769,12 +1783,12 @@ func #{waNewName}.GetRaw() => i64 {
}"
elseif isStatic
item = "#{cppFuncName}(#{argsConverted})"
"func #{waNewName}#{waFuncName}(#{argsList})#{waReturnType} {
"#{waDocText}func #{waNewName}#{waFuncName}(#{argsList})#{waReturnType} {
#{prepareStr} #{waReturn item}
}"
else
item = "#{cppFuncName}(*this.raw#{argsConverted == "" and "" or ", " .. argsConverted})"
"func #{waNewName}.#{waFuncName}(#{argsList})#{waReturnType} {
"#{waDocText}func #{waNewName}.#{waFuncName}(#{argsList})#{waReturnType} {
#{prepareStr} #{waReturn item}
}"
else
Expand Down
46 changes: 23 additions & 23 deletions Tools/dora-rust/dora/src/dora/action_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl ActionDef {
pub(crate) fn from(raw: i64) -> ActionDef {
ActionDef { raw: raw }
}
/// Creates a new Action object to change a property of a node.
/// Creates a new action definition object to change a property of a node.
///
/// # Arguments
///
Expand All @@ -45,11 +45,11 @@ impl ActionDef {
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
pub fn prop(duration: f32, start: f32, stop: f32, prop: crate::dora::Property, easing: crate::dora::EaseType) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_prop(duration, start, stop, prop as i32, easing as i32)); }
}
/// Creates a new Action object to change the color of a node.
/// Creates a new action definition object to change the color of a node.
///
/// # Arguments
///
Expand All @@ -60,11 +60,11 @@ impl ActionDef {
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
pub fn tint(duration: f32, start: &crate::dora::Color3, stop: &crate::dora::Color3, easing: crate::dora::EaseType) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_tint(duration, start.to_rgb() as i32, stop.to_rgb() as i32, easing as i32)); }
}
/// Creates a new Action object to rotate a node by smallest angle.
/// Creates a new action definition object to rotate a node by smallest angle.
///
/// # Arguments
///
Expand All @@ -75,55 +75,55 @@ impl ActionDef {
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
pub fn roll(duration: f32, start: f32, stop: f32, easing: crate::dora::EaseType) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_roll(duration, start, stop, easing as i32)); }
}
/// Creates a new Action object to run a group of actions in parallel.
/// Creates a new action definition object to run a group of actions in parallel.
///
/// # Arguments
///
/// * `defs` - The actions to run in parallel.
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
pub fn spawn(defs: &Vec<crate::dora::ActionDef>) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_spawn(crate::dora::Vector::from_action_def(defs))); }
}
/// Creates a new Action object to run a group of actions in sequence.
/// Creates a new action definition object to run a group of actions in sequence.
///
/// # Arguments
///
/// * `defs` - The actions to run in sequence.
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
pub fn sequence(defs: &Vec<crate::dora::ActionDef>) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_sequence(crate::dora::Vector::from_action_def(defs))); }
}
/// Creates a new Action object to delay the execution of following action.
/// Creates a new action definition object to delay the execution of following action.
///
/// # Arguments
///
/// * `duration` - The duration of the delay.
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
pub fn delay(duration: f32) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_delay(duration)); }
}
/// Creates a new Action object to show a node.
/// Creates a new action definition object to show a node.
pub fn show() -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_show()); }
}
/// Creates a new Action object to hide a node.
/// Creates a new action definition object to hide a node.
pub fn hide() -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_hide()); }
}
/// Creates a new Action object to emit an event.
/// Creates a new action definition object to emit an event.
///
/// # Arguments
///
Expand All @@ -132,11 +132,11 @@ impl ActionDef {
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
pub fn event(event_name: &str, msg: &str) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_event(crate::dora::from_string(event_name), crate::dora::from_string(msg))); }
}
/// Creates a new Action object to move a node.
/// Creates a new action definition object to move a node.
///
/// # Arguments
///
Expand All @@ -147,11 +147,11 @@ impl ActionDef {
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
pub fn move_to(duration: f32, start: &crate::dora::Vec2, stop: &crate::dora::Vec2, easing: crate::dora::EaseType) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_move_to(duration, start.into_i64(), stop.into_i64(), easing as i32)); }
}
/// Creates a new Action object to scale a node.
/// Creates a new action definition object to scale a node.
///
/// # Arguments
///
Expand All @@ -162,11 +162,11 @@ impl ActionDef {
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
pub fn scale(duration: f32, start: f32, stop: f32, easing: crate::dora::EaseType) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_scale(duration, start, stop, easing as i32)); }
}
/// Creates a new Action object to do a frame animation. Can only be performed on a Sprite node.
/// Creates a new action definition object to do a frame animation. Can only be performed on a Sprite node.
///
/// # Arguments
///
Expand All @@ -175,11 +175,11 @@ impl ActionDef {
///
/// # Returns
///
/// * `Action` - A new Action object.
/// * `ActionDef` - A new ActionDef object.
pub fn frame(clip_str: &str, duration: f32) -> crate::dora::ActionDef {
unsafe { return crate::dora::ActionDef::from(actiondef_frame(crate::dora::from_string(clip_str), duration)); }
}
/// Creates a new Action object to do a frame animation with frames count for each frame. Can only be performed on a Sprite node.
/// Creates a new action definition object to do a frame animation with frames count for each frame. Can only be performed on a Sprite node.
///
/// # Arguments
///
Expand Down
Loading

0 comments on commit 3c0aa4b

Please sign in to comment.