Skip to content

Commit

Permalink
more progress and get rid of some redundant type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
saboooor committed Jun 13, 2024
1 parent c8c0ef9 commit 6be64c3
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 388 deletions.
10 changes: 5 additions & 5 deletions src/analyze/functions/analyzeProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export default async function analyzeProfile(id: string) {
const jvm_version = sampler.metadata.systemStatistics.java.version;

if (flags.includes('-XX:+UseZGC') && flags.includes('-Xmx')) {
const flaglist = flags.split(' ');
flaglist.forEach((flag: string) => {
const flaglist: string[] = flags.split(' ');
flaglist.forEach((flag) => {
if (flag.startsWith('-Xmx')) {
let max_mem = flag.split('-Xmx')[1].toLowerCase();
max_mem = max_mem.replace('g', '000');
Expand All @@ -105,8 +105,8 @@ export default async function analyzeProfile(id: string) {
if (!flags.includes('-XX:+UseG1GC') && jvm_version.startsWith('1.8.')) fields.push({ name: '❌ Aikar\'s Flags', value: 'You must use G1GC when using Aikar\'s flags.' });
if (flags.includes('-Xmx')) {
let max_mem = 0;
const flaglist = flags.split(' ');
flaglist.forEach((flag: string) => {
const flaglist: string[] = flags.split(' ');
flaglist.forEach((flag) => {
if (flag.startsWith('-Xmx')) {
flag = flag.split('-Xmx')[1].toLowerCase();
flag = flag.replace('g', '000');
Expand All @@ -118,7 +118,7 @@ export default async function analyzeProfile(id: string) {
if (1000 * sampler.metadata.platformStatistics.playerCount / max_mem > 6 && max_mem < 10000) fields.push({ name: '❌ Low Memory', value: 'You should be using more RAM with this many players.' });
if (flags.includes('-Xms')) {
let min_mem = 0;
flaglist.forEach((flag: string) => {
flaglist.forEach((flag) => {
if (flag.startsWith('-Xms')) {
flag = flag.split('-Xms')[1].toLowerCase();
flag = flag.replace('g', '000');
Expand Down
10 changes: 5 additions & 5 deletions src/analyze/functions/analyzeTimings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export default async function analyzeTimings(id: string) {
const flags = request.timingsMaster.system.flags;
const jvm_version = request.timingsMaster.system.jvmversion;
if (flags.includes('-XX:+UseZGC') && flags.includes('-Xmx')) {
const flaglist = flags.split(' ');
flaglist.forEach((flag: string) => {
const flaglist: string[] = flags.split(' ');
flaglist.forEach((flag) => {
if (flag.startsWith('-Xmx')) {
let max_mem = flag.split('-Xmx')[1].toLowerCase();
max_mem = max_mem.replace('g', '000');
Expand All @@ -102,8 +102,8 @@ export default async function analyzeTimings(id: string) {
if (!flags.includes('-XX:+UseG1GC') && jvm_version.startsWith('1.8.')) fields.push({ name: '❌ Aikar\'s Flags', value: 'You must use G1GC when using Aikar\'s flags.' });
if (flags.includes('-Xmx')) {
let max_mem = 0;
const flaglist = flags.split(' ');
flaglist.forEach((flag: string) => {
const flaglist: string[] = flags.split(' ');
flaglist.forEach((flag) => {
if (flag.startsWith('-Xmx')) {
flag = flag.split('-Xmx')[1].toLowerCase();
flag = flag.replace('g', '000');
Expand All @@ -124,7 +124,7 @@ export default async function analyzeTimings(id: string) {
if (1000 * max_online_players / max_mem > 6 && max_mem < 10000) fields.push({ name: '❌ Low Memory', value: 'You should be using more RAM with this many players.' });
if (flags.includes('-Xms')) {
let min_mem = 0;
flaglist.forEach((flag: string) => {
flaglist.forEach((flag) => {
if (flag.startsWith('-Xms')) {
flag = flag.split('-Xms')[1].toLowerCase();
flag = flag.replace('g', '000');
Expand Down
58 changes: 45 additions & 13 deletions src/components/util/PresetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface format {

declare interface preset {
version: number;
colors: string[];
colors: { hex: string; pos: number }[];
name: string;
text: string;
type: number;
Expand All @@ -29,15 +29,47 @@ declare interface preset {
}

export const presets = {
'birdflop': ['#084CFB', '#ADF3FD'],
'SimplyMC': ['#00FFE0', '#EB00FF'],
'Rainbow': ['#FF0000', '#FF7F00', '#FFFF00', '#00FF00', '#0000FF', '#4B0082', '#9400D3'],
'Skyline': ['#1488CC', '#2B32B2'],
'Mango': ['#FFE259', '#FFA751'],
'Vice City': ['#3494E6', '#EC6EAD'],
'Dawn': ['#F3904F', '#3B4371'],
'Rose': ['#F4C4F3', '#FC67FA'],
'Firewatch': ['#CB2D3E', '#EF473A'],
'birdflop': [
{ hex: '#084CFB', pos: 0 },
{ hex: '#ADF3FD', pos: 100 },
],
'SimplyMC': [
{ hex: '#00FFE0', pos: 0 },
{ hex: '#EB00FF', pos: 100 },
],
'Rainbow': [
{ hex: '#FF0000', pos: 0 },
{ hex: '#FF7F00', pos: 16.66 },
{ hex: '#FFFF00', pos: 33.33 },
{ hex: '#00FF00', pos: 50 },
{ hex: '#0000FF', pos: 66.66 },
{ hex: '#4B0082', pos: 83.33 },
{ hex: '#9400D3', pos: 100 },
],
'Skyline': [
{ hex: '#1488CC', pos: 0 },
{ hex: '#2B32B2', pos: 100 },
],
'Mango': [
{ hex: '#FFE259', pos: 0 },
{ hex: '#FFA751', pos: 100 },
],
'Vice City': [
{ hex: '#3494E6', pos: 0 },
{ hex: '#EC6EAD', pos: 100 },
],
'Dawn': [
{ hex: '#F3904F', pos: 0 },
{ hex: '#3B4371', pos: 100 },
],
'Rose': [
{ hex: '#F4C4F3', pos: 0 },
{ hex: '#FC67FA', pos: 100 },
],
'Firewatch': [
{ hex: '#CB2D3E', pos: 0 },
{ hex: '#EF473A', pos: 100 },
],
};

export const v3formats = [
Expand Down Expand Up @@ -81,7 +113,7 @@ export const types = [
];

export const defaults: preset = {
version: 3,
version: 4,
colors: presets.birdflop,
name: 'logo',
text: 'birdflop',
Expand Down Expand Up @@ -163,8 +195,8 @@ const v1formats = {
},
};

export function fromBinary(encoded: string): string {
let binary: string;
export function fromBinary(encoded: string) {
let binary;
try {
binary = atob(encoded);
} catch (error) {
Expand Down
21 changes: 9 additions & 12 deletions src/components/util/RGBUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AnimatedGradient, Gradient } from './HexUtils';
import type { format } from './PresetUtils';
import { defaults } from './PresetUtils';

export function hex(c: number) {
Expand Down Expand Up @@ -43,8 +42,8 @@ export function getRandomColor() {
return color;
}

export function getAnimFrames(store: any) {
let colors = store.colors.map((color: string) => convertToRGB(color));
export function getAnimFrames(store: typeof defaults) {
let colors = store.colors.map(color => convertToRGB(color.hex));
if (colors.length < 2) colors = [convertToRGB('#00FFE0'), convertToRGB('#EB00FF')];

const text = store.text ?? 'birdflop';
Expand Down Expand Up @@ -115,15 +114,15 @@ export function getAnimFrames(store: any) {
return { OutputArray, frames };
}

export function AnimationOutput(store: any) {
export function AnimationOutput(store: typeof defaults) {
let FinalOutput = '';

const AnimFrames = getAnimFrames(store);
let { OutputArray } = AnimFrames;

const format = store.outputFormat;
FinalOutput = format.replace('%name%', store.name);
FinalOutput = FinalOutput.replace('%speed%', store.speed);
FinalOutput = FinalOutput.replace('%speed%', `${store.speed}`);
if (store.type == 1) {
OutputArray.reverse();
}
Expand All @@ -133,17 +132,15 @@ export function AnimationOutput(store: any) {
}

const outputFormat = FinalOutput.match(/%output:{(.*\$t.*)}%/);
if (outputFormat) {
OutputArray = OutputArray.map((output: string) => outputFormat[1].replace('$t', output));
}
if (outputFormat) OutputArray = OutputArray.map(output => outputFormat[1].replace('$t', output));
FinalOutput = FinalOutput.replace(/%output:{.*\$t.*}%/, OutputArray.join('\n'));
return FinalOutput;
}

export function generateOutput(
text: string = defaults.text,
colors: string[] = defaults.colors,
format: format = defaults.format,
text = defaults.text,
colors = defaults.colors,
format = defaults.format,
prefixsuffix?: string,
trimspaces?: boolean,
bold?: boolean,
Expand All @@ -157,7 +154,7 @@ export function generateOutput(
output += `<gradient:${colors.join(':')}>${text}</gradient>`;
}

const newColors = colors?.map((color: string) => convertToRGB(color));
const newColors = colors?.map(color => convertToRGB(color.hex));
while (newColors.length < 2) newColors.push(convertToRGB(getRandomColor()));

const gradient = new Gradient(newColors, text.length);
Expand Down
6 changes: 5 additions & 1 deletion src/components/util/SharedUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ export const setCookies = function (json: { [key: string]: any; }) {
console.debug('cookie', key, encodedValue);
document.cookie = `${key}=${encodedValue}; path=/`;
});
};
};

export function sortColors(colors: { hex: string, pos: number }[]) {
return [...colors].sort((a, b) => a.pos - b.pos);
}
3 changes: 1 addition & 2 deletions src/routes/resources/animpreview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export default component$(() => {
const pattern = /&(#[0-9A-Fa-f]{6})?(&[0-9A-Fa-fk-or])?(&[0-9A-Fa-fk-or])?(&[0-9A-Fa-fk-or])?(&[0-9A-Fa-fk-or])([^&]*)/;
const spans = store.frames[store.frame].match(new RegExp(pattern, 'g'));
return spans.map((string: string, i: number) => {
let result: any = string.match(pattern);
result = result.filter((obj: string) => { return obj; });
const result: any = string.match(pattern);
return (
<span key={`char${i}`} style={{ color: result[1] }} class={{
'underline': result.includes('&n'),
Expand Down
Loading

0 comments on commit 6be64c3

Please sign in to comment.