Slowly adding themes x2

This commit is contained in:
Michael Wain 2024-11-27 03:16:15 +03:00
parent bb84ae88de
commit dac6c53e3f
13 changed files with 58 additions and 0 deletions

View File

@ -1,12 +1,17 @@
package com.alterdekim.javabot.components; package com.alterdekim.javabot.components;
import com.alterdekim.javabot.dto.UserDTO; import com.alterdekim.javabot.dto.UserDTO;
import com.alterdekim.javabot.entities.GameTheme;
import com.alterdekim.javabot.entities.TextDataVal;
import com.alterdekim.javabot.service.GameThemeService;
import com.alterdekim.javabot.service.TextDataValService;
import com.alterdekim.javabot.service.UserService; import com.alterdekim.javabot.service.UserService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.telegram.telegrambots.meta.api.objects.games.Game;
import java.util.UUID; import java.util.UUID;
@ -18,7 +23,15 @@ public class StartupListener {
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired
private GameThemeService gameThemeService;
@Autowired
private TextDataValService textDataValService;
private static final String ADMIN_USERNAME = "admin"; private static final String ADMIN_USERNAME = "admin";
private static final String DEFAULT_THEME = "Default";
@EventListener @EventListener
public void onApplicationEvent(ContextRefreshedEvent event) { public void onApplicationEvent(ContextRefreshedEvent event) {
@ -26,5 +39,12 @@ public class StartupListener {
String pwd = UUID.randomUUID().toString(); String pwd = UUID.randomUUID().toString();
log.info("Your admin account password is: {}", pwd); log.info("Your admin account password is: {}", pwd);
userService.saveUser(new UserDTO(ADMIN_USERNAME, pwd)); userService.saveUser(new UserDTO(ADMIN_USERNAME, pwd));
gameThemeService.saveGameTheme(
new GameTheme(
textDataValService.save(
new TextDataVal(DEFAULT_THEME)
).getId()
)
);
} }
} }

View File

@ -34,4 +34,7 @@ public class AdditionalFacts {
@Column(nullable = false) @Column(nullable = false)
private Long textDescId; private Long textDescId;
@Column(nullable = false)
private Long theme = 1L;
} }

View File

@ -37,4 +37,7 @@ public class Bio {
@Column(nullable = false) @Column(nullable = false)
private Long genderTextId; private Long genderTextId;
@Column(nullable = false)
private Long theme = 1L;
} }

View File

@ -24,6 +24,9 @@ public class Disaster {
@Column(nullable = false) @Column(nullable = false)
private Long descTextId; private Long descTextId;
@Column(nullable = false)
private Long theme = 1L;
public Disaster(Long nameTextId, Long descTextId) { public Disaster(Long nameTextId, Long descTextId) {
this.nameTextId = nameTextId; this.nameTextId = nameTextId;
this.descTextId = descTextId; this.descTextId = descTextId;

View File

@ -18,6 +18,9 @@ public class GameTheme {
@Column(nullable = false) @Column(nullable = false)
private Long textNameId; private Long textNameId;
@Column(nullable = false)
private Boolean isSelected = true;
public GameTheme(Long textNameId) { public GameTheme(Long textNameId) {
this.textNameId = textNameId; this.textNameId = textNameId;
} }

View File

@ -32,6 +32,9 @@ public class Health {
@Column(nullable = false) @Column(nullable = false)
private Boolean isChildfree; private Boolean isChildfree;
@Column(nullable = false)
private Long theme = 1L;
public Health(Float health_index, Long textNameId, Long textDescId, Boolean isChildfree) { public Health(Float health_index, Long textNameId, Long textDescId, Boolean isChildfree) {
this.health_index = health_index; this.health_index = health_index;
this.textNameId = textNameId; this.textNameId = textNameId;

View File

@ -42,6 +42,9 @@ public class Hobby {
@Column(nullable = false) @Column(nullable = false)
private Long textDescId; private Long textDescId;
@Column(nullable = false)
private Long theme = 1L;
public Double getValue() { public Double getValue() {
return ((this.getFoodstuffs().doubleValue() + return ((this.getFoodstuffs().doubleValue() +
this.getPower().doubleValue()) / 2.0d) - (((this.getViolence().doubleValue() + this.getAsocial().doubleValue()) / 2.0d)); this.getPower().doubleValue()) / 2.0d) - (((this.getViolence().doubleValue() + this.getAsocial().doubleValue()) / 2.0d));

View File

@ -52,6 +52,9 @@ public class Luggage {
@Column(nullable = false) @Column(nullable = false)
private Long textDescId; private Long textDescId;
@Column(nullable = false)
private Long theme = 1L;
public Double getValue() { public Double getValue() {
return ((this.getFoodstuffs().doubleValue() + return ((this.getFoodstuffs().doubleValue() +
this.getPower().doubleValue()) * 0.5d) - (((this.getViolence().doubleValue() + this.getAsocial().doubleValue()) / 2.0d)); this.getPower().doubleValue()) * 0.5d) - (((this.getViolence().doubleValue() + this.getAsocial().doubleValue()) / 2.0d));

View File

@ -33,6 +33,9 @@ public class Synergy {
@Column(nullable = false) @Column(nullable = false)
private Float probabilityValue; private Float probabilityValue;
@Column(nullable = false)
private Long theme = 1L;
public Synergy(Long firstEntityId, SectionType firstType, Long secondEntityId, SectionType secondType, Float probabilityValue) { public Synergy(Long firstEntityId, SectionType firstType, Long secondEntityId, SectionType secondType, Float probabilityValue) {
this.firstEntityId = firstEntityId; this.firstEntityId = firstEntityId;
this.firstType = firstType; this.firstType = firstType;

View File

@ -37,6 +37,9 @@ public class Work {
@Column(nullable = false) @Column(nullable = false)
private Long textDescId; private Long textDescId;
@Column(nullable = false)
private Long theme = 1L;
public Work(Float asocial, Float power, Float violence, Float foodstuffs, Long textNameId, Long textDescId) { public Work(Float asocial, Float power, Float violence, Float foodstuffs, Long textNameId, Long textDescId) {
this.asocial = asocial; this.asocial = asocial;
this.power = power; this.power = power;

View File

@ -2,6 +2,7 @@ package com.alterdekim.javabot.repository;
import com.alterdekim.javabot.entities.GameTheme; import com.alterdekim.javabot.entities.GameTheme;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -10,4 +11,7 @@ public interface GameThemeRepository extends JpaRepository<GameTheme, Long> {
Optional<GameTheme> findById(Long id); Optional<GameTheme> findById(Long id);
List<GameTheme> findAll(); List<GameTheme> findAll();
@Query("SELECT t FROM GameTheme t WHERE t.isSelected = true")
List<GameTheme> findAllSelected();
} }

View File

@ -11,4 +11,6 @@ public interface GameThemeService {
void removeById(long themeId); void removeById(long themeId);
void saveGameTheme(GameTheme gameTheme); void saveGameTheme(GameTheme gameTheme);
List<GameTheme> getSelectedThemes();
} }

View File

@ -32,4 +32,9 @@ public class GameThemeServiceImpl implements GameThemeService {
public void saveGameTheme(GameTheme gameTheme) { public void saveGameTheme(GameTheme gameTheme) {
repository.save(gameTheme); repository.save(gameTheme);
} }
@Override
public List<GameTheme> getSelectedThemes() {
return repository.findAllSelected();
}
} }