Created
December 19, 2020 20:53
-
-
Save Utopiah/c5f5efe89446d629dad8dba8cfe57dde to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import {loadAssetsFromURLs, getAvatarFromName, getFirstElementFromHash, objects3DFromPartialName} from './utils'; | |
var emojiPrefix = 'emoji-' | |
var nafPrefix = 'naf-' | |
function emojiRadarScript(){ | |
var refreshEmojis = setInterval( updateEmojis, 500 ) | |
} | |
function updateEmojis(){ | |
var avatars = document.querySelectorAll("[networked-avatar]") | |
for (var a of avatars){ | |
var emoji = '๐' | |
if (a.id == "avatar-rig") emoji = '๐' | |
var pos = a.object3D.position | |
var el = document.getElementById(emojiPrefix+a.id) | |
if (!el){ el = addEmojiPerson(a.id, emoji) } | |
updateEmojiPerson(el, 50 + pos.x * 10, 50 + pos.z * 10) | |
} | |
cleanUpZombies() | |
} | |
function cleanUpZombies(){ | |
for (var e of document.querySelectorAll('[id*="'+emojiPrefix+nafPrefix+'"]') ) { | |
if (! document.getElementById( e.id.replace(emojiPrefix, '') ) ) e.remove() | |
} | |
} | |
function addEmojiPerson(id, emoji){ | |
var el = document.createElement("span") | |
document.body.appendChild(el) | |
el.innerText = emoji | |
el.style.position = 'fixed' | |
el.style['z-index'] = 1000 | |
el.id = emojiPrefix + id | |
return el | |
} | |
function updateEmojiPerson(el, x, y){ | |
el.style.top = x+'px' | |
el.style.left = y+'px' | |
} | |
export { emojiRadarScript }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment