Skip to content

Commit

Permalink
Merge pull request #17 from pixelaw/refactor/use_u32_as_xy_pixel_coor…
Browse files Browse the repository at this point in the history
…dinates

refactor: use u32 as xy pixel coordinates
  • Loading branch information
mariz-ov authored Dec 6, 2023
2 parents 7d114c1 + 84d7abe commit 52c2e1c
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
REPO = pixelaw/core
CORE_VERSION = v0.0.14
CORE_VERSION = v0.0.15
KEIKO_VERSION = v0.0.11


Expand Down
10 changes: 5 additions & 5 deletions contracts/src/apps/snake/app.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use starknet::{ContractAddress, ClassHash};
use pixelaw::core::utils::{Direction, Position, DefaultParameters, starknet_keccak};


fn next_position(x: u64, y: u64, direction: Direction) -> Option<(u64, u64)> {
fn next_position(x: u32, y: u32, direction: Direction) -> Option<(u32, u32)> {
match direction {
Direction::None(()) => { Option::Some((x, y)) },
Direction::Left(()) => {
Expand Down Expand Up @@ -39,8 +39,8 @@ struct SnakeSegment {
id: u32,
previous_id: u32,
next_id: u32,
x: u64,
y: u64,
x: u32,
y: u32,
pixel_original_color: u32,
pixel_original_text: felt252
}
Expand Down Expand Up @@ -82,8 +82,8 @@ mod snake_actions {
#[derive(Drop, starknet::Event)]
struct Died {
owner: ContractAddress,
x: u64,
y: u64
x: u32,
y: u32
}

#[derive(Drop, starknet::Event)]
Expand Down
8 changes: 4 additions & 4 deletions contracts/src/core/models/pixel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use starknet::{ContractAddress, ClassHash};

#[derive(Copy, Drop, Serde)]
struct PixelUpdate {
x: u64,
y: u64,
x: u32,
y: u32,
color: Option<u32>,
owner: Option<ContractAddress>,
app: Option<ContractAddress>,
Expand All @@ -16,9 +16,9 @@ struct PixelUpdate {
struct Pixel {
// System properties
#[key]
x: u64,
x: u32,
#[key]
y: u64,
y: u32,
created_at: u64,
updated_at: u64,
// User-changeable properties
Expand Down
10 changes: 5 additions & 5 deletions contracts/src/core/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ enum Direction {

#[derive(Copy, Drop, Serde, SerdeLen)]
struct Position {
x: u64,
y: u64
x: u32,
y: u32
}


Expand All @@ -37,7 +37,7 @@ impl DirectionIntoFelt252 of Into<Direction, felt252> {
}
}
}
const U64_MAX: u64 = 0xFFFFFFFFFFFFFFFF;
const U32_MAX: u32 = 0xFFFFFFFF;


/// Computes the starknet keccak to have a hash that fits in one felt.
Expand Down Expand Up @@ -73,7 +73,7 @@ fn get_position(direction: Direction, position: Position) -> Position {
}
},
Direction::Right => {
if position.x == U64_MAX {
if position.x == U32_MAX {
position
} else {
Position { x: position.x + 1, y: position.y }
Expand All @@ -87,7 +87,7 @@ fn get_position(direction: Direction, position: Position) -> Position {
}
},
Direction::Down => {
if position.y == U64_MAX {
if position.y == U32_MAX {
position
} else {
Position { x: position.x, y: position.y + 1 }
Expand Down
74 changes: 37 additions & 37 deletions web/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ export type Pixel = {
text?: Maybe<Scalars['felt252']['output']>;
timestamp?: Maybe<Scalars['u64']['output']>;
updated_at?: Maybe<Scalars['u64']['output']>;
x?: Maybe<Scalars['u64']['output']>;
y?: Maybe<Scalars['u64']['output']>;
x?: Maybe<Scalars['u32']['output']>;
y?: Maybe<Scalars['u32']['output']>;
};

export type PixelConnection = {
Expand Down Expand Up @@ -471,20 +471,20 @@ export type PixelWhereInput = {
updated_atLT?: InputMaybe<Scalars['u64']['input']>;
updated_atLTE?: InputMaybe<Scalars['u64']['input']>;
updated_atNEQ?: InputMaybe<Scalars['u64']['input']>;
x?: InputMaybe<Scalars['u64']['input']>;
xEQ?: InputMaybe<Scalars['u64']['input']>;
xGT?: InputMaybe<Scalars['u64']['input']>;
xGTE?: InputMaybe<Scalars['u64']['input']>;
xLT?: InputMaybe<Scalars['u64']['input']>;
xLTE?: InputMaybe<Scalars['u64']['input']>;
xNEQ?: InputMaybe<Scalars['u64']['input']>;
y?: InputMaybe<Scalars['u64']['input']>;
yEQ?: InputMaybe<Scalars['u64']['input']>;
yGT?: InputMaybe<Scalars['u64']['input']>;
yGTE?: InputMaybe<Scalars['u64']['input']>;
yLT?: InputMaybe<Scalars['u64']['input']>;
yLTE?: InputMaybe<Scalars['u64']['input']>;
yNEQ?: InputMaybe<Scalars['u64']['input']>;
x?: InputMaybe<Scalars['u32']['input']>;
xEQ?: InputMaybe<Scalars['u32']['input']>;
xGT?: InputMaybe<Scalars['u32']['input']>;
xGTE?: InputMaybe<Scalars['u32']['input']>;
xLT?: InputMaybe<Scalars['u32']['input']>;
xLTE?: InputMaybe<Scalars['u32']['input']>;
xNEQ?: InputMaybe<Scalars['u32']['input']>;
y?: InputMaybe<Scalars['u32']['input']>;
yEQ?: InputMaybe<Scalars['u32']['input']>;
yGT?: InputMaybe<Scalars['u32']['input']>;
yGTE?: InputMaybe<Scalars['u32']['input']>;
yLT?: InputMaybe<Scalars['u32']['input']>;
yLTE?: InputMaybe<Scalars['u32']['input']>;
yNEQ?: InputMaybe<Scalars['u32']['input']>;
};

export type QueueItem = {
Expand Down Expand Up @@ -582,8 +582,8 @@ export type SnakeSegment = {
pixel_original_color?: Maybe<Scalars['u32']['output']>;
pixel_original_text?: Maybe<Scalars['felt252']['output']>;
previous_id?: Maybe<Scalars['u32']['output']>;
x?: Maybe<Scalars['u64']['output']>;
y?: Maybe<Scalars['u64']['output']>;
x?: Maybe<Scalars['u32']['output']>;
y?: Maybe<Scalars['u32']['output']>;
};

export type SnakeSegmentConnection = {
Expand Down Expand Up @@ -649,20 +649,20 @@ export type SnakeSegmentWhereInput = {
previous_idLT?: InputMaybe<Scalars['u32']['input']>;
previous_idLTE?: InputMaybe<Scalars['u32']['input']>;
previous_idNEQ?: InputMaybe<Scalars['u32']['input']>;
x?: InputMaybe<Scalars['u64']['input']>;
xEQ?: InputMaybe<Scalars['u64']['input']>;
xGT?: InputMaybe<Scalars['u64']['input']>;
xGTE?: InputMaybe<Scalars['u64']['input']>;
xLT?: InputMaybe<Scalars['u64']['input']>;
xLTE?: InputMaybe<Scalars['u64']['input']>;
xNEQ?: InputMaybe<Scalars['u64']['input']>;
y?: InputMaybe<Scalars['u64']['input']>;
yEQ?: InputMaybe<Scalars['u64']['input']>;
yGT?: InputMaybe<Scalars['u64']['input']>;
yGTE?: InputMaybe<Scalars['u64']['input']>;
yLT?: InputMaybe<Scalars['u64']['input']>;
yLTE?: InputMaybe<Scalars['u64']['input']>;
yNEQ?: InputMaybe<Scalars['u64']['input']>;
x?: InputMaybe<Scalars['u32']['input']>;
xEQ?: InputMaybe<Scalars['u32']['input']>;
xGT?: InputMaybe<Scalars['u32']['input']>;
xGTE?: InputMaybe<Scalars['u32']['input']>;
xLT?: InputMaybe<Scalars['u32']['input']>;
xLTE?: InputMaybe<Scalars['u32']['input']>;
xNEQ?: InputMaybe<Scalars['u32']['input']>;
y?: InputMaybe<Scalars['u32']['input']>;
yEQ?: InputMaybe<Scalars['u32']['input']>;
yGT?: InputMaybe<Scalars['u32']['input']>;
yGTE?: InputMaybe<Scalars['u32']['input']>;
yLT?: InputMaybe<Scalars['u32']['input']>;
yLTE?: InputMaybe<Scalars['u32']['input']>;
yNEQ?: InputMaybe<Scalars['u32']['input']>;
};

export type SnakeWhereInput = {
Expand Down Expand Up @@ -1084,10 +1084,10 @@ export type GetEntitiesQuery = { __typename?: 'World__Query', entities?: { __typ

export type All_Filtered_EntitiesQueryVariables = Exact<{
first?: InputMaybe<Scalars['Int']['input']>;
xMin?: InputMaybe<Scalars['u64']['input']>;
xMax?: InputMaybe<Scalars['u64']['input']>;
yMin?: InputMaybe<Scalars['u64']['input']>;
yMax?: InputMaybe<Scalars['u64']['input']>;
xMin?: InputMaybe<Scalars['u32']['input']>;
xMax?: InputMaybe<Scalars['u32']['input']>;
yMin?: InputMaybe<Scalars['u32']['input']>;
yMax?: InputMaybe<Scalars['u32']['input']>;
}>;


Expand Down Expand Up @@ -1183,7 +1183,7 @@ export const GetEntitiesDocument = gql`
}
`;
export const All_Filtered_EntitiesDocument = gql`
query all_filtered_entities($first: Int, $xMin: u64, $xMax: u64, $yMin: u64, $yMax: u64) {
query all_filtered_entities($first: Int, $xMin: u32, $xMax: u32, $yMin: u32, $yMax: u32) {
pixelModels(
first: $first
where: {xGTE: $xMin, xLTE: $xMax, yGTE: $yMin, yLTE: $yMax}
Expand Down
8 changes: 4 additions & 4 deletions web/src/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ query getEntities {

query all_filtered_entities(
$first: Int
$xMin: u64
$xMax: u64
$yMin: u64
$yMax: u64
$xMin: u32
$xMax: u32
$yMin: u32
$yMax: u32
) {
pixelModels(
first: $first
Expand Down

0 comments on commit 52c2e1c

Please sign in to comment.