Completed basic effect functions (object oriented)

This commit is contained in:
loplkc loplkc 2022-01-20 14:15:42 -05:00
parent d1680bf63c
commit 47bde9f3ce
4 changed files with 430 additions and 381 deletions

View file

@ -3,3 +3,5 @@
The highly unfinished skeleton of an ambitious Roblox game. 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. 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.)

633
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,77 +1,109 @@
const TweenService = game.GetService("TweenService"); const TweenService = game.GetService("TweenService");
type effectKeypoint = [number, Color3, Vector3, CFrame, number, Enum.EasingStyle?, Enum.EasingDirection?]; 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( export interface effectMaker {
effectFolder: Folder, meshPartEffect: (
meshPart: MeshPart, meshPart: MeshPart,
material: Enum.Material, material: Enum.Material,
effectKeypoints: effectKeypoint[], effectKeypoints: effectKeypoint[],
) { priority?: number,
) => void;
particleEffect: () => void;
}
export interface effectRunner {
runEffects: (
timeSinceLastFrame: number
) => void;//(timeSinceLastFrame: number, effectsToRun: effect[]) => effect[]
}
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(); const effectMeshPart = meshPart.Clone();
effectMeshPart.Material = material; effectMeshPart.Material = material;
effectMeshPart.Color = effectKeypoints[0][1]; effectMeshPart.Color = effectKeypoints[0][1];
effectMeshPart.Size = effectKeypoints[0][2]; effectMeshPart.Size = effectKeypoints[0][2];
effectMeshPart.CFrame = effectKeypoints[0][3]; effectMeshPart.CFrame = effectKeypoints[0][3];
effectMeshPart.Transparency = effectKeypoints[0][4]; effectMeshPart.Transparency = effectKeypoints[0][4];
let effectDuration = 0
effectKeypoints.forEach(effectKeypoint => {
effectDuration += effectKeypoint[0]
});
effectMeshPart.CastShadow = false; effectMeshPart.CastShadow = false;
effectMeshPart.CanCollide = false; effectMeshPart.CanCollide = false;
effectMeshPart.Anchored = true; effectMeshPart.Anchored = true;
effectMeshPart.Parent = effectFolder; effectMeshPart.Parent = this.EFFECT_FOLDER;
effectKeypoints.remove(0); // Insert the effect before the effect that will end after it
return [effectMeshPart, effectKeypoints, 0] as [MeshPart, effectKeypoint[], number]; const effectsToRun = this.effectsToRun
// Do the interpolation on one thread somehow for (let index = 0; index < effectsToRun.size(); index += 1) {
} const effectInArray = effectsToRun[index];
let effectInArrayDuration = -effectInArray[0]
function particleEffect() {} effectInArray[1].forEach(effectKeypoint => {
/* effectInArrayDuration += effectKeypoint[0]
function getLerpKeypoint(time: number, pastKeypoint: effectKeypoint, futureKeypoint: effectKeypoint) { });
let alpha = 0; if (effectInArrayDuration > effectDuration) {
if (pastKeypoint[5]) { effectsToRun.insert(index, [0, effectKeypoints, effectMeshPart, priority || 0] as effect);
alpha = TweenService.GetValue(time / futureKeypoint[0], pastKeypoint[5], Enum.EasingDirection.InOut); break
} else {
alpha = time;
}
let new
for (let i = 1; i < 5; i += 1) {
} }
} }
*/ effectsToRun.insert(effectsToRun.size(), [0, effectKeypoints, effectMeshPart, priority || 0] as effect);
},
function runEffects(timeSinceLastFrame: number, effectsToRun: [MeshPart, effectKeypoint[], number][]) { particleEffect: function() {},
runEffects: function(timeSinceLastFrame: number) {
let effectsToRun = this.effectsToRun
for (const effect of effectsToRun) { for (const effect of effectsToRun) {
const meshPart = effect[0]; // Update the effect time
const futureKeypoint = effect[1][1]; let nextKeypoint = effect[1][1];
const timeToNext = futureKeypoint[0]; let timeOfNextKeypoint = nextKeypoint[0];
const timeSinceLastKeypoint = effect[2] + timeSinceLastFrame; let timeSinceLastKeypoint = effect[0] + timeSinceLastFrame;
if (timeSinceLastKeypoint >= timeToNext) { while (timeSinceLastKeypoint >= timeOfNextKeypoint) {
// Remove keypoint if (effect[1][2]) {
// Set effect[3] to 0 timeSinceLastKeypoint -= timeOfNextKeypoint;
// Delete effect if no keypoints left effect[1].remove(0);
nextKeypoint = effect[1][1];
timeOfNextKeypoint = nextKeypoint[0];
} else { } else {
effect[2] = timeSinceLastKeypoint; effect[2].Destroy()
effectsToRun.remove(0)
continue // Move on if this effect is done
} }
const pastKeypoint = effect[1][0]; }
const easingStyle = pastKeypoint[5]; 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 // Get the alpha
let alpha = 0; let alpha = 0;
if (easingStyle) { if (easingStyle) {
alpha = TweenService.GetValue( alpha = TweenService.GetValue(
timeSinceLastKeypoint / timeToNext, timeSinceLastKeypoint / timeOfNextKeypoint,
easingStyle, easingStyle,
pastKeypoint[6] || Enum.EasingDirection.InOut, currentKeypoint[6] || Enum.EasingDirection.InOut,
); );
} else { } else {
alpha = timeSinceLastKeypoint / timeToNext; alpha = timeSinceLastKeypoint / timeOfNextKeypoint;
} }
// Alter the effect // Alter the effect
meshPart.Color = pastKeypoint[1].Lerp(futureKeypoint[1], alpha); meshPart.Color = currentKeypoint[1].Lerp(nextKeypoint[1], alpha);
meshPart.Position = pastKeypoint[2].Lerp(futureKeypoint[2], alpha); meshPart.Position = currentKeypoint[2].Lerp(nextKeypoint[2], alpha);
meshPart.CFrame = pastKeypoint[3].Lerp(futureKeypoint[3], alpha); meshPart.CFrame = currentKeypoint[3].Lerp(nextKeypoint[3], alpha);
meshPart.Transparency = pastKeypoint[4] + (futureKeypoint[4] - pastKeypoint[4]) * 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) local function horseEffModule(o,typ,a1,a2,a3,a4,a5,a6,a7)

View file

@ -1,9 +1,11 @@
// "init": The local script. This script doesn't have to account for any other players. // "init": The local script. This script doesn't have to account for any other players.
const Players = game.GetService("Players"); const Players = game.GetService("Players");
const UserInputService = game.GetService("UserInputService"); const UserInputService = game.GetService("UserInputService");
const RunService = game.GetService("RunService");
const Workspace = game.GetService("Workspace"); const Workspace = game.GetService("Workspace");
import { bindToOutput, messageServer } from "./ClientMessenger"; import { bindToOutput, messageServer } from "./ClientMessenger";
import { handleGuiInput, drawGui, closeGui } from "./GuiHandler"; import { handleGuiInput, drawGui, closeGui } from "./GuiHandler";
import { makeEffectHandler, effectRunner } from "./EffectMaker";
const LOCALPLAYER = Players.LocalPlayer; const LOCALPLAYER = Players.LocalPlayer;
const PLAYERGUI = LOCALPLAYER.WaitForChild("PlayerGui", 1) as PlayerGui; const PLAYERGUI = LOCALPLAYER.WaitForChild("PlayerGui", 1) as PlayerGui;
assert( assert(
@ -58,3 +60,11 @@ function handleOutput(messageType: unknown, messageContent: unknown) {
// Action phase // Action phase
UserInputService.InputBegan.Connect(handleInput); UserInputService.InputBegan.Connect(handleInput);
bindToOutput(handleOutput); bindToOutput(handleOutput);
const effectRunners: effectRunner[] = [];
// Put stuff in the effectRunners table
RunService.RenderStepped.Connect(function(deltaTime) {
effectRunners.forEach(effectRunner => {
effectRunner.runEffects(deltaTime)
});
})