diff --git a/.github/workflows/azure-static-web-apps-mango-water-0ba859b03.yml b/.github/workflows/azure-static-web-apps-mango-water-0ba859b03.yml new file mode 100644 index 0000000..d3fbca7 --- /dev/null +++ b/.github/workflows/azure-static-web-apps-mango-water-0ba859b03.yml @@ -0,0 +1,46 @@ +name: Azure Static Web Apps CI/CD + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened, closed] + branches: + - main + +jobs: + build_and_deploy_job: + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') + runs-on: ubuntu-latest + name: Build and Deploy Job + steps: + - uses: actions/checkout@v3 + with: + submodules: true + lfs: false + - name: Build And Deploy + id: builddeploy + uses: Azure/static-web-apps-deploy@v1 + with: + azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_MANGO_WATER_0BA859B03 }} + repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments) + action: "upload" + ###### Repository/Build Configurations - These values can be configured to match your app requirements. ###### + # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig + app_location: "/client" # App source code path + api_location: "" # Api source code path - optional + output_location: "" # Built app content directory - optional + ###### End of Repository/Build Configurations ###### + + close_pull_request_job: + if: github.event_name == 'pull_request' && github.event.action == 'closed' + runs-on: ubuntu-latest + name: Close Pull Request Job + steps: + - name: Close Pull Request + id: closepullrequest + uses: Azure/static-web-apps-deploy@v1 + with: + azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_MANGO_WATER_0BA859B03 }} + action: "close" diff --git a/.github/workflows/main_magicthememeingapiprod.yml b/.github/workflows/main_magicthememeingapiprod.yml new file mode 100644 index 0000000..6c69998 --- /dev/null +++ b/.github/workflows/main_magicthememeingapiprod.yml @@ -0,0 +1,57 @@ +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# More GitHub Actions for Azure: https://github.com/Azure/actions + +name: Build and deploy ASP.Net Core app to Azure Web App - magicthememeingapiprod + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '8.x' + include-prerelease: true + + - name: Build with dotnet + run: dotnet build --configuration Release + + - name: dotnet publish + run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp + + - name: Upload artifact for deployment job + uses: actions/upload-artifact@v3 + with: + name: .net-app + path: ${{env.DOTNET_ROOT}}/myapp + + deploy: + runs-on: ubuntu-latest + needs: build + environment: + name: 'Production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v3 + with: + name: .net-app + + - name: Deploy to Azure Web App + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: 'magicthememeingapiprod' + slot-name: 'Production' + publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_77A194824F824B37818FD3C0F15D3D48 }} + package: . diff --git a/README.md b/README.md index 68d5019..ac9c3f1 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# KJ2024 \ No newline at end of file +# KJ2024 + +REEEEEEEEEEEEEEEEEEEEEEEEE diff --git a/backend/MemeBE/Models/Player.cs b/backend/MemeBE/Models/Player.cs index 3b6339c..1548b57 100644 --- a/backend/MemeBE/Models/Player.cs +++ b/backend/MemeBE/Models/Player.cs @@ -36,9 +36,11 @@ public Result AddCardToPersistentSlot(Card card) public int PrepareLaugh(int value, out List cardsToDelete) { - cardsToDelete = new List(); int result = value; - foreach (var card in PersistentSlot) + cardsToDelete = new List(); + var cardsCopy = new List(PersistentSlot); + PersistentSlot.Clear(); + foreach (var card in cardsCopy) { foreach (Effect effect in card.EffectList) { @@ -47,6 +49,10 @@ public int PrepareLaugh(int value, out List cardsToDelete) result += effect.Value; cardsToDelete.Add(card.DeckId); } + else + { + PersistentSlot.Add(card); + } } } @@ -55,9 +61,9 @@ public int PrepareLaugh(int value, out List cardsToDelete) return result; } - public void ReceiveLaugh(int laughValue,out List cardsToDelete) + public int PrepareGrumpy(int value, out List cardsToDelete) { - var laughReceived = laughValue; + int result = value; cardsToDelete = new List(); var cardsCopy = new List(PersistentSlot); PersistentSlot.Clear(); @@ -65,42 +71,48 @@ public void ReceiveLaugh(int laughValue,out List cardsToDelete) { foreach (Effect effect in card.EffectList) { - if (effect.EffectName.Equals("Shield")) + if (effect.EffectName.Equals("Buff")) { - Console.WriteLine("Shiled used laugh"); - laughReceived -= effect.Value; + result += effect.Value; cardsToDelete.Add(card.DeckId); } else { PersistentSlot.Add(card); } - + } } - laughReceived = laughReceived < 0 ? 0 : laughReceived; - LaughPoints += laughReceived; + return result; } - public int PrepareGrumpy(int value, out List cardsToDelete) + public void ReceiveLaugh(int laughValue,out List cardsToDelete) { - int result = value; + var laughReceived = laughValue; cardsToDelete = new List(); - foreach (var card in PersistentSlot) + var cardsCopy = new List(PersistentSlot); + PersistentSlot.Clear(); + foreach (var card in cardsCopy) { foreach (Effect effect in card.EffectList) { - if (effect.EffectName.Equals("Buff")) + if (effect.EffectName.Equals("Shield")) { - result += effect.Value; + Console.WriteLine("Shiled used laugh"); + laughReceived -= effect.Value; cardsToDelete.Add(card.DeckId); } + else + { + PersistentSlot.Add(card); + } } } - - return result; + laughReceived = laughReceived < 0 ? 0 : laughReceived; + LaughPoints += laughReceived; + } public void ReceiveGrumpy(int grumpyValue,out List cardsToDelete) diff --git a/backend/MemeBE/Program.cs b/backend/MemeBE/Program.cs index 5462b3e..6147e34 100644 --- a/backend/MemeBE/Program.cs +++ b/backend/MemeBE/Program.cs @@ -13,7 +13,7 @@ { options.AddPolicy("MyCorsPolicy", builder => { - builder.WithOrigins("https://nice-water-0ee9aa403.4.azurestaticapps.net", "http://localhost:63342", "https://memethegathering.wielki.ch", "https://mtg.wielki.ch/") // URL innego serwera + builder.WithOrigins("https://nice-water-0ee9aa403.4.azurestaticapps.net", "http://localhost:63342", "https://memethegathering.wielki.ch", "https://mtg.wielki.ch") // URL innego serwera .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); // Ważne dla SignalR diff --git a/backend/MemeBE/hubs/GameHub.cs b/backend/MemeBE/hubs/GameHub.cs index bb8fab5..5681aac 100644 --- a/backend/MemeBE/hubs/GameHub.cs +++ b/backend/MemeBE/hubs/GameHub.cs @@ -151,6 +151,7 @@ public async Task SendCard(int cardId, string targetNick) // tutaj jest aktywny gracz w odpowiednim pokoju // Wyliczanie akcjki var activeCard = room.ActivePlayer.CardsOnHand.SingleOrDefault(card => card.DeckId == cardId); + Clients.Group(room.RoomId).SendAsync("LastCard", activeCard.URL); foreach (var effect in activeCard.EffectList) { @@ -340,7 +341,7 @@ public async Task MakeGrumpy(Room room, int value, string? targetNick = null) Console.WriteLine("MakeGrumpy - To All"); foreach (var player in room.Players.Values) { - Console.WriteLine("Player " +player.Nick +" is gone take laugh: " + grumpyValue); + Console.WriteLine("Player " +player.Nick +" is gone take grumpy: " + grumpyValue); player.ReceiveGrumpy(grumpyValue, out List cardsToDeleteFromShieldBuff); // Emit await Clients.Client(player.ConnectionID).SendAsync("TakeGrumpy",player.LaughPoints); @@ -359,8 +360,7 @@ await Clients.Group(room.RoomId) } else // Single player { - Console.WriteLine("MakeGrumpy - To: " + targetNick); - Console.WriteLine("Player " +targetNick +" is gone take laugh: " + grumpyValue); + Console.WriteLine("Player " +targetNick +" is gone take grumpy " + grumpyValue); var targetPlayer = room.GetPlayerByNick(targetNick); targetPlayer.ReceiveGrumpy(grumpyValue,out List cardsToDeleteFromShieldBuff); // emit diff --git a/client/index.html b/client/index.html index 8692084..a1a6e33 100644 --- a/client/index.html +++ b/client/index.html @@ -13,7 +13,7 @@
-

