Completed basic effect functions (object oriented)
This commit is contained in:
parent
d1680bf63c
commit
47bde9f3ce
4 changed files with 430 additions and 381 deletions
|
@ -3,3 +3,5 @@
|
|||
The highly unfinished skeleton of an ambitious Roblox game.
|
||||
|
||||
This is a Rojo project that uses Roblox-ts. You can compile it and play it yourself if you have Rojo and Roblox-ts installed. However, I cannot guarantee that it will actually work.
|
||||
|
||||
(Remember to use `npm up` before attempting to edit or compile.)
|
635
package-lock.json
generated
635
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,77 +1,109 @@
|
|||
const TweenService = game.GetService("TweenService");
|
||||
type effectKeypoint = [number, Color3, Vector3, CFrame, number, Enum.EasingStyle?, Enum.EasingDirection?];
|
||||
type effect = [number, effectKeypoint[], MeshPart, number] // Time since last keypoint, effect keypoints, effect meshPart, effect priority
|
||||
|
||||
export function meshPartEffect(
|
||||
effectFolder: Folder,
|
||||
meshPart: MeshPart,
|
||||
material: Enum.Material,
|
||||
effectKeypoints: effectKeypoint[],
|
||||
) {
|
||||
const effectMeshPart = meshPart.Clone();
|
||||
effectMeshPart.Material = material;
|
||||
|
||||
effectMeshPart.Color = effectKeypoints[0][1];
|
||||
effectMeshPart.Size = effectKeypoints[0][2];
|
||||
effectMeshPart.CFrame = effectKeypoints[0][3];
|
||||
effectMeshPart.Transparency = effectKeypoints[0][4];
|
||||
|
||||
effectMeshPart.CastShadow = false;
|
||||
effectMeshPart.CanCollide = false;
|
||||
effectMeshPart.Anchored = true;
|
||||
effectMeshPart.Parent = effectFolder;
|
||||
effectKeypoints.remove(0);
|
||||
return [effectMeshPart, effectKeypoints, 0] as [MeshPart, effectKeypoint[], number];
|
||||
// Do the interpolation on one thread somehow
|
||||
export interface effectMaker {
|
||||
meshPartEffect: (
|
||||
meshPart: MeshPart,
|
||||
material: Enum.Material,
|
||||
effectKeypoints: effectKeypoint[],
|
||||
priority?: number,
|
||||
) => void;
|
||||
particleEffect: () => void;
|
||||
}
|
||||
|
||||
function particleEffect() {}
|
||||
/*
|
||||
function getLerpKeypoint(time: number, pastKeypoint: effectKeypoint, futureKeypoint: effectKeypoint) {
|
||||
let alpha = 0;
|
||||
if (pastKeypoint[5]) {
|
||||
alpha = TweenService.GetValue(time / futureKeypoint[0], pastKeypoint[5], Enum.EasingDirection.InOut);
|
||||
} else {
|
||||
alpha = time;
|
||||
}
|
||||
let new
|
||||
for (let i = 1; i < 5; i += 1) {
|
||||
|
||||
}
|
||||
export interface effectRunner {
|
||||
runEffects: (
|
||||
timeSinceLastFrame: number
|
||||
) => void;//(timeSinceLastFrame: number, effectsToRun: effect[]) => effect[]
|
||||
}
|
||||
*/
|
||||
|
||||
function runEffects(timeSinceLastFrame: number, effectsToRun: [MeshPart, effectKeypoint[], number][]) {
|
||||
for (const effect of effectsToRun) {
|
||||
const meshPart = effect[0];
|
||||
const futureKeypoint = effect[1][1];
|
||||
const timeToNext = futureKeypoint[0];
|
||||
const timeSinceLastKeypoint = effect[2] + timeSinceLastFrame;
|
||||
if (timeSinceLastKeypoint >= timeToNext) {
|
||||
// Remove keypoint
|
||||
// Set effect[3] to 0
|
||||
// Delete effect if no keypoints left
|
||||
} else {
|
||||
effect[2] = timeSinceLastKeypoint;
|
||||
}
|
||||
const pastKeypoint = effect[1][0];
|
||||
const easingStyle = pastKeypoint[5];
|
||||
// Get the alpha
|
||||
let alpha = 0;
|
||||
if (easingStyle) {
|
||||
alpha = TweenService.GetValue(
|
||||
timeSinceLastKeypoint / timeToNext,
|
||||
easingStyle,
|
||||
pastKeypoint[6] || Enum.EasingDirection.InOut,
|
||||
);
|
||||
} else {
|
||||
alpha = timeSinceLastKeypoint / timeToNext;
|
||||
}
|
||||
// Alter the effect
|
||||
meshPart.Color = pastKeypoint[1].Lerp(futureKeypoint[1], alpha);
|
||||
meshPart.Position = pastKeypoint[2].Lerp(futureKeypoint[2], alpha);
|
||||
meshPart.CFrame = pastKeypoint[3].Lerp(futureKeypoint[3], alpha);
|
||||
meshPart.Transparency = pastKeypoint[4] + (futureKeypoint[4] - pastKeypoint[4]) * alpha;
|
||||
interface effectHandler extends effectMaker, effectRunner {
|
||||
EFFECT_FOLDER: Folder;
|
||||
effectsToRun: effect[]
|
||||
}
|
||||
|
||||
export function makeEffectHandler(effectFolder: Folder) {
|
||||
const effectHandler: effectHandler = {
|
||||
meshPartEffect: function(meshPart: MeshPart, material: Enum.Material, effectKeypoints: effectKeypoint[], priority?: number) {
|
||||
const effectMeshPart = meshPart.Clone();
|
||||
effectMeshPart.Material = material;
|
||||
effectMeshPart.Color = effectKeypoints[0][1];
|
||||
effectMeshPart.Size = effectKeypoints[0][2];
|
||||
effectMeshPart.CFrame = effectKeypoints[0][3];
|
||||
effectMeshPart.Transparency = effectKeypoints[0][4];
|
||||
let effectDuration = 0
|
||||
effectKeypoints.forEach(effectKeypoint => {
|
||||
effectDuration += effectKeypoint[0]
|
||||
});
|
||||
effectMeshPart.CastShadow = false;
|
||||
effectMeshPart.CanCollide = false;
|
||||
effectMeshPart.Anchored = true;
|
||||
effectMeshPart.Parent = this.EFFECT_FOLDER;
|
||||
// Insert the effect before the effect that will end after it
|
||||
const effectsToRun = this.effectsToRun
|
||||
for (let index = 0; index < effectsToRun.size(); index += 1) {
|
||||
const effectInArray = effectsToRun[index];
|
||||
let effectInArrayDuration = -effectInArray[0]
|
||||
effectInArray[1].forEach(effectKeypoint => {
|
||||
effectInArrayDuration += effectKeypoint[0]
|
||||
});
|
||||
if (effectInArrayDuration > effectDuration) {
|
||||
effectsToRun.insert(index, [0, effectKeypoints, effectMeshPart, priority || 0] as effect);
|
||||
break
|
||||
}
|
||||
}
|
||||
effectsToRun.insert(effectsToRun.size(), [0, effectKeypoints, effectMeshPart, priority || 0] as effect);
|
||||
},
|
||||
particleEffect: function() {},
|
||||
runEffects: function(timeSinceLastFrame: number) {
|
||||
let effectsToRun = this.effectsToRun
|
||||
for (const effect of effectsToRun) {
|
||||
// Update the effect time
|
||||
let nextKeypoint = effect[1][1];
|
||||
let timeOfNextKeypoint = nextKeypoint[0];
|
||||
let timeSinceLastKeypoint = effect[0] + timeSinceLastFrame;
|
||||
while (timeSinceLastKeypoint >= timeOfNextKeypoint) {
|
||||
if (effect[1][2]) {
|
||||
timeSinceLastKeypoint -= timeOfNextKeypoint;
|
||||
effect[1].remove(0);
|
||||
nextKeypoint = effect[1][1];
|
||||
timeOfNextKeypoint = nextKeypoint[0];
|
||||
} else {
|
||||
effect[2].Destroy()
|
||||
effectsToRun.remove(0)
|
||||
continue // Move on if this effect is done
|
||||
}
|
||||
}
|
||||
effect[0] = timeSinceLastKeypoint;
|
||||
// Get the rest of the variables
|
||||
const currentKeypoint = effect[1][0];
|
||||
const easingStyle = currentKeypoint[5];
|
||||
const meshPart = effect[2];
|
||||
// Get the alpha
|
||||
let alpha = 0;
|
||||
if (easingStyle) {
|
||||
alpha = TweenService.GetValue(
|
||||
timeSinceLastKeypoint / timeOfNextKeypoint,
|
||||
easingStyle,
|
||||
currentKeypoint[6] || Enum.EasingDirection.InOut,
|
||||
);
|
||||
} else {
|
||||
alpha = timeSinceLastKeypoint / timeOfNextKeypoint;
|
||||
}
|
||||
// Alter the effect
|
||||
meshPart.Color = currentKeypoint[1].Lerp(nextKeypoint[1], alpha);
|
||||
meshPart.Position = currentKeypoint[2].Lerp(nextKeypoint[2], alpha);
|
||||
meshPart.CFrame = currentKeypoint[3].Lerp(nextKeypoint[3], alpha);
|
||||
meshPart.Transparency = currentKeypoint[4] + (nextKeypoint[4] - currentKeypoint[4]) * alpha;
|
||||
}
|
||||
//this = effectsToRun;
|
||||
},
|
||||
|
||||
EFFECT_FOLDER: effectFolder,
|
||||
effectsToRun: [],
|
||||
}
|
||||
return effectHandler;
|
||||
}
|
||||
/*
|
||||
local function horseEffModule(o,typ,a1,a2,a3,a4,a5,a6,a7)
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
// "init": The local script. This script doesn't have to account for any other players.
|
||||
const Players = game.GetService("Players");
|
||||
const UserInputService = game.GetService("UserInputService");
|
||||
const RunService = game.GetService("RunService");
|
||||
const Workspace = game.GetService("Workspace");
|
||||
import { bindToOutput, messageServer } from "./ClientMessenger";
|
||||
import { handleGuiInput, drawGui, closeGui } from "./GuiHandler";
|
||||
import { makeEffectHandler, effectRunner } from "./EffectMaker";
|
||||
const LOCALPLAYER = Players.LocalPlayer;
|
||||
const PLAYERGUI = LOCALPLAYER.WaitForChild("PlayerGui", 1) as PlayerGui;
|
||||
assert(
|
||||
|
@ -58,3 +60,11 @@ function handleOutput(messageType: unknown, messageContent: unknown) {
|
|||
// Action phase
|
||||
UserInputService.InputBegan.Connect(handleInput);
|
||||
bindToOutput(handleOutput);
|
||||
|
||||
const effectRunners: effectRunner[] = [];
|
||||
// Put stuff in the effectRunners table
|
||||
RunService.RenderStepped.Connect(function(deltaTime) {
|
||||
effectRunners.forEach(effectRunner => {
|
||||
effectRunner.runEffects(deltaTime)
|
||||
});
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue