Skip to content

Commit

Permalink
Ghost-s-Utilities -> GhostUtil2
Browse files Browse the repository at this point in the history
Import from last repository
  • Loading branch information
AlsoGhostglowDev authored Feb 9, 2024
1 parent 461e818 commit c2dc2e9
Show file tree
Hide file tree
Showing 39 changed files with 2,542 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 GhostglowDev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Ghost's Utilities

Ghost's Utilities or more known as GhostUtil is a module/addon to Psych Engine to make programming more easier and tidier.
GhostUtil provides a lot of unique variables and functions for you to mess around!

## 2.0 Contributors:
*These are the peoples who contributes to GhostUtil atleast once*
* [GhostglowDev](https://github.com/GhostglowDev)
* [T-Bar](https://github.com/TBar09)
* [galactic_2005](https://github.com/galactic2005)
* [Meloomazy / Laztrix](https://github.com/Meloomazy)
* [Apollo](https://github.com/apollooo7)
* [Flain](https://www.youtube.com/channel/UCQ-WPpDkLX3PdKlTTtAqcsw)

## Other Recommended Library:
* [PEModUtils](https://github.com/galactic2005/PEModUtils) by galactic_2005

## The Basics

### How do I use GhostUtil?
* Add the "ghostutil" folder to the main Psych Engine folder. (where the `.exe` is)

![image](https://github.com/GhostglowDev/Ghost-s-Utilities/assets/108509756/076a2654-46fd-4231-b4ba-2512f4ee880c)

and then, drag-n-drop the `callbackhandler.lua` file to `mods/scripts`

![image](https://github.com/GhostglowDev/Ghost-s-Utilities/assets/108509756/cf993438-85c4-447c-9cb0-0255ebf7a765)

* To use GhostUtil, you must import it's modules; use the `require` function on a variable.
Since we're using base lua functions, this is not needed to be in a function.

![image](https://github.com/GhostglowDev/Ghost-s-Utilities/assets/108509756/d2114b55-ad69-484d-bb8b-6135d544d671)

* Let's try messing with the script!
```lua
local math = require "ghostutil.lua-addons.math"
local game = require "ghostutil.Game"

function onCreate()
luaDebugMode = true
game.doTweenScale("tweenScale", "boyfriend", {2, 2.1}, "expoOut")
game.doTweenPosition({"boyfriendcool", "boyfriendswag"}, "boyfriend", {
game.getPosition("boyfriend").x - 100,
math.boundto(game.getPosition("dad").y + 100, -100, 200)
}, 2, "expoOut")
end
```
This does a tweens boyfriend's scale to 2x it's default size. It also tweens boyfriend's position!

`math.boundto` was to limit the coordinates to reach a certain number

### For more advanced informations:
**CHECK OUT THE [WIKI](https://github.com/GhostglowDev/Ghost-s-Utilities/wiki) FOR MORE FUNCTIONS.**

### Older Versions
**Psych Engine**:

* below 0.6.3:
Mostly because most of the lua functions that GhostUtil use doesn't exist.

* 0.7.1h:
It breaks GhostUtil (mostly because of `runHaxeCode`); so use the latest version or 0.7.3 instead.

**GhostUtil**:

* below 2.0.0a:
When using the `Window` class, add `window.init()` before doing anything with the Window functions/variables
"window" in `window.init()` depends on what you set the variable to. If it's `wind` then `wind.init()`, etc.


* below 1.0.0:
Naming the variable `math` will break the script.
11 changes: 11 additions & 0 deletions examples/modchart/swappin'.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local modchart = require "ghostutil.Modcharts"
local bool = false

function onBeatHit()
if curBeat % 8 == 0 then
bool = not bool
for i = 0,7 do
modchart.swapStrums(bool, 2, "expoOut")
end
end
end
11 changes: 11 additions & 0 deletions examples/modchart/up-n-down.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local modchart = require "ghostutil.Modcharts"
local bool = false

function onBeatHit()
if curBeat % 8 == 0 then
bool = not bool
for i = 0,7 do
modchart.downscroll(i, bool, 2, "expoOut", true)
end
end
end
48 changes: 48 additions & 0 deletions examples/window/better-title.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
local window = require "ghostutil.Window"

-- local defaultTitle = "Friday Night Funkin': Psych Engine // Ghost's Utilities"
local defaultTitle = "Friday Night Funkin': Psych Engine"
local divider1 = " // "
local divider2 = " | "
local started = false

function onCreatePost()
luaDebugMode = true
window.changeTitle(". "..defaultTitle.." | "..songName)
end

function onDestroy()
window.changeTitle(defaultTitle)
end

function onSongStart()
started = true
end

function onCountdownTick(counter)
if counter == 0 then
window.changeTitle(". > Three... <");
elseif counter == 1 then
window.changeTitle(". > Two.. <");
elseif counter == 2 then
window.changeTitle(". > One, <");
elseif counter == 3 then
window.changeTitle(". > GO! <");
end
end

function onUpdate(elapsed)
if started then
window.changeTitle(". "..defaultTitle..divider1..songName.." ["..difficultyName.."] (" .. formatTime(getSongPosition() - noteOffset) .. " / " .. formatTime(songLength) .. ")")
end
end

function onPause(elapsed)
window.changeTitle(". "..defaultTitle..divider1..songName.." ["..difficultyName.."] (Paused)")
end

function formatTime(millisecond) -- thanks moonlight :D
local seconds = math.floor(millisecond / 1000)

return string.format("%01d:%02d", (seconds / 60) % 60, seconds % 60)
end
74 changes: 74 additions & 0 deletions examples/window/fancier-loop.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
--[[
-- DISCLAIMER --
THE SCRIPT WILL MOSTLY *ONLY* WILL WORK ON VANILLA
WEEKS LIKE:
DADDY DEAREST's
PICO's
'and some others we didn't test~'
]]

-- Requires
local window = require "ghostutil.Window"

-- Variables
local started = false

-- EDITABLE VARIABLES
local num = 0.4
local distance = 0 -- this is need to be editable on the onUpdatePost function
local speed = {
x = 1,
y = 2,
}

function onCreatePost()
-- This simply just adds "lime.app.Application" library to the hscript stuffs
window.init()

-- Easy to know when you get an error.
luaDebugMode = true
end

function onSongStart()
started = true
end

function onUpdatePost(elapsed)
num = num + elapsed

-- Another editable variables
local windowOffsets = {
x = 300,
y = 150
}

local hudOffsets = {
x = 0,
y = 0
}

local cameraOffsets = {
x = 700,
y = 450
}

-- The main code, I guess
distance = 50
setProperty("camFollowPos.x", (math.sin(num * speed.x) * distance) + cameraOffsets.x)
setProperty("camFollowPos.y", (math.sin(num * speed.y) * distance) + cameraOffsets.y)

distance = 20
setProperty("camHUD.x", (math.sin(num * speed.x) * distance) + hudOffsets.x)
setProperty("camHUD.y", (math.sin(num * speed.y) * distance) + hudOffsets.y)

distance = 50
window.setProperty("x", (math.sin(num * speed.x) * distance) + windowOffsets.x)
window.setProperty("y", (math.sin(num * speed.y) * distance) + windowOffsets.y)
end

function onDestroy()
-- Centers the window when you're done with the song. (When exit, restarting, going to debug, dying, etc.)
window.screenCenter()
end
43 changes: 43 additions & 0 deletions examples/window/in-a-loop.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- Requires
local window = require "ghostutil.Window"

-- Variables
local started = false

-- EDITABLE VARIABLES
local num = 0.4
local distance = 80
local speed = {
x = 1,
y = 2,
}

function onCreatePost()
-- This simply just adds "lime.app.Application" library to the hscript stuffs
window.init()

-- Easy to know when you get an error.
luaDebugMode = true
end

function onSongStart()
started = true
end

function onUpdatePost(elapsed)
if started then
-- The code for the looping motion
num = num + elapsed
local offset = {
x = 300,
y = 150
}
window.setProperty("x", (math.sin(num * speed.x) * distance) + offset.x)
window.setProperty("y", (math.sin(num * speed.y) * distance) + offset.y)
end
end

function onDestroy()
-- Centers the window when you're done with the song. (When exit, restarting, going to debug, dying, etc.)
window.screenCenter()
end
77 changes: 77 additions & 0 deletions ghostutil/Color.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---@meta Color
---@author GhostglowDev

---@class Color
local color = {}

local d = require "ghostutil.Debug"

color.WHITE = "0xFFFFFFFF"
color.GRAY = "0xFF808080"
color.BLACK = "0xFF000000"

color.RED = "0xFFFF0000"
color.BLUE = "0xFF0000FF"
color.GREEN = "0xFF008000"
color.PINK = "0xFFFFC0CB"
color.MAGENTA = "0xFFFF00FF"
color.PURPLE = "0xFF800080"
color.LIME = "0xFF00FF00"
color.YELLOW = '0xFFFFFF00'
color.ORANGE = "0xFFFFA500"
color.CYAN = "0xFF00FFFF"

---Sets an object color to the target value
---@param spr string Object
---@param val string The target color. (RRGGBB)
color.setSpriteColor = function(spr, val)
if spr ~= nil then setProperty(spr..".color", getColorFromHex (val or "FFFFFF")) else
d.error("color.setSpriteColor:1: Expected a value")
end
end

---Sets an object's color transform to the target values
---@param spr string Object
---@param multipliers table<number> Values: {redMult, blueMult, greenMult, alphaMult}
---@param offsets table<number> Values: {redOffset, blueOffset, greenOffset, alphaOffset}
color.setSpriteColorTransform = function(spr, multipliers, offsets)
local isLuaSprite = luaSpriteExists(spr)

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
d.error("color.setSpriteColorTransform:1: Expected a value")
end

for i = 1, 4 do
if multipliers[i] == nil then d.warning("color.setSpriteColorTransform:2["..i.."]: Given an empty value, nil -> 0") end
if offsets[i] == nil then d.warning("color.setSpriteColorTransform:3["..i.."]: Given an empty value, nil -> 0") end
end
end

---Returns an object color
---@param spr string
---@return string
---@nodiscard
color.getSpriteColor = function(spr)
if spr ~= nil then
return getProperty(spr..".color")
end

d.error("color.getSpriteColor:1: Expected a value")
return ""
end

---Converts RGB to the Hex format (RRGGBB).
---@param r integer
---@param g integer
---@param b integer
---@return string
---@nodiscard
color.rgbToHex = function(r, g, b)
if r == nil or g == nil or b == nil then
d.warning("color.rgbToHex: Given an empty value. nil -> 255")
end

return string.format("%02X%02X%02X", (r or 255), (g or 255), (b or 255))
end

return color
Loading

0 comments on commit c2dc2e9

Please sign in to comment.