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

Improvements #105

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

38 changes: 21 additions & 17 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ impl QueryRoot {
center: PositionInput,
radius: i32,
shipyard_policy_id: String,
fuel_policy_id: String,
ship_address: String,
fuel_address: String,
asteria_address: String,
Expand All @@ -321,17 +322,17 @@ impl QueryRoot {
SELECT
id,
'Ship' as class,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 0 ->> 'int' AS INTEGER) AS fuel,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 1 ->> 'int' AS INTEGER) AS position_x,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 2 ->> 'int' AS INTEGER) AS position_y,
CAST(utxo_subject_amount(era, cbor, decode($5::varchar, 'hex')) AS INTEGER) AS fuel,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 0 ->> 'int' AS INTEGER) AS position_x,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 1 ->> 'int' AS INTEGER) AS position_y,
$4::varchar AS shipyard_policy,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 3 ->> 'bytes' AS TEXT) AS ship_token_name,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 4 ->> 'bytes' AS TEXT) AS pilot_token_name,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 2 ->> 'bytes' AS TEXT) AS ship_token_name,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 3 ->> 'bytes' AS TEXT) AS pilot_token_name,
0 AS total_rewards
FROM
utxos
WHERE
utxo_address(era, cbor) = from_bech32($5::varchar)
utxo_address(era, cbor) = from_bech32($6::varchar)
AND utxo_has_policy_id(era, cbor, decode($4::varchar, 'hex'))
AND spent_slot IS NULL

Expand All @@ -340,17 +341,17 @@ impl QueryRoot {
SELECT
id,
'Fuel' as class,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 0 ->> 'int' AS INTEGER) AS fuel,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 1 ->> 'int' AS INTEGER) AS position_x,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 2 ->> 'int' AS INTEGER) AS position_y,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 3 ->> 'bytes' AS VARCHAR(56)) AS shipyard_policy,
CAST(utxo_subject_amount(era, cbor, decode($5::varchar, 'hex')) AS INTEGER) AS fuel,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 0 ->> 'int' AS INTEGER) AS position_x,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 1 ->> 'int' AS INTEGER) AS position_y,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 2 ->> 'bytes' AS VARCHAR(56)) AS shipyard_policy,
NULL AS ship_token_name,
NULL AS pilot_token_name,
0 AS total_rewards
FROM
utxos
WHERE
utxo_address(era, cbor) = from_bech32($6::varchar)
utxo_address(era, cbor) = from_bech32($7::varchar)
AND spent_slot IS NULL

UNION ALL
Expand All @@ -368,7 +369,7 @@ impl QueryRoot {
FROM
utxos
WHERE
utxo_address(era, cbor) = from_bech32($7::varchar)
utxo_address(era, cbor) = from_bech32($8::varchar)
AND spent_slot IS NULL
)
SELECT
Expand All @@ -391,6 +392,7 @@ impl QueryRoot {
center.y,
radius,
shipyard_policy_id,
fuel_policy_id,
ship_address,
fuel_address,
asteria_address,
Expand Down Expand Up @@ -515,6 +517,7 @@ impl QueryRoot {
&self,
ctx: &Context<'_>,
shipyard_policy_id: String,
fuel_policy_id: String,
ship_address: String,
) -> Result<Vec<LeaderboardRecord>, Error> {
let pool = ctx
Expand All @@ -525,19 +528,20 @@ impl QueryRoot {
"
SELECT
id,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 0 ->> 'int' AS INTEGER) AS fuel,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 3 ->> 'bytes' AS TEXT) AS ship_token_name,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 4 ->> 'bytes' AS TEXT) AS pilot_token_name,
ABS(CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 1 ->> 'int' AS INTEGER)) + ABS(CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 2 ->> 'int' AS INTEGER)) AS distance
CAST(utxo_subject_amount(era, cbor, decode($2::varchar, 'hex')) AS INTEGER) AS fuel,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 2 ->> 'bytes' AS TEXT) AS ship_token_name,
CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 3 ->> 'bytes' AS TEXT) AS pilot_token_name,
ABS(CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 0 ->> 'int' AS INTEGER)) + ABS(CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 1 ->> 'int' AS INTEGER)) AS distance
FROM
utxos
WHERE
utxo_address(era, cbor) = from_bech32($2::varchar)
utxo_address(era, cbor) = from_bech32($3::varchar)
AND utxo_has_policy_id(era, cbor, decode($1::varchar, 'hex'))
AND spent_slot IS NULL
ORDER BY distance ASC
",
shipyard_policy_id,
fuel_policy_id,
ship_address,
)
.fetch_all(pool)
Expand Down
3 changes: 3 additions & 0 deletions docker/Dockerfile.frontend
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ COPY ./frontend/package*.json ./
RUN npm install

COPY ./frontend ./

COPY ./frontend/public/godot.png ./public/visualizer/index.png

RUN npm run build

CMD ["npm", "start"]
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"build-godot": "mkdir public/visualizer; godot --path ../godot-visualizer --headless --export-release \"Web\" ../frontend/public/visualizer/index.html",
"build-godot": "mkdir public/visualizer; godot --path ../godot-visualizer --headless --export-release \"Web\" ../frontend/public/visualizer/index.html; cp public/godot.png public/visualizer/index.png",
"dev": "npm run build-godot; next dev",
"build": "next build",
"start": "next start"
Expand Down
Binary file added frontend/public/godot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/txs/build-ship.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/txs/gather-fuel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/txs/mine-asteria.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/public/txs/move-ship.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed frontend/public/txs/quit.png
Binary file not shown.
4 changes: 3 additions & 1 deletion frontend/src/components/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { codeToHtml } from "shiki";

const CodeBlock = ({
content,
lang
}: {
lang?: string;
content: string;
}) => {
const [code, setCode] = useState<string>('<div></div>');

useEffect(() => {
codeToHtml(content, { lang: 'typescript', theme: 'dark-plus' }).then(setCode);
codeToHtml(content, { lang: lang ? lang : 'typescript', theme: 'dark-plus' }).then(setCode);
}, [content]);

return <div dangerouslySetInnerHTML={{ __html: code }} />;
Expand Down
Loading
Loading