Skip to content

Commit

Permalink
Merge pull request #19 from addegbenga/pixel-position
Browse files Browse the repository at this point in the history
feat/#4 Pass pixel position instead of (x, y)
  • Loading branch information
b-j-roberts authored Apr 10, 2024
2 parents 080fa74 + d65b95a commit 2b92db7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
9 changes: 3 additions & 6 deletions backend/routes/pixel.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,14 @@ func placePixelDevnet(w http.ResponseWriter, r *http.Request) {
panic(err)
}

x, err := strconv.Atoi(jsonBody["x"])
if err != nil {
panic(err)
}
y, err := strconv.Atoi(jsonBody["y"])
position, err := strconv.Atoi(jsonBody["position"])
if err != nil {
panic(err)
}

shellCmd := backend.ArtPeaceBackend.BackendConfig.Scripts.PlacePixelDevnet
position := x + y * int(backend.ArtPeaceBackend.CanvasConfig.Canvas.Width)
contract := os.Getenv("ART_PEACE_CONTRACT_ADDRESS")

cmd := exec.Command(shellCmd, contract, "place_pixel", strconv.Itoa(position), jsonBody["color"])
_, err = cmd.Output()
if err != nil {
Expand Down
15 changes: 9 additions & 6 deletions frontend/src/canvas/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,17 @@ const Canvas = props => {
if (props.selectedPositionX === null || props.selectedPositionY === null) {
return
}
const x = props.selectedPositionX
const y = props.selectedPositionY

const position = props.selectedPositionX + props.selectedPositionY * width
const colorIdx = props.selectedColorId
let placePixelEndpoint = backendUrl + "/placePixelDevnet"
fetch(placePixelEndpoint, {
mode: 'cors',
method: 'POST',
body: JSON.stringify({x: x.toString(), y: y.toString(), color: colorIdx.toString()})
mode: "cors",
method: "POST",
body: JSON.stringify({
position: position.toString(),
color: colorIdx.toString(),
}),
}).then(response => {
return response.text()
}).then(data => {
Expand Down Expand Up @@ -303,4 +306,4 @@ const Canvas = props => {
);
}

export default Canvas
export default Canvas

0 comments on commit 2b92db7

Please sign in to comment.