Skip to content

Commit

Permalink
Release/0.0.1 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexzeug authored Jul 13, 2023
2 parents b157074 + c0959a3 commit 7293cbb
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .run/WerewolfApplication.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<module name="werewolf.werewolf-backend.main" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.hexszeug.werewolf.*" />
<option name="PATTERN" value="com.hexzeug.werewolf.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Werewolf

Turn-based web multiplayer role-playing game
Play the current version on [hexzeug.com](https://hexzeug.com/werewolf/).

## Development stage

Expand Down
1 change: 1 addition & 0 deletions werewolf-alpha-launcher/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GENERATE_SOURCEMAP=false
2 changes: 1 addition & 1 deletion werewolf-alpha-launcher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "werewolf-alpha-launcher",
"version": "0.0.1-SNAPSHOT",
"version": "1.0.0",
"homepage": ".",
"proxy": "http://127.0.0.1:8080",
"private": true,
Expand Down
4 changes: 2 additions & 2 deletions werewolf-alpha-launcher/src/home/HomeApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function HomeApp() {
<h1>{t('home.about')}</h1>
<p>
Dies ist die Alpha von Werewolf, einem zugbasiertem online
multiplayer Game. <br />
Multiplayer-Game. <br />
Ich bin Schüler und habe diese Version in etwa 3 Monaten neben der
Schule alleine entwickelt.
</p>
Expand All @@ -32,7 +32,7 @@ function HomeApp() {
noch der eine oder andere größere Bug im Spiel verstecken, und es
gibt noch keine Stats, Accounts, o.ä. <br />
Es gibt auch noch keine ausführliche Anleitung, das Spiel ist aber
sehr intuitiv spielbar, vorallem wenn man die Werwölfe von
sehr intuitiv spielbar, vor allem wenn man die Werwölfe von
Düsterwald kennt.
</p>
<p>Viel Spaß beim Spielen!</p>
Expand Down
2 changes: 1 addition & 1 deletion werewolf-alpha-launcher/src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ await i18n.use(initReactI18next).init({
'home.feedback.info':
'Wenn du Ideen oder Verbesserungsvorschäge hast, einen Bug gefunden hast, oder einfach nur etwas zum Spiel sagen möchtest, würde ich mich freuen, wenn du mir dies anonym in diesem Feedback-Feld zurückmeldest.',
'home.feedback.disclaimer':
'P.S. Das die Grafik schlecht ist, ist schon klar. Die Alpha Version hat noch keine "richtige" Grafik und das designen einer Grafik ist schon geplant. Du kannst aber natürlich trotzdem gerne Ideen zur Grafik äußern.',
'P.S. Die Alpha Version hat noch keine "richtige" Grafik und das designen einer Grafik ist schon geplant. Du kannst aber natürlich trotzdem gerne Ideen zur Grafik äußern.',
'home.feedback.send': 'Senden',
'home.feedback.placeholder': 'Schreibe hier...',
'home.feedback.sent': 'Wurde gesendet',
Expand Down
4 changes: 2 additions & 2 deletions werewolf-backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ plugins {
id 'io.spring.dependency-management' version '1.1.0'
}

group = 'com.hexszeug'
version = '0.0.1-SNAPSHOT'
group = 'com.hexzeug'
version = '0.0.1'
sourceCompatibility = '17'

configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RequiredArgsConstructor
@RestControllerAdvice("com.hexszeug.werewolf.game.controller")
@RestControllerAdvice("com.hexzeug.werewolf.game.controller")
public class AuthorizationProvider {
private final AuthorizationRepository authorizationRepository;
private final VillageRepository villageRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

@RestControllerAdvice("com.hexszeug.werewolf.game.controller")
@RestControllerAdvice("com.hexzeug.werewolf.game.controller")
public class GameExceptionHandler extends ResponseEntityExceptionHandler {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.hexzeug.werewolf.game.logic.services;

import com.hexszeug.werewolf.game.controller.*;
import com.hexzeug.werewolf.game.controller.*;
import com.hexzeug.werewolf.game.events.phase.PhaseEvent;
import com.hexzeug.werewolf.game.model.player.Player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ public void handlePostName(
}

/**
* enable feedback by adding command line attribute {@code --feedback=true}
* enable feedback by adding command line attribute {@code --feedback=<path>}
*/
@PostMapping(value = "/feedback", consumes = MediaType.TEXT_PLAIN_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public void handlePostFeedback(@RequestBody String feedback, ServletRequest request) throws IOException {
if (!environment.getProperty("feedback", Boolean.TYPE, false)) return;
try (FileOutputStream fileOutputStream = new FileOutputStream("feedback.txt", true)) {
String file = environment.getProperty("feedback");
if (file == null) return;
try (FileOutputStream fileOutputStream = new FileOutputStream(file, true)) {
fileOutputStream.write(
"%1$td.%1$tm.%1$tY %1$tT: (%2$s)\n%3$s\n\n\n".formatted(
new Date(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hexzeug.werewolf.launcher.alpha;

import com.hexzeug.werewolf.game.model.village.Village;

import java.util.List;

/**
Expand All @@ -22,5 +24,5 @@ public interface GameCreationService {
* @param userIdentities the user identities
* @throws IllegalArgumentException if there are less than 2 or more than 18 user identities.
*/
void createGame(List<UserIdentity> userIdentities);
Village createGame(List<UserIdentity> userIdentities);
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void createGame(int playerCount) {
createGame(userIdentities);
}
@Override
public void createGame(List<UserIdentity> userIdentities) {
public Village createGame(List<UserIdentity> userIdentities) {
int playerCount = userIdentities.size();
if (playerCount < PLAYERS_MIN || playerCount > PLAYERS_MAX) {
throw new IllegalArgumentException(
Expand Down Expand Up @@ -122,6 +122,8 @@ public void createGame(List<UserIdentity> userIdentities) {
players.get(i).getPlayerId()
);
}

return village;
}

private List<Phase> generatePhaseOrder(List<Role> roles) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.hexzeug.werewolf.launcher.alpha;

import com.hexzeug.werewolf.game.events.phase.PhaseEvent;
import com.hexzeug.werewolf.game.model.village.Village;
import com.hexzeug.werewolf.game.model.village.phase.Phase;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.http.HttpStatus;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -62,31 +65,37 @@ public void setName(String authToken, String name) {
userIdentity.setName(name);
if (room.getUserIdentities().stream().anyMatch(ui -> ui.getName() == null)) return;
room.setRunning(true);
gameCreationService.createGame(room.getUserIdentities());
Village village = gameCreationService.createGame(room.getUserIdentities());
room.setVillage(village);
}

@Scheduled(cron = "0 * * * * ?")
@Scheduled(fixedRate = 1000 * 60 * 60)
public void cleanUp() {
Iterator<Room> iterator = roomCache.iterator();
while (iterator.hasNext()) {
Room room = iterator.next();
long lifetime = Duration.between(room.getCreated(), Instant.now()).toMinutes();
if (!room.isRunning() && lifetime < 1 || room.isRunning() && lifetime < 1) continue;
if (!room.isRunning() && lifetime < 30 || room.isRunning() && lifetime < 60) continue;
if (room.isRunning()) deleteGame(room);
room.getUserIdentities().forEach(userIdentity -> authMap.remove(userIdentity.getAuthToken()));
iterator.remove();
}
}

private void deleteGame(Room room) {
Village village = villageRepository.getByVillageId(
authorizationRepository.getPlayerByAuthToken(
room.getUserIdentities().get(0).getAuthToken()
).getVillageId()
);
Village village = room.getVillage();
room.getUserIdentities().forEach(
userIdentity -> authorizationRepository.removeAuthorization(userIdentity.getAuthToken())
);
villageRepository.removeVillage(village);
}

@EventListener
public void handleGameEnd(PhaseEvent event) {
if (event.getPhase() != Phase.GAME_END) return;
Optional<Room> roomOptional = roomCache.stream().filter(r -> r.getVillage() == event.getVillage()).findFirst();
if (roomOptional.isEmpty()) return;
Room room = roomOptional.get();
authMap.entrySet().removeIf(stringUserIdentityEntry -> stringUserIdentityEntry.getValue().getRoom() == room);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.hexzeug.werewolf.launcher.alpha;

import com.hexzeug.werewolf.game.model.village.Village;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.Instant;
import java.util.List;
import java.util.UUID;

@Data
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class Room {
private List<UserIdentity> userIdentities;
@EqualsAndHashCode.Include
private final UUID uuid;
private final Instant created = Instant.now();
private boolean running;
private Village village;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.hexzeug.werewolf.launcher.alpha;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Base64;
import java.util.Random;

@Data
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class UserIdentity {
@EqualsAndHashCode.Include
private final String authToken;
private String name;
private Room room;
Expand Down
2 changes: 1 addition & 1 deletion werewolf-backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@

server.address=127.0.0.1
1 change: 1 addition & 0 deletions werewolf-game-client/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GENERATE_SOURCEMAP=false
2 changes: 1 addition & 1 deletion werewolf-game-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "werewolf-game-client",
"version": "0.0.1-SNAPSHOT",
"version": "0.0.1",
"homepage": ".",
"private": true,
"dependencies": {
Expand Down
8 changes: 4 additions & 4 deletions werewolf-game-client/src/control/api.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// absolute path without the optional suffix 'play' or 'play/'
const base_url =
window.location.pathname.match(/^(.*?)(?:play\/?)?$/)[1] + 'api';
// absolute path without the optional suffix 'play/'
export const base_url = window.location.pathname.match(/^(.*?)(?:play\/)?$/)[1];
export const api_url = base_url + 'api';

const request = async (url, method, body, options) => {
const res = await fetch(base_url + url, {
const res = await fetch(api_url + url, {
...(body !== undefined && { body: JSON.stringify(body) }),
method,
...options,
Expand Down
8 changes: 4 additions & 4 deletions werewolf-game-client/src/control/eventReceiver.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const eventSource = new EventSource('/api/event-stream');
import { base_url, api_url } from './api';

const eventSource = new EventSource(api_url + '/event-stream');

eventSource.onopen = () => {
console.log(`SSE: Connection to ${eventSource.url} opened.`);
Expand All @@ -20,9 +22,7 @@ eventSource.onerror = (event) => {
break;
case EventSource.CLOSED:
console.error(`SSE: Connection to ${eventSource.url} failed.`);
if (process.env.NODE_ENV !== 'development') {
alert('Connection to server-sent event service failed.');
}
window.location.pathname = base_url;
break;
default:
break;
Expand Down
1 change: 1 addition & 0 deletions werewolf-game-client/src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ await i18n.use(initReactI18next).init({
'narrator.winner.werewolves': 'Die Werwölfe haben gewonnen.',
'narrator.winner.villagers': 'Die Dorfbewohner haben gewonnen.',
'narrator.winner.couple': 'Das verliebte Paar hat gewonnen.',
'narrator.winner.none': 'Alle sind gestorben. Niemand hat gewonnen.',
'witch.question.heal': 'Willst du das Opfer heilen?',
'witch.question.poison':
'Willst du noch jemand anderen töten? Wenn ja wähle ihn aus.',
Expand Down

0 comments on commit 7293cbb

Please sign in to comment.