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

feat/#4 Pass pixel position instead of (x, y) #19

Merged
merged 5 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 4 additions & 7 deletions backend/routes/pixel.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,15 @@ 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)
computedPosition := x + y * int(backend.ArtPeaceBackend.CanvasConfig.Canvas.Width)
b-j-roberts marked this conversation as resolved.
Show resolved Hide resolved
contract := os.Getenv("ART_PEACE_CONTRACT_ADDRESS")
cmd := exec.Command(shellCmd, contract, "place_pixel", strconv.Itoa(position), jsonBody["color"])
cmd := exec.Command(shellCmd, contract, "place_pixel", strconv.Itoa(computedPosition), jsonBody["color"])
b-j-roberts marked this conversation as resolved.
Show resolved Hide resolved
_, err = cmd.Output()
if err != nil {
fmt.Println("Error executing shell command: ", err)
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
b-j-roberts marked this conversation as resolved.
Show resolved Hide resolved
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