Skip to content

Commit

Permalink
Prepare v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Caspar Oostendorp committed May 20, 2024
1 parent 44843f0 commit 429de43
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 122 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# client
The (browser) client

Version 0.2.16
Version 0.3.0

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.16
0.3.0
98 changes: 65 additions & 33 deletions doc/encodePngToFelt.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import {PNG} from 'pngjs';
import fs from 'fs';
import {Buffer} from 'buffer';
import {Account, CallData, Contract, Provider, RpcProvider} from "starknet";
import {Account, CallData, Contract, RpcProvider} from "starknet";

async function processImage(imageFile: string, origin: { x: number, y: number }, write: boolean) {
const entrypoint = 'pixel_row'
type PixelRow = { position: { x: number, y: number }, image_data: string[] }
type PixelRows = PixelRow[]

async function generatePixelRows(imageFile: string, origin: { x: number, y: number }): Promise<PixelRows> {

let pixelRows = []
const png = PNG.sync.read(fs.readFileSync(imageFile));

const pixels = [];
Expand All @@ -16,7 +22,7 @@ async function processImage(imageFile: string, origin: { x: number, y: number },
const PIXELS_PER_FELT = 7
let x_offset = 0
for (let last_pixel = 0; last_pixel < pixels.length; last_pixel++) {
let x = last_pixel % (png.width );
let x = last_pixel % (png.width);
let y = Math.floor(last_pixel / png.width);

buffer.push(pixels[last_pixel])
Expand All @@ -25,7 +31,7 @@ async function processImage(imageFile: string, origin: { x: number, y: number },
if (
buffer.length === BUFFER_SIZE
|| x == png.width - 1
|| last_pixel === pixels.length -1
|| last_pixel === pixels.length - 1
) {

// Chop in rows of 7
Expand All @@ -42,21 +48,39 @@ async function processImage(imageFile: string, origin: { x: number, y: number },
});

buffer = []
if (write) await submit({x: origin.x + x_offset, y: origin.y + y}, image_data)

pixelRows.push({position: {x: origin.x + x_offset, y: origin.y + y}, image_data})

// Adjust the offset if we didnt finish the row (so the row is wider than 1000 pixels
if(x == png.width - 1){
if (x == png.width - 1) {
x_offset = 0
}else{
} else {
x_offset = x
}


}
}
return pixelRows
}


async function submit(position: { x: number; y: number; }, image_data: string[]) {

function generateSozo(pixelRows: PixelRows): string {
let result = ""
for (let {position, image_data} of pixelRows) {

result += `sozo \
--profile dev-pop \
execute \
0x1f04b61e71f2afa9610c422db007807f73ebad6b4c069e72bb6e22ff032a93c \
pixel_row \
-c 0,0,${position.x},${position.y},0,${image_data.length},${image_data.join(',')}\nsleep 0.2\n`
}
return result
}

async function execute(pixelRows: PixelRows) {

const provider = new RpcProvider({nodeUrl: "http://127.0.0.1:5050",})

Expand All @@ -72,40 +96,48 @@ async function submit(position: { x: number; y: number; }, image_data: string[])
}
const myTestContract = new Contract(abi, contractAddress, provider);
myTestContract.connect(account0);
console.log({position})
const defaultParams = {
for_player: 0,
for_system: 0,
position,
color: "0xAFAFAF"
}
try {
const entrypoint = 'pixel_row'

for (let {position, image_data} of pixelRows) {
const defaultParams = {
for_player: 0,
for_system: 0,
position,
color: "0xAFAFAF"
}

const calldata = CallData.compile({
defaultParams,
image_data
})

const {suggestedMaxFee: estimatedFee1} = await account0.estimateInvokeFee({
contractAddress,
entrypoint,
calldata,
});
try {
// const {suggestedMaxFee: estimatedFee1} = await account0.estimateInvokeFee({
// contractAddress,
// entrypoint,
// calldata,
// });

const result = await account0.execute({
contractAddress,
entrypoint,
calldata,
});
await provider.waitForTransaction(result.transaction_hash);
// TODO probably need to sleep() here

console.log({result});
const result = await account0.execute({
contractAddress,
entrypoint,
calldata,
});
await provider.waitForTransaction(result.transaction_hash);

} catch (e) {
console.error(e)
console.log({result});
} catch (e) {
console.error({calldata}, e)
}
}
}

async function main() {

const pixelRows = await generatePixelRows('doc/coast.png', {x: 0, y: 0})
console.log(generateSozo(pixelRows))
await execute(pixelRows)
}

// Usage
processImage('doc/coast.png', {x: 0, y: 0}, true);
await main()
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
services:
pixelaw-core:
image: ghcr.io/pixelaw/core:0.2.15
image: ghcr.io/pixelaw/core:0.3.20
platform: linux/x86_64
container_name: pixelaw-core
environment:
- DISABLE_FEE=true
- DISABLE_VALIDATE=true
- RUST_LOG=info,hyper=off
# - WORLD_ADDRESS=0xfc685b398bc4692ab3a4acd380859e71f97d2c319f188854d3a01948ba276a
- WORLD_ADDRESS=0xfc685b398bc4692ab3a4acd380859e71f97d2c319f188854d3a01948ba276a
- INVOKE_MAX_STEPS=4000000
ports:
Expand Down
174 changes: 88 additions & 86 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,88 +1,90 @@
{
"name": "pixelaw-web",
"private": false,
"type": "module",
"license": "MIT",
"version": "0.2.16",
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
"scripts": {
"dev": "rm -rf node_modules/.vite && vite",
"img": "tsx doc/encodePngToFelt.ts",
"build": "tsc && vite build",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"codegen": "graphql-codegen",
"fix-codegen": "node src/fixGeneratedGraphql.cjs",
"create-components": "npx @dojoengine/core ../contracts/target/dev/manifest.json src/dojo/contractComponents.ts http://localhost:5050 0x47864d08a1b86cf0dd52ea2785f8bc93b5f48edca8380bbb3057d158521e12d",
"loadManifests": "tsx src/scripts/loadManifests.ts"
},
"dependencies": {
"@dojoengine/core": "0.6.125",
"@dojoengine/create-burner": "0.6.125",
"@dojoengine/react": "0.6.125",
"@dojoengine/recs": "0.1.35",
"@dojoengine/state": "0.6.125",
"@dojoengine/torii-client": "0.6.125",
"@dojoengine/utils": "0.6.125",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-toast": "^1.1.5",
"@tanstack/react-query": "^5.32.1",
"@tanstack/react-query-devtools": "^5.0.0",
"@use-gesture/react": "^10.3.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"dotenv": "^16.4.5",
"events": "^3.3.0",
"graphql": "^16.7.1",
"graphql-request": "^6.1.0",
"graphql-tag": "^2.12.6",
"graphql-ws": "^5.14.2",
"immer": "^10.1.1",
"lodash": "^4.17.21",
"lucide-react": "^0.288.0",
"micro-starknet": "^0.2.3",
"mobx": "^6.9.0",
"proxy-deep": "^3.1.1",
"query-string": "^9.0.0",
"react": "^18.2.0",
"react-color": "^2.19.3",
"react-dom": "^18.2.0",
"react-icons": "^4.11.0",
"react-router-dom": "^6.17.0",
"rxjs": "^7.8.1",
"starknet": "^6.1.5",
"tailwind-merge": "^1.14.0",
"tailwindcss-animate": "^1.0.7",
"threejs-math": "^0.147.0",
"type-fest": "^2.14.0",
"vite-plugin-top-level-await": "^1.3.1",
"vite-plugin-wasm": "^3.2.2",
"zustand": "^4.5.2"
},
"devDependencies": {
"@graphql-codegen/cli": "^5.0.0",
"@graphql-codegen/typescript": "^4.0.1",
"@graphql-codegen/typescript-graphql-request": "^6.0.0",
"@graphql-codegen/typescript-operations": "^4.0.1",
"@types/lodash": "^4.14.200",
"@types/node": "^20.8.6",
"@types/react": "^18.2.28",
"@types/react-color": "^3.0.7",
"@types/react-dom": "^18.2.13",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"@vitejs/plugin-react": "^4.1.0",
"autoprefixer": "^10.4.16",
"eslint": "^8.51.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"postcss": "^8.4.31",
"postinstall-postinstall": "^2.1.0",
"tailwindcss": "^3.3.3",
"typescript": "^5.2.2",
"vite": "^4.4.11"
}
"name": "pixelaw-web",
"private": false,
"type": "module",
"license": "MIT",
"version": "0.3.0",
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
"scripts": {
"dev": "rm -rf node_modules/.vite && vite",
"img": "tsx doc/encodePngToFelt.ts",
"build": "tsc && vite build",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"codegen": "graphql-codegen",
"fix-codegen": "node src/fixGeneratedGraphql.cjs",
"create-components": "npx @dojoengine/core ../contracts/target/dev/manifest.json src/dojo/contractComponents.ts http://localhost:5050 0x47864d08a1b86cf0dd52ea2785f8bc93b5f48edca8380bbb3057d158521e12d",
"loadManifests": "tsx src/scripts/loadManifests.ts"
},
"dependencies": {
"@dojoengine/core": "0.6.125",
"@dojoengine/create-burner": "0.6.125",
"@dojoengine/react": "0.6.125",
"@dojoengine/recs": "0.1.35",
"@dojoengine/state": "0.6.125",
"@dojoengine/torii-client": "0.6.125",
"@dojoengine/utils": "0.6.125",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-toast": "^1.1.5",
"@tanstack/react-query": "^5.32.1",
"@tanstack/react-query-devtools": "^5.0.0",
"@types/pngjs": "^6.0.5",
"@use-gesture/react": "^10.3.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"dotenv": "^16.4.5",
"events": "^3.3.0",
"graphql": "^16.7.1",
"graphql-request": "^6.1.0",
"graphql-tag": "^2.12.6",
"graphql-ws": "^5.14.2",
"immer": "^10.1.1",
"lodash": "^4.17.21",
"lucide-react": "^0.288.0",
"micro-starknet": "^0.2.3",
"mobx": "^6.9.0",
"pngjs": "^7.0.0",
"proxy-deep": "^3.1.1",
"query-string": "^9.0.0",
"react": "^18.2.0",
"react-color": "^2.19.3",
"react-dom": "^18.2.0",
"react-icons": "^4.11.0",
"react-router-dom": "^6.17.0",
"rxjs": "^7.8.1",
"starknet": "^6.1.5",
"tailwind-merge": "^1.14.0",
"tailwindcss-animate": "^1.0.7",
"threejs-math": "^0.147.0",
"type-fest": "^2.14.0",
"vite-plugin-top-level-await": "^1.3.1",
"vite-plugin-wasm": "^3.2.2",
"zustand": "^4.5.2"
},
"devDependencies": {
"@graphql-codegen/cli": "^5.0.0",
"@graphql-codegen/typescript": "^4.0.1",
"@graphql-codegen/typescript-graphql-request": "^6.0.0",
"@graphql-codegen/typescript-operations": "^4.0.1",
"@types/lodash": "^4.14.200",
"@types/node": "^20.8.6",
"@types/react": "^18.2.28",
"@types/react-color": "^3.0.7",
"@types/react-dom": "^18.2.13",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"@vitejs/plugin-react": "^4.1.0",
"autoprefixer": "^10.4.16",
"eslint": "^8.51.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"postcss": "^8.4.31",
"postinstall-postinstall": "^2.1.0",
"tailwindcss": "^3.3.3",
"typescript": "^5.2.2",
"vite": "^4.4.11"
}
}
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,13 @@
dependencies:
undici-types "~5.26.4"

"@types/pngjs@^6.0.5":
version "6.0.5"
resolved "https://registry.yarnpkg.com/@types/pngjs/-/pngjs-6.0.5.tgz#6dec2f7eb8284543ca4e423f3c09b119fa939ea3"
integrity sha512-0k5eKfrA83JOZPppLtS2C7OUtyNAl2wKNxfyYl9Q5g9lPkgBl/9hNyAu6HuEH2J4XmIv2znEpkDd0SaZVxW6iQ==
dependencies:
"@types/node" "*"

"@types/prop-types@*":
version "15.7.11"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.11.tgz#2596fb352ee96a1379c657734d4b913a613ad563"
Expand Down Expand Up @@ -4877,6 +4884,11 @@ pirates@^4.0.1:
resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.6.tgz#3018ae32ecfcff6c29ba2267cbf21166ac1f36b9"
integrity sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg==

pngjs@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/pngjs/-/pngjs-7.0.0.tgz#a8b7446020ebbc6ac739db6c5415a65d17090e26"
integrity sha512-LKWqWJRhstyYo9pGvgor/ivk2w94eSjE3RGVuzLGlr3NmD8bf7RcYGze1mNdEHRP6TRP6rMuDHk5t44hnTRyow==

postcss-import@^15.1.0:
version "15.1.0"
resolved "https://registry.yarnpkg.com/postcss-import/-/postcss-import-15.1.0.tgz#41c64ed8cc0e23735a9698b3249ffdbf704adc70"
Expand Down

0 comments on commit 429de43

Please sign in to comment.