Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty components and plugins with options #730

Merged
merged 5 commits into from
Jun 30, 2023
Merged

empty components and plugins with options #730

merged 5 commits into from
Jun 30, 2023

Conversation

lajbel
Copy link
Contributor

@lajbel lajbel commented Jun 18, 2023

Plugins

No plugins, no type

If there is not a plugins property inside KaboomOpt, it only returns KaboomCtx

Before

image
Now

image

Options in plugins

Now there's a support for options in plugins

Normal plugins

function logPlugin(k: KaboomCtx) {
    return {
        logWidth() {
            return {
                id: "logWidth",
                log() {
                    k.debug.log(k.width());
                },
            };
        },
        logHeight() {
            return {
                id: "logHeight",
                log() {
                    k.debug.log(k.height());
                },
            };
        },
    };
}

Plugins with options

function newLogPlugin(log: "width" | "height") {
    return (k: KaboomCtx) => {
        return {
            logRes() {
                return {
                    id: "hello",
                    log() {
                        k.debug.log(k[log]());
                    },
                }
            },
        };
    };
}

They work both
image

Component

Empty Component type

This was a big odyssey, basically I discovered MergeObj<T> doesn't work good when there are types with not required properties (for example, Comp type), so my first solution was doing this

type LifespanComp = Comp & { id: string }
type MoveComp = Comp & { id: string }

This fixes the problem without don't have required properties, because now id is required, and we got this result

image

But if there's two duplicated values in an Union, typescript ignores one, so this can happen

image

One is ignored, and looks strange, so I made EmptyComp, it represents a Comp with an id, but without nothing more, so, if there are 2 components that returns an EmptyComp, it makes sense with the returned object type. It should fix #691

image

@lajbel lajbel changed the title Improve TS in plugins and comps and create plugins with options empty components and plugins with options Jun 18, 2023
src/kaboom.ts Outdated
tex.width = img.width
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have to ignore here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried remove them and don't get any warnings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this one image

@slmjkdbtl
Copy link
Contributor

Thank you this is amazing

