-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from joshuacurtiss/settings
Add Settings Screens
- Loading branch information
Showing
27 changed files
with
1,049 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Comp, GameObj } from 'kaboom'; | ||
|
||
export interface ActionComp extends Comp { | ||
get action(): Function; | ||
set action(newFn: Function); | ||
}; | ||
|
||
export function isActionComp(obj: GameObj): obj is GameObj<ActionComp> { | ||
return obj.is('can-action'); | ||
} | ||
|
||
function wrapAction(newFn: Function, prevFn: Function): Function { | ||
return ()=>{ | ||
prevFn(); | ||
newFn(); | ||
}; | ||
} | ||
|
||
export function action(actionFunction: Function = ()=>{}): ActionComp { | ||
let actionFn: Function; | ||
return { | ||
id: 'can-action', | ||
get action() { | ||
return actionFn; | ||
}, | ||
set action(newFn: Function) { | ||
const defaultFn = ()=>this.trigger('action', this); | ||
actionFn = wrapAction(newFn, defaultFn); | ||
}, | ||
add() { | ||
this.action = actionFunction; | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { | ||
AnchorComp, | ||
AreaComp, | ||
Color, | ||
ColorComp, | ||
Comp, | ||
GameObj, | ||
PosComp, | ||
RectComp, | ||
RectCompOpt, | ||
TextComp, | ||
TextCompOpt, | ||
Vec2, | ||
} from 'kaboom'; | ||
import { k } from '../kaboom'; | ||
import { ActionComp, action } from './Action'; | ||
import { FocusComp, focus } from './Focus'; | ||
|
||
const { | ||
add, | ||
anchor, | ||
area, | ||
color, | ||
pos, | ||
rgb, | ||
rect, | ||
setCursor, | ||
text, | ||
vec2, | ||
width, | ||
BLACK, | ||
} = k; | ||
|
||
export type Button = GameObj<RectComp & AnchorComp & PosComp & AreaComp & ColorComp & ActionComp & FocusComp & ButtonComp>; | ||
|
||
export interface ButtonComp extends Comp { | ||
get text(): string; | ||
set text(newLabel: string); | ||
textObj?: GameObj<AnchorComp & TextComp>; | ||
} | ||
|
||
export interface ButtonCompOpt { | ||
color: Color; | ||
focusColor: Color; | ||
pos: Vec2; | ||
width: number; | ||
height: number; | ||
text: string; | ||
action: Function; | ||
rectOpt: RectCompOpt; | ||
textOpt: TextCompOpt; | ||
}; | ||
|
||
export const ButtonCompOptDefaults: ButtonCompOpt = { | ||
color: BLACK, | ||
focusColor: rgb(80, 80, 80), | ||
pos: vec2(0), | ||
width: width()/2, | ||
height: 18, | ||
text: 'Button', | ||
action: ()=>{}, | ||
rectOpt: { radius: 2 }, | ||
textOpt: { size: 8 }, | ||
}; | ||
|
||
export function button(options: Partial<ButtonCompOpt> = {}): ButtonComp { | ||
const opt = Object.assign({}, ButtonCompOptDefaults, options); | ||
return { | ||
id: 'button', | ||
require: ['can-action', 'can-focus', "color"], | ||
get text(): string { | ||
return this.textObj.text; | ||
}, | ||
set text(newText: string) { | ||
this.textObj.text = newText; | ||
}, | ||
add() { | ||
this.textObj = this.add([ | ||
anchor('center'), | ||
text(opt.text, opt.textOpt), | ||
]); | ||
this.on('blur', ()=>this.color = opt.color); | ||
this.on('focus', ()=>this.color = opt.focusColor); | ||
this.onClick(this.action); | ||
this.onHover(this.focus); | ||
this.onHoverUpdate(()=>setCursor('pointer')); | ||
}, | ||
}; | ||
} | ||
|
||
export function addButton(options: Partial<ButtonCompOpt> = {}): Button { | ||
const opt = Object.assign({}, ButtonCompOptDefaults, options); | ||
return add([ | ||
rect(opt.width, opt.height, opt.rectOpt), | ||
anchor('center'), | ||
pos(opt.pos), | ||
area(), | ||
color(opt.color), | ||
action(opt.action), | ||
focus(), | ||
button(opt), | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Comp, GameObj } from 'kaboom'; | ||
|
||
export interface FocusComp extends Comp { | ||
get isBlurred(): boolean; | ||
get isFocused(): boolean; | ||
blur: Function; | ||
focus: Function; | ||
}; | ||
|
||
export function isFocusComp(obj: GameObj): obj is GameObj<FocusComp> { | ||
return obj.is('can-focus'); | ||
} | ||
|
||
export function focus(): FocusComp { | ||
let foc = false; | ||
return { | ||
id: 'can-focus', | ||
get isFocused() { | ||
return foc; | ||
}, | ||
get isBlurred() { | ||
return !foc; | ||
}, | ||
focus() { | ||
foc = true; | ||
this.trigger('focus') | ||
}, | ||
blur() { | ||
foc = false; | ||
this.trigger('blur') | ||
}, | ||
}; | ||
}; |
Oops, something went wrong.