1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#![no_std]

use gear_lib_old::non_fungible_token::token::TokenId;
use gstd::{prelude::*, ActorId};
use nft_pixelboard_io::*;

#[gmeta::metawasm]
pub mod metafns {
    pub type State = NFTPixelboardState;

    pub fn painting(state: State) -> Vec<Color> {
        state.painting
    }

    pub fn resolution(state: State) -> Resolution {
        state.resolution
    }

    pub fn pixel_price(state: State) -> u128 {
        state.pixel_price
    }

    pub fn block_side_length(state: State) -> BlockSideLength {
        state.block_side_length
    }

    pub fn commission_percentage(state: State) -> u8 {
        state.commission_percentage
    }

    pub fn pixel_info(state: State, coordinates: Coordinates) -> Token {
        let mut token = Default::default();

        if coordinates.x < state.resolution.width && coordinates.y < state.resolution.height {
            for (rectangle, token_info) in state.tokens_by_rectangles.iter() {
                if coordinates.x < rectangle.bottom_right_corner.x
                    && coordinates.y < rectangle.bottom_right_corner.y
                {
                    token = Token(*rectangle, *token_info)
                }
            }
        }

        token
    }

    pub fn token_info(state: State, token_id: TokenId) -> Token {
        let mut token = Default::default();

        if let Some((_, rectangle)) = state
            .rectangles_by_token_ids
            .iter()
            .find(|&(x, _)| x == &token_id)
        {
            if let Some((_, token_info)) = state
                .tokens_by_rectangles
                .iter()
                .find(|&(x, _)| x == rectangle)
            {
                token = Token(*rectangle, *token_info);
            }
        }
        token
    }

    pub fn ft_program(state: State) -> ActorId {
        state.ft_program
    }

    pub fn nft_program(state: State) -> ActorId {
        state.nft_program
    }
}