Meme: The Gathering

+

Meme: The Gathering

@@ -36,9 +36,16 @@

Meme: The Gathering

-
-
Invite your friends - Room ID:
-
+
+
+ +
+
+
Invite your friends - Room ID:
+
+ +
+
diff --git a/client/static/css/style.css b/client/static/css/style.css index c96aee0..f92e71c 100644 --- a/client/static/css/style.css +++ b/client/static/css/style.css @@ -147,6 +147,21 @@ body { flex-direction: row; } +.middle .lastDetails { + display: flex; + flex-direction: row; + flex-grow: 1; +} + +.middle #lastCard { + width: 250px; +} + +.middle #lastCard img { + width: 200px; + margin: 25px; +} + .middle .lastMessage { flex-grow: 1; display: flex; diff --git a/client/static/js/main.js b/client/static/js/main.js index fb3509a..c85e4ca 100644 --- a/client/static/js/main.js +++ b/client/static/js/main.js @@ -12,8 +12,9 @@ $(document).ready(function () { function initServer() { connection = new signalR.HubConnectionBuilder() - //.withUrl("https://memethegatheringapi.azurewebsites.net/GameHub") .withUrl("https://578d-87-206-130-93.ngrok-free.app/GameHub") + //.withUrl("https://memethegatheringapi.azurewebsites.net/GameHub") + // .withUrl("https://578d-87-206-130-93.ngrok-free.app/GameHub") .withAutomaticReconnect() .configureLogging(signalR.LogLevel.Information) .build(); @@ -121,6 +122,15 @@ function initReceiveMethods() { document.querySelector('#playersZones .other.player[data-player-name="' + target + '"] .points').innerHTML = points; }); + connection.on("GameEnded", function (message) { + yourTurn = false; + ShowEndGameScreen(message); + }); + + connection.on("LastCard", function (url) { + ShowLastPlayedCard(url); + }); + connection.on("TurnStarted", function () { yourTurn = true; }); @@ -296,6 +306,13 @@ function PlacePersistentCard(deckId, url, target, owner) { } } +function ShowLastPlayedCard(url){ + let card = CreateCard('', url, ''); + + document.querySelector('#lastCard').innerHTML = card.innerHTML; + +} + function RemoveCard(deckId, handOnly) { if(handOnly){ $("#playerHand .card[data-deck-id='" + deckId + "']").remove();