Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
add log time
Browse files Browse the repository at this point in the history
  • Loading branch information
slmjkdbtl committed Aug 2, 2023
1 parent 6060a4c commit cd06f89
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 9 deletions.
46 changes: 45 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,48 @@
# v3000.0.0 (Unreleased)
## v3000.1.0

- added `make()` to create game object without adding to the scene
```js
const obj = make([
sprite("bean"),
pos(120, 60),
])

add(obj)
```

- fixed children not inheriting `fixed()` from parent
```js
// before
const ui = add([
fixed(),
])

ui.add([
rect(),
// have to also give all children game objects fixed()
fixed(),
])

// now
const ui = add([
fixed(),
])

// you don't have to add fixed() to children
ui.add([
rect(100, 100),
])
```

- fixed `AreaComp#onClick()` event not getting cleaned up when game object is destroyed
- fixed typo `isTouchScreen()` -> `isTouchscreen()`
- fixed inspect mode doesn't show the properties box of indirect children game objects
- fixed some problem causing kaboom to not work with vite
- fixed "destroy" event not run on children game objects
- calling `shake()` when another shake is happening adds to the shake instead of reset it?
- fixed incorrect touch position when canvas is not at top left of page

# v3000.0.0

## Game Objects

Expand Down
31 changes: 24 additions & 7 deletions src/kaboom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ const UV_PAD = 0.1
const DEF_HASH_GRID_SIZE = 64
const DEF_FONT_FILTER = "nearest"

const LOG_MAX = 10
const LOG_MAX = 8
const LOG_TIME = 4

const VERTEX_FORMAT = [
{ name: "a_pos", size: 2 },
Expand Down Expand Up @@ -2900,8 +2901,10 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
clearLog: () => game.logs = [],
log: (msg) => {
const max = gopt.logMax ?? LOG_MAX
const style = msg instanceof Error ? "error" : "info"
game.logs.unshift(`${`[time]${app.time().toFixed(2)}[/time] `}[${style}]${msg?.toString ? msg.toString() : msg}[/${style}]`)
game.logs.unshift({
msg: msg,
time: app.time(),
})
if (game.logs.length > max) {
game.logs = game.logs.slice(0, max)
}
Expand Down Expand Up @@ -3603,9 +3606,10 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {

// get the screen position (transformed by camera)
screenPos(this: GameObj<PosComp | FixedComp>): Vec2 {
const pos = this.worldPos()
return this.fixed
? this.pos
: toScreen(this.pos)
? pos
: toScreen(pos)
},

inspect() {
Expand Down Expand Up @@ -3755,7 +3759,7 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
id: "offscreen",
require: [ "pos" ],
isOffScreen(this: GameObj<PosComp>): boolean {
const pos = toScreen(this.pos)
const pos = this.screenPos()
const screenRect = new Rect(vec2(0), width(), height())
return !testRectPoint(screenRect, pos)
&& screenRect.sdistToPoint(pos) > distance * distance
Expand Down Expand Up @@ -6333,9 +6337,22 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
pushTranslate(8, -8)

const pad = 8
const logs = []

for (const log of game.logs) {
let str = ""
const style = log.msg instanceof Error ? "error" : "info"
str += `[time]${log.time.toFixed(2)}[/time]`
str += " "
str += `[${style}]${log.msg?.toString ? log.msg.toString() : log.msg}[/${style}]`
logs.push(str)
}

game.logs = game.logs
.filter((log) => app.time() - log.time < (gopt.logTime || LOG_TIME))

const ftext = formatText({
text: game.logs.join("\n"),
text: logs.join("\n"),
font: DBG_FONT,
pos: vec2(pad, -pad),
anchor: "botleft",
Expand Down
8 changes: 7 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2466,9 +2466,15 @@ export interface KaboomOpt<T extends PluginList<any> = any> {
*/
texFilter?: TexFilter,
/**
* How many log messages can there be on one screen.
* How many log messages can there be on one screen (default 8).
*/
logMax?: number,
/**
* How many seconds log messages stay on screen (default 4).
*
* @since v3000.1
*/
logTime?: number,
/**
* Size of the spatial hash grid for collision detection (default 64).
*
Expand Down

0 comments on commit cd06f89

Please sign in to comment.