Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI updates #257

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions backend/routes/indexer/nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,27 +121,46 @@ func processNFTMintedEvent(event IndexerEvent) {
}
colorPalette[idx] = color.RGBA{R: uint8(r), G: uint8(g), B: uint8(b), A: 255}
}

// Scale factors
scaleFactor := 10
scaledWidth := width * int64(scaleFactor)
scaledHeight := height * int64(scaleFactor)

// Create a new image with scaled dimensions
generatedImage := image.NewRGBA(image.Rect(0, 0, int(scaledWidth), int(scaledHeight)))

bitWidth := int64(core.ArtPeaceBackend.CanvasConfig.ColorsBitWidth)
startX := int64(position % int64(core.ArtPeaceBackend.CanvasConfig.Canvas.Width))
startY := int64(position / int64(core.ArtPeaceBackend.CanvasConfig.Canvas.Width))
oneByteBitOffset := int64(8 - bitWidth)
twoByteBitOffset := int64(16 - bitWidth)
generatedImage := image.NewRGBA(image.Rect(0, 0, int(width), int(height)))

for y := startY; y < startY+height; y++ {
for x := startX; x < startX+width; x++ {
pos := y*int64(core.ArtPeaceBackend.CanvasConfig.Canvas.Width) + x
bitPos := pos * bitWidth
bytePos := bitPos / 8
bitOffset := bitPos % 8
if bitOffset <= oneByteBitOffset {
colorIdx := (canvas[bytePos] >> (oneByteBitOffset - bitOffset)) & 0b11111
generatedImage.Set(int(x-startX), int(y-startY), colorPalette[colorIdx])
} else {
colorIdx := (((uint16(canvas[bytePos]) << 8) | uint16(canvas[bytePos+1])) >> (twoByteBitOffset - bitOffset)) & 0b11111
generatedImage.Set(int(x-startX), int(y-startY), colorPalette[colorIdx])

// Calculate the scaled position
for dy := 0; dy < scaleFactor; dy++ {
for dx := 0; dx < scaleFactor; dx++ {
scaledX := int(x-startX)*scaleFactor + dx
scaledY := int(y-startY)*scaleFactor + dy

if bitOffset <= oneByteBitOffset {
colorIdx := (canvas[bytePos] >> (oneByteBitOffset - bitOffset)) & 0b11111
generatedImage.Set(scaledX, scaledY, colorPalette[colorIdx])
} else {
colorIdx := (((uint16(canvas[bytePos]) << 8) | uint16(canvas[bytePos+1])) >> (twoByteBitOffset - bitOffset)) & 0b11111
generatedImage.Set(scaledX, scaledY, colorPalette[colorIdx])
}
}
}
}
}

// TODO: Check if file exists
if _, err := os.Stat("nfts"); os.IsNotExist(err) {
err = os.MkdirAll("nfts", os.ModePerm)
Expand Down Expand Up @@ -183,7 +202,6 @@ func processNFTMintedEvent(event IndexerEvent) {
}

// Create a NFT JSON metadata file

x := position % int64(core.ArtPeaceBackend.CanvasConfig.Canvas.Width)
y := position / int64(core.ArtPeaceBackend.CanvasConfig.Canvas.Width)
metadata := map[string]interface{}{
Expand All @@ -193,11 +211,11 @@ func processNFTMintedEvent(event IndexerEvent) {
"attributes": []map[string]interface{}{
{
"trait_type": "Width",
"value": fmt.Sprintf("%d", width),
"value": fmt.Sprintf("%d", scaledWidth),
},
{
"trait_type": "Height",
"value": fmt.Sprintf("%d", height),
"value": fmt.Sprintf("%d", scaledHeight),
},
{
"trait_type": "Position",
Expand Down
23 changes: 20 additions & 3 deletions frontend/src/footer/PixelSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const PixelSelector = (props) => {
// Track when a placement is available

const [placementTimer, setPlacementTimer] = useState('XX:XX');
const [placementMode, setPlacementMode] = useState(false);
const [ended, setEnded] = useState(false);

useEffect(() => {
if (props.queryAddress === '0') {
Expand All @@ -29,11 +31,23 @@ const PixelSelector = (props) => {
// TODO: Use lowest timer out of base, chain, faction, ...
setPlacementTimer(props.basePixelTimer);
}
if (
placementTimer === '0:00' &&
placementMode &&
placementTimer !== 'Out of Pixels' &&
placementTimer !== 'Login to Play'
) {
setEnded(true);
} else {
setEnded(false);
}
}, [
props.availablePixels,
props.availablePixelsUsed,
props.basePixelTimer,
props.queryAddress
props.queryAddress,
placementTimer,
placementMode
]);

const toSelectorMode = (event) => {
Expand All @@ -51,6 +65,7 @@ const PixelSelector = (props) => {
if (props.availablePixels > props.availablePixelsUsed) {
props.setSelectorMode(true);
props.setIsEraserMode(false);
setPlacementMode(true);
}
};

Expand All @@ -62,12 +77,14 @@ const PixelSelector = (props) => {
const cancelSelector = () => {
props.setSelectedColorId(-1);
props.setSelectorMode(false);
setPlacementMode(false);
props.setIsEraserMode(false);
setEnded(false);
};

return (
<div className='PixelSelector'>
{props.selectorMode && (
{(props.selectorMode || ended) && (
<div className='PixelSelector__selector'>
<div className='PixelSelector__selector__colors'>
{props.colors.map((color, idx) => {
Expand All @@ -86,7 +103,7 @@ const PixelSelector = (props) => {
</div>
</div>
)}
{!props.selectorMode && (
{!props.selectorMode && !ended && (
<div
className={
'Button__primary Text__large ' +
Expand Down
Loading