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

Add draft of resources in Client and Server #85

Merged
merged 31 commits into from
Mar 25, 2025
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
97ebc2c
Add draft of resources in Client and Server
EduardoLR10 Dec 10, 2024
c08f3f7
Make resources into objects
z-silver Dec 17, 2024
d4c1fbb
Make client compile
z-silver Jan 7, 2025
84c8beb
Merge branch 'master' of github.com:Dr-Nekoma/lyceum into issue-60
z-silver Jan 7, 2025
d81ed1c
Fix position type expected in the client
z-silver Jan 7, 2025
8cfda8e
Remove wrong check
z-silver Jan 7, 2025
bba1b4d
Add conversion for kinds when sending resources to client
EduardoLR10 Jan 25, 2025
ef18b24
Update resources query in Server
EduardoLR10 Jan 26, 2025
4ce2876
Introduce resource proximity + rock asset (resource)
EduardoLR10 Jan 26, 2025
cdbdee5
Merge branch 'master' of github.com:Dr-Nekoma/lyceum into issue-60
z-silver Feb 3, 2025
d064f35
Update README to note requirement on nix run command
z-silver Feb 4, 2025
6a8f700
Add new state for resource collection
z-silver Feb 4, 2025
ef589e0
Add resource collection controls and HUD on client
z-silver Feb 4, 2025
a40b6dd
Add resource management and inventory management in the BE
EduardoLR10 Feb 11, 2025
685ca3d
60: fix dialyzer
schonfinkel Feb 11, 2025
56ac0c5
Add update_inventory function to the DB
z-silver Feb 20, 2025
7a8e711
Update update_character to use update_inventory
z-silver Feb 20, 2025
48f55a5
WIP: Add map.harvest_resource procedure
z-silver Feb 20, 2025
f6ff35a
Replace faulty trigger with a procedure
z-silver Mar 3, 2025
3da99dc
WIP: start implementing the handler for resource harvesting
z-silver Mar 3, 2025
6138f3f
Finish server changes to retrieve resources and inventory
EduardoLR10 Mar 11, 2025
9faa436
Reorganize server types in client using namespaces
EduardoLR10 Mar 11, 2025
dcf1162
Add post processing into harvest query results from DB in server
EduardoLR10 Mar 11, 2025
4513e97
Add message dispatch from client to server when harvesting
EduardoLR10 Mar 11, 2025
9f454fa
Make the rock easier to mine
z-silver Mar 18, 2025
2aee089
Fix resource exhaustion
z-silver Mar 18, 2025
172112b
Fix server breakage when a resource is exhausted
z-silver Mar 18, 2025
1bde09b
Add resource harvesting to the client
z-silver Mar 18, 2025
3aaf2b4
Simplify upsert procedure as suggested in comment
z-silver Mar 25, 2025
89f289b
Remove old comment
z-silver Mar 25, 2025
6cb3330
Use less Doofenschmirtzy nomenclature
z-silver Mar 25, 2025
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
Prev Previous commit
Next Next commit
Finish server changes to retrieve resources and inventory
EduardoLR10 committed Mar 11, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 6138f3feda48139602bf5c458761d45c282730e7
21 changes: 11 additions & 10 deletions server/apps/server/src/character.erl
Original file line number Diff line number Diff line change
@@ -152,19 +152,20 @@ harvest_resource(#{name := Name,
username := Username,
email := Email,
map_name := MapName,
kind := Kind,
x_position := XPosition,
y_position := YPosition},
kind := Kind,
x_position := XPosition,
y_position := YPosition},
Connection) ->
Harvest = "CALL map.harvest_resource($1::TEXT, $2::\"map\".OBJECT_TYPE, $3::REAL, $4::REAL, $5::TEXT, $6::TEXT, $7::TEXT);",
%% TODO
_Inventory = "SELECT item_name, quantity FROM character.inventory WHERE\
name = $1::TEXT AND username = $2::TEXT AND e_mail",
_Resource = "",
Inventory = "SELECT item_name, quantity FROM map.resource_item_view WHERE\
name = $1::TEXT AND username = $2::TEXT AND e_mail = $2::TEXT",
Resource = "SELECT quantity FROM map.resource WHERE map_name = $1::TEXT AND x_position = $2::REAL AND y_position = $3::REAL AND kind = $4::\"map\".OBJECT_TYPE",
epgsql:with_transaction(Connection,
fun (Conn) ->
do([postgres_m ||
_ <- {epgsql:equery(Conn, Harvest, [MapName, Kind, XPosition, YPosition, Name, Email, Username]), call},
return(ok)])
_ <- {epgsql:equery(Conn, Harvest, [MapName, Kind, XPosition, YPosition, Name, Email, Username]), call},
DeltaInventory <- {epgsql:equery(Connection, Inventory, [Name, Username, Email]), select},
DeltaResource <- {epgsql:equery(Connection, Resource, [MapName, XPosition, YPosition, Kind]), select},
return(#{delta_inventory => DeltaInventory, delta_resource => DeltaResource})])
end,
#{ begin_opts => "ISOLATION LEVEL READ UNCOMMITTED"}). % Double-check this.
#{ begin_opts => "ISOLATION LEVEL READ UNCOMMITTED"}). % Double-check this.
5 changes: 2 additions & 3 deletions server/apps/server/src/player.erl
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
-compile({parse_transform, do}).

-dialyzer({nowarn_function,
[exit_map/1, logout/1, joining_map/2, update/2, update_inventory/2]}).
[exit_map/1, logout/1, joining_map/2, update/2, harvest_resource/2]}).

