Skip to content

Commit

Permalink
some docs for lua part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
khuonghoanghuy committed Dec 26, 2024
1 parent ec269bd commit 58adf82
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 47 deletions.
3 changes: 2 additions & 1 deletion docs/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ For a good starter, please check the [Creating A Game Folder](https://github.com
### Shortcut
* [Setup Game](https://github.com/JoaTH-Team/Cruese-Engine/wiki/Setup-Game)
* [Coding Game](https://github.com/JoaTH-Team/Cruese-Engine/wiki/Coding-Game)
* [Adding Credits](https://github.com/JoaTH-Team/Cruese-Engine/wiki/Adding-Credits)
* [Adding Credits](https://github.com/JoaTH-Team/Cruese-Engine/wiki/Adding-Credits)
* [Lua Code](https://github.com/JoaTH-Team/Cruese-Engine/wiki/Lua-Code)
55 changes: 55 additions & 0 deletions docs/Lua-Code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## Thing to say
Please note that `Lua` on Cruese Engine is still not fully done yet!, lot of function and various thing to adjust is still here, if you wanna code without have missing anything (or something), please go to the [Script Code](https://github.com/JoaTH-Team/Cruese-Engine/wiki/Coding-Game) instead!
## Function/Variable can be used
### Function
* onCreate: Init a newly fresh `PlayState`
* onCreatePost: Go after `onCreate`
* onUpdate: Will update the game every second
* onUpdatePost: Update after `onUpdate`
* onDestroy: Clear some memory?
### Code Function
#### Main Function
* setVar(name, value)
> This one will set a global variable, all lua script can access
* getVar(name)
> This one will get a global variable, all lua script can access
* deleteVar(name)
> This one will delete a global
* callFunction(name, args)
> This one will call a global function, like how `onCreate`, `onUpdate` work, all lua script can access
#### Text Function
* createText(tag, x, y, width, text, size)
> This one will create a text and push a variable onto lua script, all lua script can access thought using `getTextProperty`, `setTextProperty` or other...
* removeText(tag)
> This one will remove a text and also delete a variable from lua script
* reviveText(tag)
> This one will revive a text after using `removeText`, after that, this one will push a variable onto lua script, all lua script can access thought using `getTextProperty`, `setTextProperty` or other...
* destroyText(tag)
> This one will clear up some memory
* setTextColor(tag, color)
> This one will change/set a new color for text, you don't need to add `0xFF` since engine already add this
* setTextActive(tag, bool)
> This one will set active for the text
* setTextVisible(tag, bool)
> This one will set visible for the text
* setTextPosition(tag, x, y)
> This one will set a position by `x` and `y`
* setTextSize(tag, size)
> This one will set how big or small by size number
* setTextString(tag, text)
> This one will set a text content for the text
* setTextFont(tag, font)
> This one will set a new font for the text, if you didn't add the font extension, the default of font extension will be added by `.ttf`
* setTextAlignment(tag, alignment)
> This one will set a alignment for the text
* setTextProperty(tag, property, value)
> This one will set a property by a value from the text
* getTextProperty(tag, property)
> This one will get a property from a text
## Example
```lua
function onCreate()
createText('test1', 0, 0, 0, "Hello World", 32)
end
```
52 changes: 6 additions & 46 deletions source/LuaScript.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import llua.Lua;
import llua.LuaL;
import llua.State;

using StringTools;

class LuaScript extends FlxBasic
{
public static var lua:State;
Expand Down Expand Up @@ -154,58 +156,16 @@ class LuaScript extends FlxBasic
setFunction("setTextFont", function(tag:String, font:String)
{
var text:FlxText = getTagObject("gameText", tag);
return text.font = Paths.font(font);
var fonts:String = font;
if (!fonts.endsWith(".ttf") && !fonts.endsWith(".otf"))
fonts += ".ttf";
return text.font = Paths.font(fonts);
});
setFunction("setTextAlignment", function(tag:String, alignment:String)
{
var text:FlxText = getTagObject("gameText", tag);
return text.alignment = alignment;
});
setFunction("getTextString", function(tag:String)
{
var text:FlxText = getTagObject("gameText", tag);
return text.text;
});
setFunction("getTextWidth", function(tag:String)
{
var text:FlxText = getTagObject("gameText", tag);
return text.width;
});
setFunction("getTextHeight", function(tag:String)
{
var text:FlxText = getTagObject("gameText", tag);
return text.height;
});
setFunction("getTextActive", function(tag:String)
{
var text:FlxText = getTagObject("gameText", tag);
return text.active;
});
setFunction("getTextVisible", function(tag:String)
{
var text:FlxText = getTagObject("gameText", tag);
return text.visible;
});
setFunction("getTextPosition", function(tag:String)
{
var text:FlxText = getTagObject("gameText", tag);
return [text.x, text.y];
});
setFunction("getTextSize", function(tag:String)
{
var text:FlxText = getTagObject("gameText", tag);
return text.size;
});
setFunction("getTextColor", function(tag:String)
{
var text:FlxText = getTagObject("gameText", tag);
return text.color;
});
setFunction("getTextAlignment", function(tag:String)
{
var text:FlxText = getTagObject("gameText", tag);
return text.alignment;
});
setFunction("setTextProperty", function(tag:String, property:String, value:Dynamic)
{
var text:FlxText = getTagObject("gameText", tag);
Expand Down

0 comments on commit 58adf82

Please sign in to comment.