-
-
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.
- Loading branch information
1 parent
bea61a6
commit 11a0368
Showing
79 changed files
with
339 additions
and
99 deletions.
There are no files selected for viewing
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.
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.
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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file not shown.
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
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,72 @@ | ||
import React from 'react' | ||
import Svg, { Image, Circle } from 'react-native-svg' | ||
import { Asset, ImageAsset } from '../../Asset' | ||
import { Buffer } from 'buffer' | ||
import { bufferToString } from '@consento/crypto/util/buffer' | ||
import { Placement } from '../../styles/Component' | ||
import { Color } from '../../styles/Color' | ||
import { exists } from '../../util/exists' | ||
|
||
const hairs = [ | ||
{ below: Asset.avatarHairBelow1, above: Asset.avatarHairAbove1 }, | ||
{ below: Asset.avatarHairBelow2, above: Asset.avatarHairAbove2 }, | ||
{ below: Asset.avatarHairBelow3, above: Asset.avatarHairAbove3 } | ||
] | ||
|
||
function matchingProperties <T> (item: any, reg: RegExp): T[] { | ||
return Object.keys(item).filter(key => reg.test(key)).map(key => item[key]) | ||
} | ||
|
||
const faces = matchingProperties <() => ImageAsset>(Asset, /^avatarFace/) | ||
const noses = matchingProperties <() => ImageAsset>(Asset, /^avatarNose/) | ||
const mouths = matchingProperties <() => ImageAsset>(Asset, /^avatarMouth/) | ||
const eyes = matchingProperties <() => ImageAsset>(Asset, /^avatarEyes/) | ||
const colors = matchingProperties <string>(Color, /^avatar/) | ||
|
||
function oneOf (list: any[]): number { | ||
const index = (list.length * Math.random()) | 0 | ||
return index % list.length | ||
} | ||
|
||
export function randomAvatarId (): string { | ||
const buffer = Buffer.alloc(13) | ||
buffer[0] = 1 | ||
buffer.writeUInt16LE(oneOf(hairs), 1) | ||
buffer.writeUInt16LE(oneOf(faces), 3) | ||
buffer.writeUInt16LE(oneOf(noses), 5) | ||
buffer.writeUInt16LE(oneOf(mouths), 7) | ||
buffer.writeUInt16LE(oneOf(eyes), 9) | ||
buffer.writeUInt16LE(oneOf(colors), 11) | ||
return bufferToString(buffer, 'hex') | ||
} | ||
|
||
const combinations = hairs.length * faces.length * noses.length * mouths.length * eyes.length * colors.length | ||
|
||
console.log(`${combinations.toString()} possible Avatar combinations`) | ||
|
||
export interface IAvatarProps { | ||
avatarId: string | ||
place: Placement | ||
} | ||
|
||
export const Avatar = ({ avatarId, place }: IAvatarProps): JSX.Element => { | ||
if (!exists(avatarId)) { | ||
return Asset.avatarUnknown().img({ ...place.style(), position: 'absolute' }) | ||
} | ||
const buffer = Buffer.from(avatarId, 'hex') | ||
const hair = hairs[buffer.readUInt16LE(1)] | ||
const face = faces[buffer.readUInt16LE(3)] | ||
const nose = noses[buffer.readUInt16LE(5)] | ||
const mouth = mouths[buffer.readUInt16LE(7)] | ||
const eye = eyes[buffer.readUInt16LE(9)] | ||
const color = colors[buffer.readUInt16LE(11)] | ||
return <Svg width={place.width} height={place.height} viewBox='0 0 200 200' style={{ position: 'absolute', left: place.left, top: place.top }}> | ||
<Circle cx={100} cy={100} r={100} fill={color} /> | ||
<Image href={hair.below().source} /> | ||
<Image href={face().source} /> | ||
<Image href={eye().source} /> | ||
<Image href={nose().source} /> | ||
<Image href={mouth().source} /> | ||
<Image href={hair.above().source} /> | ||
</Svg> | ||
} |
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
Oops, something went wrong.