@slmjkdbtl slmjkdbtl merged commit aa44a62 into master Jun 30, 2023
1 check passed
@slmjkdbtl slmjkdbtl deleted the lj-improve-ts branch June 30, 2023 19:25
tristanperrow added a commit to tristanperrow/kaboom_fork that referenced this pull request Dec 5, 2023
* Add blockly editor (replit#667)

* add more blocks

* clean

* use kaboom_ prefix

* improve

* stuff

* shadow

* blocks

* kinda make callback work

* add stuff

* stuff

* dynamic add block

* clean

* add hasOutput option

* yes!!!!

* better movement

* improve color

* add add block checks

* misc

* local images

* fix example

* add more icons

* more icons

* kinda fix size

* fix ts

* fix initial resize event

* fix mem leak on resize

* alpha.24

* only import types from types.ts, fix import issue

* prep v3000 beta, update site

* fix ts

* fix site crash

* add icons

* upgrade deps

* update site deps

* add embed editor for articles

* rm unused deps

* gravity() -> setGravity() / getGravity(), more 3000 blog

* support LoadFontOpt

* improve text outline

* text atlas lineJoin

* Fixed testLineCircle (replit#671)

* Improve gamepad support (replit#672)

* Add support for Nintendo's Pro Controller

* Fix mapping for `Joy-Con L+R` gamepad

* Add support for using a single Joy-Con

* Add new accepted values to `GamepadButton` type

* add custom gamepads support

* add xbox360 gamepad

* tmp workaround for correct audio.time() when looped

* rm generic gamepad to fallback to default

* send 0.0 to stick events

* rename dpad buttons

* rm follow()

* revert removing follow()

* fix doc render

* froggy -> bean

* fix get/set cursor

* beta.0

* fix example and blog twitter card

* Fix broken link (replit#677)

* use better gamepad default

* add setCursorLocked()

* add AgentCompOpt to agent() type (replit#685)

* add AgentCompOpt to agent() type

* make opt optional

---------

Co-authored-by: tga <[email protected]>

* update readme (replit#680)

* update readme

* remove 0.5 doc from misc section

* fix details, add dots and update examples code (replit#679)

* add final dots and update some doc

* fmt and update addLevel example

* repos elements in hover demo

* fix concert demo, and music code example

* fix shooter example music

* add src/app.ts

* adopt app.ts

* fix err in migration guide

* fix objects not falling off platform when not overlapping

* improve drag example

* fix type

* fix ts error

* fix events not running for recursive children

* fix mouse pos

* prevent volumn go below 0

* fix sprite having 0 width height on load

* fix spriteatlas breaking

* cleaning

* fix events not clear when scene switch

* add amount health arg to onHurt / onHeal

* forward kabooom opt to app

* support maxFPS

* beta.4

* update deps

* add 404 to dev server

* Kaboom gamepads (replit#698)

Co-authored-by: tga <[email protected]>

* rm redundent

* add loadJSON() and getAsset()

* switch to tauri

* use tauri for create-kaboom

* rm unused code

* automatically clean up events registered in comp.add

* add unuse example

* fix tween type, add loop and tween to timer() comp

* tie timer comonent wait with game object

* remove params to timer()

* fix timer references

* mention tauri + rust in create-kaboom readme

* Fix file type in setup.md. (replit#703)

The file type of the horse sound was wrong (png), so i changed it to mp3.

also fixed a typo.

* doc

* add onSceneLeave

* add README to create-kaboom projs

* tauri icon

* fix tiled sprite

* better fix

* replace all object assign to not mutate original opt

* fix anim 0 error

* deal with resize

* fix more sizing issues

* fix letterbox!

* fix letterbox resizing

* fix fulllscreen

* clean

* fix global scale

* rm virtual control

* v3000 stable

* fix onclick

* isTouchscreen typo

* Remove concept tutorials, fix many refs and links (replit#719)

* remove concept tutorials, fix many refs and links

* fix

* update intro screenshots (replit#720)

* add make()

* fix for `debug.inspect` doesn't show the properties box if the area is from a child of a child replit#716 (replit#722)

* bug fix release

* add typing for plugins in `kaboom()` returns (replit#727)

* fix some ts errors, add MergePlugins

* fix mini typo

* mention create-kaboom in setup

* add back legacy endpoints

* fix global scale

* fix: ignore errors from other sources (replit#723)

This e.g. happens with iframes.
Seems to fix replit#466

* Bump tauri from 1.2.4 to 1.2.5 in /src-tauri (replit#710)

Bumps [tauri](https://github.com/tauri-apps/tauri) from 1.2.4 to 1.2.5.
- [Release notes](https://github.com/tauri-apps/tauri/releases)
- [Commits](tauri-apps/tauri@tauri-v1.2.4...tauri-v1.2.5)

---
updated-dependencies:
- dependency-name: tauri
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* dont init draw state until draw phase

* 3000.0.6

* fix vit import

* fix types

* fix some types

* recursively run destroy event to children

* fix ts and drawCircle

* shake() adds up instead of replace

* fix accessing mouse pos in touch events

* fix relateive touch pos

* empty components and plugins with options (replit#730)

* improve ts of plugins

* better plug

* empty comps

* lit generic type fix in kaboom()

* remove unrelated ts-ignore

* fix fixed inheritence

* alternative fixed fix

* version

* update dep

* downgrade puppeteer

* delete unused

* try

* refactor scripts

* update site deps

* Update types.ts (replit#743)

Adds a comment explaining the usage of Texture.free() and it's importance

* doc: fix OffScreenCompOpt.distance default value (replit#738)

The value is actually 200 in [source](https://github.com/replit/kaboom/blob/aa44a62999b6b510c24e317fc76ffc64524e9680/src/kaboom.ts#L3743C1-L3744C1)

* type `GameObjRaw#onAdd` (replit#737)

* Fix kenney assets link (replit#733)

* Expose clamp() math helper (replit#732)

* Expose clamp()

* Add clamp in types.ts

* Bump word-wrap from 1.2.3 to 1.2.5 in /pkgs/matter (replit#751)

Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.5.
- [Release notes](https://github.com/jonschlinkert/word-wrap/releases)
- [Commits](jonschlinkert/word-wrap@1.2.3...1.2.5)

---
updated-dependencies:
- dependency-name: word-wrap
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump semver from 6.3.0 to 6.3.1 in /site (replit#749)

Bumps [semver](https://github.com/npm/node-semver) from 6.3.0 to 6.3.1.
- [Release notes](https://github.com/npm/node-semver/releases)
- [Changelog](https://github.com/npm/node-semver/blob/v6.3.1/CHANGELOG.md)
- [Commits](npm/node-semver@v6.3.0...v6.3.1)

---
updated-dependencies:
- dependency-name: semver
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat: support pingpong loop for sprite anim (replit#745)

* feat: support pingpong loop for sprite anim

* format: better indents

* fmt

* change default logMax to 10 (replit#736)

* add log time

* deps

* input events on game obj

* workaround

* deps

* clean up, changelog

* fix background audio, expose onHide and onShow events

* tips

* rm dup

* misc fix

* fix debug.timeScale

* fix debug.paused not able to resume

* fix sprite quad not working

* stop audio on error

* SpriteData#width

* fix collide update still running when obj paused

* allow empty add() and make()

* improve err msg

* add audio.stop()

* add Event#clear()

* fix add() without arguments

* fix changelog

* fix typings

* fix debug paused not pausing audio

* add mask() and colored font outline

* naming

* only handle own error

* misc

* update text width immediately

* fix debug ui when scale & size are set (replit#755)

* v3000.1.8

* add fill option

* add kaboomware site

* update deps

* site

* site

* fix view getting cut off, update deps

* fix test code accidentally getting shipped

* fix resize event gets cleared on scene change

* use tex / framebuf binder stack

* fix toImageData flipped

* fix mousepos in fullscreen

* add Color#toHSL()

* fix err

* version

* fix color not working, add confetti example

* fix site

* add draw field to render comps

* rm site

* use gfx.ts

* cleaning

* cleaning, modulizing assets

* fix shader error report

* improve deepeq

* fix moving platform

* Fix emoji display in text (replit#771)

* Fix emoji display in text

* Fix emoji text color

* cleaning

* fmt & improvements

* use overload helper

* fix maxhp

* start adding offscreen canvas

* rm global err hand

* update deps

* misc fix

* Add polygon component (replit#774)

* Initial commit of polygon component. Updates types, adds the logic, and provised a real boring example in examples/

* Fixes a linting issues in examples/polygon.js

* Removes extraneous comment, reorders components to polygon() is first in example

* nit: Fixes newlines in import

* Updates the polygon fn to return a polygon render area, which makes it so that polygons always collide with their shape not a rect

* Use this.pnts instead of just pnts so we can capture any updates to points later

* pass polygon() opts into drawPolygon()

* improve polygon example

* fix loadRoot not working sometimes

* fix error not being logged

* expose velocity

* improve jump example

* v3000.1.17

* add drag

* fix: skip zero-width character render (replit#787)

* update intro inspect img (replit#785)

* fix: err TS2339 (replit#788)

* support anim pingpong without loop

* improve doc

* improve doc

* fix sizing issue with global scale

* Fix puppeteer deprecated warning (replit#791)

* Fix puppeteer deprecated warning

* format

---------

Co-authored-by: tga <[email protected]>

* Fix example in types.ts (replit#794)

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: tga <[email protected]>
Co-authored-by: Marc Flerackers <[email protected]>
Co-authored-by: Nestor Vera <[email protected]>
Co-authored-by: Sean <[email protected]>
Co-authored-by: Danie <[email protected]>
Co-authored-by: kingerious <[email protected]>
Co-authored-by: Hayden Mankin <[email protected]>
Co-authored-by: Pelle Johnsen <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: coding398 <[email protected]>
Co-authored-by: Nami W <[email protected]>
Co-authored-by: Luiz Bills <[email protected]>
Co-authored-by: hirnsalat <[email protected]>
Co-authored-by: 陆陆侠 <[email protected]>
Co-authored-by: trevordilley <[email protected]>
Co-authored-by: Neerajkumar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TS move() comp returns Comp type, and that "bugs" add() return type
2 participants