Skip to content

Commit ea5a489

Browse files
committed
fix: improve signs viewer by allow to copy position and select signs
1 parent 9dfff40 commit ea5a489

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

prismarine-viewer/viewer/lib/worldrendererThree.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ export class WorldRendererThree extends WorldRendererCommon {
2929
super(config)
3030
this.starField = new StarField(scene)
3131
this.holdingBlock = new HoldingBlock(this.scene)
32-
this.onHandItemSwitch({
33-
name: 'furnace',
34-
properties: {}
35-
})
3632

3733
this.renderUpdateEmitter.on('textureDownloaded', () => {
3834
if (this.holdingBlock.toBeRenderedItem) {

src/react/ModuleSignsViewer.tsx

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
1-
import { useEffect, useRef } from 'react'
1+
import { useEffect, useRef, useState } from 'react'
22
import { WorldRendererThree } from 'prismarine-viewer/viewer/lib/worldrendererThree'
33
import FullScreenWidget from './FullScreenWidget'
44

5-
export const name = 'signs'
5+
export const name = 'loaded world signs'
66

77
export default () => {
8+
const [selected, setSelected] = useState([] as string[])
9+
const allSignsPos = [] as string[]
810
const signs = viewer.world instanceof WorldRendererThree ? [...viewer.world.chunkTextures.values()].flatMap(textures => {
911
return Object.entries(textures).map(([signPosKey, texture]) => {
12+
allSignsPos.push(signPosKey)
1013
const pos = signPosKey.split(',').map(Number)
14+
const isSelected = selected.includes(signPosKey)
1115
return <div key={signPosKey}>
12-
<div style={{ color: 'white' }}>{pos.join(', ')}</div>
13-
<div style={{ background: 'rgba(255, 255, 255, 0.5)', padding: 5, borderRadius: 5 }}>
16+
<div style={{ color: 'white', userSelect: 'text', fontSize: 8, }}>{pos.join(', ')}</div>
17+
<div
18+
style={{ background: isSelected ? 'rgba(255, 255, 255, 0.8)' : 'rgba(255, 255, 255, 0.5)', padding: 5, borderRadius: 5, cursor: 'pointer' }}
19+
onClick={() => setSelected(selected.includes(signPosKey) ? selected.filter(x => x !== signPosKey) : [...selected, signPosKey])}>
1420
<AddElem elem={texture.image} />
1521
</div>
1622
</div>
1723
})
1824
}) : []
1925

20-
return <FullScreenWidget name='signs' title='Loaded Signs'>
26+
return <FullScreenWidget name={name} title='Loaded Signs'>
2127
<div>
22-
{signs.length} signs currently loaded:
28+
{signs.length} signs currently in the scene:
2329
</div>
30+
<div
31+
style={{ cursor: 'pointer', }} onClick={() => {
32+
// toggle all
33+
if (selected.length === allSignsPos.length) {
34+
setSelected([])
35+
return
36+
}
37+
setSelected([...allSignsPos])
38+
}}>Select All</div>
39+
{selected.length && <div
40+
style={{ cursor: 'pointer', }} onClick={() => {
41+
void navigator.clipboard.writeText(selected.join('\n'))
42+
}}>Copy Selected Signs</div>}
2443
{signs}
2544
</FullScreenWidget>
2645
}
@@ -29,13 +48,17 @@ const AddElem = ({ elem }) => {
2948
const ref = useRef<HTMLDivElement>(null)
3049
useEffect(() => {
3150
elem.style.width = '100%'
51+
elem.style.height = '100%'
3252
ref.current!.appendChild(elem)
3353
return () => {
3454
elem.remove()
3555
}
3656
}, [])
3757

38-
return <div ref={ref} />
58+
return <div
59+
ref={ref} style={{
60+
height: '35px',
61+
}} />
3962
}
4063

4164
// for (const key of Object.keys(viewer.world.sectionObjects)) {

0 commit comments

Comments
 (0)