Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
4418029d7This file is pinned to the selected release. Download the original to open it in your design tool.
import Avatar from 'avatar'
import { hsl } from 'piu/All'
import CombTransition from 'piu/CombTransition'
import { Application, Color, Content } from 'piu/MC'
import { Robot } from 'robot'
import Timer from 'timer'
export interface StackchanMod {
onLaunch?: () => (Application | undefined)
onApplicationCreated?: (application: Application) => void
onButtonChange?: (buttonName: 'A' | 'B' | 'C', pressed: boolean) => void
onRobotCreated?: (robot: Robot) => void
autoLoop?: boolean
}
// TODO: move file local variables to context hooks
let ap: Application
let avatar: Content
let robot: Robot
let isFollowing: boolean = false
function createAvatar(primaryColor: Color, secondaryColor: Color) {
return new Avatar({
width: 320,
height: 240,
name: 'avatar',
primaryColor,
secondaryColor,
props: {
autoUpdateGaze: false,
},
})
}
function swapFace(primaryColor, secondaryColor) {
const av = createAvatar(primaryColor, secondaryColor)
const transition = new CombTransition(250, Math.quadEaseOut, "horizontal", 4);
ap.run(transition, ap.content("avatar"), av);
}
function onLaunch() {
return undefined
/*
avatar = createAvatar('white', 'black')
const contents = [avatar]
ap = new Application(null, {
displayListLength: 4096,
left: 0,
top: 0,
width: 320,
height: 240,
skin: new Skin({ fill: 'white' }),
contents,
})
return ap
*/
}
function onApplicationCreated() {
/* do nothing */
}
function randomBetween(low: number, high: number): number {
return Math.random() * (high - low) + low
}
function onRobotCreated(r) {
robot = r
const targetLoop = () => {
if (!isFollowing) {
robot.lookAway()
return
}
const x = randomBetween(0.4, 1.0)
const y = randomBetween(-0.4, 0.4)
const z = randomBetween(-0.02, 0.2)
trace(`looking at: [${x}, ${y}, ${z}]\n`)
robot.lookAt([x, y, z])
}
Timer.repeat(targetLoop, 5000)
}
function onButtonChange(button, isPressed) {
if (!isPressed) {
return
}
switch (button) {
case 'A':
isFollowing = !isFollowing
break
case 'B':
const primaryColor = hsl(randomBetween(0, 360), 1.0, 0.5)
const secondaryColor = hsl(randomBetween(0, 360), 1.0, 0.5)
swapFace(primaryColor, secondaryColor)
break
case 'C':
/* noop */
break
}
}
export const defaultMod: StackchanMod = {
onLaunch,
onApplicationCreated,
onRobotCreated,
onButtonChange,
}