Skip to content

Commit c2dc2e9

Browse files
Ghost-s-Utilities -> GhostUtil2
Import from last repository
1 parent 461e818 commit c2dc2e9

39 files changed

+2542
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 GhostglowDev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Ghost's Utilities
2+
3+
Ghost's Utilities or more known as GhostUtil is a module/addon to Psych Engine to make programming more easier and tidier.
4+
GhostUtil provides a lot of unique variables and functions for you to mess around!
5+
6+
## 2.0 Contributors:
7+
*These are the peoples who contributes to GhostUtil atleast once*
8+
* [GhostglowDev](https://github.com/GhostglowDev)
9+
* [T-Bar](https://github.com/TBar09)
10+
* [galactic_2005](https://github.com/galactic2005)
11+
* [Meloomazy / Laztrix](https://github.com/Meloomazy)
12+
* [Apollo](https://github.com/apollooo7)
13+
* [Flain](https://www.youtube.com/channel/UCQ-WPpDkLX3PdKlTTtAqcsw)
14+
15+
## Other Recommended Library:
16+
* [PEModUtils](https://github.com/galactic2005/PEModUtils) by galactic_2005
17+
18+
## The Basics
19+
20+
### How do I use GhostUtil?
21+
* Add the "ghostutil" folder to the main Psych Engine folder. (where the `.exe` is)
22+
23+
![image](https://github.com/GhostglowDev/Ghost-s-Utilities/assets/108509756/076a2654-46fd-4231-b4ba-2512f4ee880c)
24+
25+
and then, drag-n-drop the `callbackhandler.lua` file to `mods/scripts`
26+
27+
![image](https://github.com/GhostglowDev/Ghost-s-Utilities/assets/108509756/cf993438-85c4-447c-9cb0-0255ebf7a765)
28+
29+
* To use GhostUtil, you must import it's modules; use the `require` function on a variable.
30+
Since we're using base lua functions, this is not needed to be in a function.
31+
32+
![image](https://github.com/GhostglowDev/Ghost-s-Utilities/assets/108509756/d2114b55-ad69-484d-bb8b-6135d544d671)
33+
34+
* Let's try messing with the script!
35+
```lua
36+
local math = require "ghostutil.lua-addons.math"
37+
local game = require "ghostutil.Game"
38+
39+
function onCreate()
40+
luaDebugMode = true
41+
game.doTweenScale("tweenScale", "boyfriend", {2, 2.1}, "expoOut")
42+
game.doTweenPosition({"boyfriendcool", "boyfriendswag"}, "boyfriend", {
43+
game.getPosition("boyfriend").x - 100,
44+
math.boundto(game.getPosition("dad").y + 100, -100, 200)
45+
}, 2, "expoOut")
46+
end
47+
```
48+
This does a tweens boyfriend's scale to 2x it's default size. It also tweens boyfriend's position!
49+
50+
`math.boundto` was to limit the coordinates to reach a certain number
51+
52+
### For more advanced informations:
53+
**CHECK OUT THE [WIKI](https://github.com/GhostglowDev/Ghost-s-Utilities/wiki) FOR MORE FUNCTIONS.**
54+
55+
### Older Versions
56+
**Psych Engine**:
57+
58+
* below 0.6.3:
59+
Mostly because most of the lua functions that GhostUtil use doesn't exist.
60+
61+
* 0.7.1h:
62+
It breaks GhostUtil (mostly because of `runHaxeCode`); so use the latest version or 0.7.3 instead.
63+
64+
**GhostUtil**:
65+
66+
* below 2.0.0a:
67+
When using the `Window` class, add `window.init()` before doing anything with the Window functions/variables
68+
"window" in `window.init()` depends on what you set the variable to. If it's `wind` then `wind.init()`, etc.
69+
70+
71+
* below 1.0.0:
72+
Naming the variable `math` will break the script.

examples/modchart/swappin'.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
local modchart = require "ghostutil.Modcharts"
2+
local bool = false
3+
4+
function onBeatHit()
5+
if curBeat % 8 == 0 then
6+
bool = not bool
7+
for i = 0,7 do
8+
modchart.swapStrums(bool, 2, "expoOut")
9+
end
10+
end
11+
end

examples/modchart/up-n-down.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
local modchart = require "ghostutil.Modcharts"
2+
local bool = false
3+
4+
function onBeatHit()
5+
if curBeat % 8 == 0 then
6+
bool = not bool
7+
for i = 0,7 do
8+
modchart.downscroll(i, bool, 2, "expoOut", true)
9+
end
10+
end
11+
end

examples/window/better-title.lua

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
local window = require "ghostutil.Window"
2+
3+
-- local defaultTitle = "Friday Night Funkin': Psych Engine // Ghost's Utilities"
4+
local defaultTitle = "Friday Night Funkin': Psych Engine"
5+
local divider1 = " // "
6+
local divider2 = " | "
7+
local started = false
8+
9+
function onCreatePost()
10+
luaDebugMode = true
11+
window.changeTitle(". "..defaultTitle.." | "..songName)
12+
end
13+
14+
function onDestroy()
15+
window.changeTitle(defaultTitle)
16+
end
17+
18+
function onSongStart()
19+
started = true
20+
end
21+
22+
function onCountdownTick(counter)
23+
if counter == 0 then
24+
window.changeTitle(". > Three... <");
25+
elseif counter == 1 then
26+
window.changeTitle(". > Two.. <");
27+
elseif counter == 2 then
28+
window.changeTitle(". > One, <");
29+
elseif counter == 3 then
30+
window.changeTitle(". > GO! <");
31+
end
32+
end
33+
34+
function onUpdate(elapsed)
35+
if started then
36+
window.changeTitle(". "..defaultTitle..divider1..songName.." ["..difficultyName.."] (" .. formatTime(getSongPosition() - noteOffset) .. " / " .. formatTime(songLength) .. ")")
37+
end
38+
end
39+
40+
function onPause(elapsed)
41+
window.changeTitle(". "..defaultTitle..divider1..songName.." ["..difficultyName.."] (Paused)")
42+
end
43+
44+
function formatTime(millisecond) -- thanks moonlight :D
45+
local seconds = math.floor(millisecond / 1000)
46+
47+
return string.format("%01d:%02d", (seconds / 60) % 60, seconds % 60)
48+
end

examples/window/fancier-loop.lua

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
--[[
2+
-- DISCLAIMER --
3+
4+
THE SCRIPT WILL MOSTLY *ONLY* WILL WORK ON VANILLA
5+
WEEKS LIKE:
6+
7+
DADDY DEAREST's
8+
PICO's
9+
'and some others we didn't test~'
10+
]]
11+
12+
-- Requires
13+
local window = require "ghostutil.Window"
14+
15+
-- Variables
16+
local started = false
17+
18+
-- EDITABLE VARIABLES
19+
local num = 0.4
20+
local distance = 0 -- this is need to be editable on the onUpdatePost function
21+
local speed = {
22+
x = 1,
23+
y = 2,
24+
}
25+
26+
function onCreatePost()
27+
-- This simply just adds "lime.app.Application" library to the hscript stuffs
28+
window.init()
29+
30+
-- Easy to know when you get an error.
31+
luaDebugMode = true
32+
end
33+
34+
function onSongStart()
35+
started = true
36+
end
37+
38+
function onUpdatePost(elapsed)
39+
num = num + elapsed
40+
41+
-- Another editable variables
42+
local windowOffsets = {
43+
x = 300,
44+
y = 150
45+
}
46+
47+
local hudOffsets = {
48+
x = 0,
49+
y = 0
50+
}
51+
52+
local cameraOffsets = {
53+
x = 700,
54+
y = 450
55+
}
56+
57+
-- The main code, I guess
58+
distance = 50
59+
setProperty("camFollowPos.x", (math.sin(num * speed.x) * distance) + cameraOffsets.x)
60+
setProperty("camFollowPos.y", (math.sin(num * speed.y) * distance) + cameraOffsets.y)
61+
62+
distance = 20
63+
setProperty("camHUD.x", (math.sin(num * speed.x) * distance) + hudOffsets.x)
64+
setProperty("camHUD.y", (math.sin(num * speed.y) * distance) + hudOffsets.y)
65+
66+
distance = 50
67+
window.setProperty("x", (math.sin(num * speed.x) * distance) + windowOffsets.x)
68+
window.setProperty("y", (math.sin(num * speed.y) * distance) + windowOffsets.y)
69+
end
70+
71+
function onDestroy()
72+
-- Centers the window when you're done with the song. (When exit, restarting, going to debug, dying, etc.)
73+
window.screenCenter()
74+
end

examples/window/in-a-loop.lua

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-- Requires
2+
local window = require "ghostutil.Window"
3+
4+
-- Variables
5+
local started = false
6+
7+
-- EDITABLE VARIABLES
8+
local num = 0.4
9+
local distance = 80
10+
local speed = {
11+
x = 1,
12+
y = 2,
13+
}
14+
15+
function onCreatePost()
16+
-- This simply just adds "lime.app.Application" library to the hscript stuffs
17+
window.init()
18+
19+
-- Easy to know when you get an error.
20+
luaDebugMode = true
21+
end
22+
23+
function onSongStart()
24+
started = true
25+
end
26+
27+
function onUpdatePost(elapsed)
28+
if started then
29+
-- The code for the looping motion
30+
num = num + elapsed
31+
local offset = {
32+
x = 300,
33+
y = 150
34+
}
35+
window.setProperty("x", (math.sin(num * speed.x) * distance) + offset.x)
36+
window.setProperty("y", (math.sin(num * speed.y) * distance) + offset.y)
37+
end
38+
end
39+
40+
function onDestroy()
41+
-- Centers the window when you're done with the song. (When exit, restarting, going to debug, dying, etc.)
42+
window.screenCenter()
43+
end

ghostutil/Color.lua

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---@meta Color
2+
---@author GhostglowDev
3+
4+
---@class Color
5+
local color = {}
6+
7+
local d = require "ghostutil.Debug"
8+
9+
color.WHITE = "0xFFFFFFFF"
10+
color.GRAY = "0xFF808080"
11+
color.BLACK = "0xFF000000"
12+
13+
color.RED = "0xFFFF0000"
14+
color.BLUE = "0xFF0000FF"
15+
color.GREEN = "0xFF008000"
16+
color.PINK = "0xFFFFC0CB"
17+
color.MAGENTA = "0xFFFF00FF"
18+
color.PURPLE = "0xFF800080"
19+
color.LIME = "0xFF00FF00"
20+
color.YELLOW = '0xFFFFFF00'
21+
color.ORANGE = "0xFFFFA500"
22+
color.CYAN = "0xFF00FFFF"
23+
24+
---Sets an object color to the target value
25+
---@param spr string Object
26+
---@param val string The target color. (RRGGBB)
27+
color.setSpriteColor = function(spr, val)
28+
if spr ~= nil then setProperty(spr..".color", getColorFromHex (val or "FFFFFF")) else
29+
d.error("color.setSpriteColor:1: Expected a value")
30+
end
31+
end
32+
33+
---Sets an object's color transform to the target values
34+
---@param spr string Object
35+
---@param multipliers table<number> Values: {redMult, blueMult, greenMult, alphaMult}
36+
---@param offsets table<number> Values: {redOffset, blueOffset, greenOffset, alphaOffset}
37+
color.setSpriteColorTransform = function(spr, multipliers, offsets)
38+
local isLuaSprite = luaSpriteExists(spr)
39+
40+
if spr ~= nil then runHaxeCode("game."..(isLuaSprite and "getLuaObject("..spr..")" or spr)..".setColorTransform("..(multipliers[1] or 0)..", "..(multipliers[2] or 0)..", "..(multipliers[3] or 0)..", "..(multipliers[4] or 0)..", "..(offsets[1] or 0)..", "..(offsets[2] or 0)..", "..(offsets[3] or 0)..", "..(offsets[4] or 0)..");") else
41+
d.error("color.setSpriteColorTransform:1: Expected a value")
42+
end
43+
44+
for i = 1, 4 do
45+
if multipliers[i] == nil then d.warning("color.setSpriteColorTransform:2["..i.."]: Given an empty value, nil -> 0") end
46+
if offsets[i] == nil then d.warning("color.setSpriteColorTransform:3["..i.."]: Given an empty value, nil -> 0") end
47+
end
48+
end
49+
50+
---Returns an object color
51+
---@param spr string
52+
---@return string
53+
---@nodiscard
54+
color.getSpriteColor = function(spr)
55+
if spr ~= nil then
56+
return getProperty(spr..".color")
57+
end
58+
59+
d.error("color.getSpriteColor:1: Expected a value")
60+
return ""
61+
end
62+
63+
---Converts RGB to the Hex format (RRGGBB).
64+
---@param r integer
65+
---@param g integer
66+
---@param b integer
67+
---@return string
68+
---@nodiscard
69+
color.rgbToHex = function(r, g, b)
70+
if r == nil or g == nil or b == nil then
71+
d.warning("color.rgbToHex: Given an empty value. nil -> 255")
72+
end
73+
74+
return string.format("%02X%02X%02X", (r or 255), (g or 255), (b or 255))
75+
end
76+
77+
return color

0 commit comments

Comments
 (0)