mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-18 13:43:27 +00:00
* Tgui: Events & Colors in typescript (#83218) ## About The Pull Request Made more common tgui bits in typescript with tests. Not much else to see here ## Why It's Good For The Game Typescript conversion + More documentation + type safety You now get full docs and type info as nature intended:  --------- Co-authored-by: Style Mistake <stylemistake@ gmail.com> * Tgui: Events & Colors in typescript --------- Co-authored-by: Jeremiah <42397676+jlsnow301@users.noreply.github.com> Co-authored-by: Style Mistake <stylemistake@ gmail.com>
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { Color } from './color';
|
|
|
|
describe('Color', () => {
|
|
it('should create a color with default values', () => {
|
|
const color = new Color();
|
|
expect(color.r).toBe(0);
|
|
expect(color.g).toBe(0);
|
|
expect(color.b).toBe(0);
|
|
expect(color.a).toBe(1);
|
|
});
|
|
|
|
it('should create a color from hex', () => {
|
|
const color = Color.fromHex('#ff0000');
|
|
expect(color.r).toBe(255);
|
|
expect(color.g).toBe(0);
|
|
expect(color.b).toBe(0);
|
|
});
|
|
|
|
it('should darken a color', () => {
|
|
const color = new Color(100, 100, 100).darken(50);
|
|
expect(color.r).toBe(50);
|
|
expect(color.g).toBe(50);
|
|
expect(color.b).toBe(50);
|
|
});
|
|
|
|
it('should lighten a color', () => {
|
|
const color = new Color(100, 100, 100).lighten(50);
|
|
expect(color.r).toBe(150);
|
|
expect(color.g).toBe(150);
|
|
expect(color.b).toBe(150);
|
|
});
|
|
|
|
it('should interpolate between two colors', () => {
|
|
const color1 = new Color(0, 0, 0);
|
|
const color2 = new Color(100, 100, 100);
|
|
const color = Color.lerp(color1, color2, 0.5);
|
|
expect(color.r).toBe(50);
|
|
expect(color.g).toBe(50);
|
|
expect(color.b).toBe(50);
|
|
});
|
|
|
|
it('should lookup a color in an array', () => {
|
|
const colors = [new Color(0, 0, 0), new Color(100, 100, 100)];
|
|
const color = Color.lookup(0.5, colors);
|
|
expect(color.r).toBe(50);
|
|
expect(color.g).toBe(50);
|
|
expect(color.b).toBe(50);
|
|
});
|
|
});
|