%%%===================================================================
%%% API
@@ -209,8 +209,7 @@ joining_map(State, #{name := Name, map_name := MapName} = Request) ->
-spec harvest_resource(user_state(), map()) -> ok.
harvest_resource(State, Request) ->
Pid = State#user_state.pid,
Connection = State#user_state.connection,

Connection = State#user_state.connection,
Result = character:harvest_resource(Request, Connection),
Pid ! Result.

2 changes: 1 addition & 1 deletion server/database/migrations/000004_character.sql
Original file line number Diff line number Diff line change
@@ -119,7 +119,7 @@ CREATE TABLE character.inventory(
quantity SMALLINT NOT NULL,
item_name TEXT NOT NULL,
FOREIGN KEY (name, username, e_mail) REFERENCES character.instance(name, username, e_mail),
FOREIGN KEY (item_name) REFERENCES character.item(name),
FOREIGN KEY (name) REFERENCES character.item(name),
PRIMARY KEY (name, username, e_mail, item_name)
);

9 changes: 9 additions & 0 deletions server/database/migrations/000005_resource.sql
Original file line number Diff line number Diff line change
@@ -10,6 +10,15 @@ CREATE TABLE IF NOT EXISTS map.object_is_resource(
FOREIGN KEY (item_pk) REFERENCES character.item(name)
);

CREATE OR REPLACE VIEW map.resource_item_view AS
SELECT i.name, inv.quantity FROM character.item i
INNER JOIN map.object_is_resource oir
ON i.name = oir.item_pk
INNER JOIN character.inventory inv
ON i.name = inv.name
INNER JOIN character.instance ins
ON ins.name = inv.name AND ins.username = inv.username AND ins.e_mail = inv.e_mail;

CREATE TABLE IF NOT EXISTS map.resource(
map_name TEXT NOT NULL,
-- TODO: Add constraint depending on the same kind and position of the tile.

Unchanged files with check annotations Beta

access-tokens = github.com=${{ github.token }}
- name: Install Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@main

Check warning on line 41 in .github/workflows/client_build.yml

GitHub Actions / Build and Test

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... uses: DeterminateSystems/magic-nix-cache-action@main ...with... uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 41 in .github/workflows/client_build.yml

GitHub Actions / Build and Test

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... uses: DeterminateSystems/magic-nix-cache-action@main ...with... uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 41 in .github/workflows/client_build.yml

GitHub Actions / Dialyzer

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... uses: DeterminateSystems/magic-nix-cache-action@main ...with... uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol
- name: "[Client] Build"
run: |
access-tokens = github.com=${{ github.token }}
- name: Install Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@main

Check warning on line 63 in .github/workflows/server_build.yml

GitHub Actions / Build and Test

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... uses: DeterminateSystems/magic-nix-cache-action@main ...with... uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 63 in .github/workflows/server_build.yml

GitHub Actions / Build and Test

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... uses: DeterminateSystems/magic-nix-cache-action@main ...with... uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 63 in .github/workflows/server_build.yml

GitHub Actions / Dialyzer

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... uses: DeterminateSystems/magic-nix-cache-action@main ...with... uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol
- name: "[Server] Build"
run: |
access-tokens = github.com=${{ github.token }}
- name: Install Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@main

Check warning on line 31 in .github/workflows/server_deploy.yml

GitHub Actions / Build and Test

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... uses: DeterminateSystems/magic-nix-cache-action@main ...with... uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 31 in .github/workflows/server_deploy.yml

GitHub Actions / Build and Test

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... uses: DeterminateSystems/magic-nix-cache-action@main ...with... uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 31 in .github/workflows/server_deploy.yml

GitHub Actions / Dialyzer

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... uses: DeterminateSystems/magic-nix-cache-action@main ...with... uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol
- name: "[Deploy] Build the new release"
run: |
access-tokens = github.com=${{ github.token }}
- name: Install Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@main

Check warning on line 41 in .github/workflows/server_dialyzer.yml

GitHub Actions / Build and Test

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... uses: DeterminateSystems/magic-nix-cache-action@main ...with... uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 41 in .github/workflows/server_dialyzer.yml

GitHub Actions / Build and Test

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... uses: DeterminateSystems/magic-nix-cache-action@main ...with... uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 41 in .github/workflows/server_dialyzer.yml

GitHub Actions / Dialyzer

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... uses: DeterminateSystems/magic-nix-cache-action@main ...with... uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol
- name: "[Server] Check Dialyzer"
run: |