diff --git a/pom.xml b/pom.xml
index 8599f67..3072d3b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -85,6 +85,11 @@
telegrambots-abilities
6.7.0
+
+ org.luaj
+ luaj-jse
+ 3.0.1
+
diff --git a/src/main/java/com/alterdekim/javabot/components/BunkerBot.java b/src/main/java/com/alterdekim/javabot/components/BunkerBot.java
index b65ebdf..f28c7fb 100644
--- a/src/main/java/com/alterdekim/javabot/components/BunkerBot.java
+++ b/src/main/java/com/alterdekim/javabot/components/BunkerBot.java
@@ -418,6 +418,7 @@ public class BunkerBot extends TelegramLongPollingBot {
this.dayNightFields = new DayNightFields();
this.players = new ArrayList<>();
this.gameState = GameState.NONE;
+ this.last_p = 0;
}
@Override
diff --git a/src/main/java/com/alterdekim/javabot/controller/DatabaseController.java b/src/main/java/com/alterdekim/javabot/controller/DatabaseController.java
index a101e26..1d5e952 100644
--- a/src/main/java/com/alterdekim/javabot/controller/DatabaseController.java
+++ b/src/main/java/com/alterdekim/javabot/controller/DatabaseController.java
@@ -6,6 +6,7 @@ import com.alterdekim.javabot.service.*;
import com.alterdekim.javabot.util.HashUtils;
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -16,6 +17,7 @@ import java.util.List;
import java.util.Map;
@Slf4j
+@AllArgsConstructor
@RestController
public class DatabaseController {
private final BioService bioService;
@@ -26,25 +28,7 @@ public class DatabaseController {
private final TextDataValService textDataValService;
private final DisasterService disasterService;
private final SynergyService synergyService;
-
- public DatabaseController(
- BioService bioService,
- HealthService healthService,
- HobbyService hobbyService,
- LuggageService luggageService,
- WorkService workService,
- TextDataValService textDataValService,
- DisasterService disasterService,
- SynergyService synergyService) {
- this.bioService = bioService;
- this.healthService = healthService;
- this.hobbyService = hobbyService;
- this.luggageService = luggageService;
- this.workService = workService;
- this.textDataValService = textDataValService;
- this.disasterService = disasterService;
- this.synergyService = synergyService;
- }
+ private final ActionScriptsService actionService;
private void saveGender(Map params) {
Boolean canDie = Boolean.parseBoolean(params.get("canDie"));
@@ -118,6 +102,18 @@ public class DatabaseController {
disasterService.saveDisaster(new Disaster(t1.getId(), t2.getId()));
}
+ private void saveAction(Map params) {
+ String scriptBody = new String(HashUtils.decodeHexString(params.get("action_body_text")));
+
+ String name_text = new String(HashUtils.decodeHexString(params.get("action_name_text")));
+ TextDataVal t1 = textDataValService.save(new TextDataVal(name_text));
+
+ String desc_text = new String(HashUtils.decodeHexString(params.get("action_desc_text")));
+ TextDataVal t2 = textDataValService.save(new TextDataVal(desc_text));
+
+ actionService.saveScript(new ActionScript(t1.getId(), t2.getId(), scriptBody));
+ }
+
@PostMapping("/api/remove_synergy")
public String remove_synergy(@RequestParam Map params) {
Long id = Long.parseLong(params.get("synergy_id"));
@@ -214,6 +210,9 @@ public class DatabaseController {
case "diss":
saveDiss(params);
break;
+ case "actions":
+ saveAction(params);
+ break;
default:
saveDiss(params);
break;
@@ -244,6 +243,9 @@ public class DatabaseController {
case "diss":
disasterService.removeById(entry_id);
break;
+ case "actions":
+ actionService.removeById(entry_id);
+ break;
default:
disasterService.removeById(entry_id);
break;
@@ -274,6 +276,8 @@ public class DatabaseController {
return mapper.writeValueAsString(luggageService.getAllLuggages());
case "diss":
return mapper.writeValueAsString(disasterService.getAllDisasters());
+ case "actions":
+ return mapper.writeValueAsString(actionService.getAllActionScripts());
default:
return mapper.writeValueAsString(disasterService.getAllDisasters());
}
@@ -301,6 +305,8 @@ public class DatabaseController {
return mapper.writeValueAsString(luggageService.getLuggageById(l));
case "diss":
return mapper.writeValueAsString(disasterService.getDisasterById(l));
+ case "actions":
+ return mapper.writeValueAsString(actionService.getActionScriptById(l));
default:
return mapper.writeValueAsString(disasterService.getDisasterById(l));
}
diff --git a/src/main/java/com/alterdekim/javabot/controller/PanelController.java b/src/main/java/com/alterdekim/javabot/controller/PanelController.java
index dc92b51..b175f9d 100644
--- a/src/main/java/com/alterdekim/javabot/controller/PanelController.java
+++ b/src/main/java/com/alterdekim/javabot/controller/PanelController.java
@@ -3,6 +3,7 @@ package com.alterdekim.javabot.controller;
import com.alterdekim.javabot.entities.*;
import com.alterdekim.javabot.service.*;
import com.alterdekim.javabot.util.UAgentInfo;
+import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@@ -18,6 +19,7 @@ import java.util.*;
@Slf4j
@Controller
+@AllArgsConstructor
public class PanelController {
private final BioService bioService;
private final HealthService healthService;
@@ -26,23 +28,7 @@ public class PanelController {
private final WorkService workService;
private final TextDataValService textDataValService;
private final DisasterService disasterService;
-
- public PanelController(
- BioService bioService,
- HealthService healthService,
- HobbyService hobbyService,
- LuggageService luggageService,
- WorkService workService,
- TextDataValService textDataValService,
- DisasterService disasterService) {
- this.bioService = bioService;
- this.healthService = healthService;
- this.hobbyService = hobbyService;
- this.luggageService = luggageService;
- this.workService = workService;
- this.textDataValService = textDataValService;
- this.disasterService = disasterService;
- }
+ private final ActionScriptsServiceImpl scriptsService;
private List dissToCards() {
List bios = disasterService.getAllDisasters();
@@ -134,6 +120,21 @@ public class PanelController {
return cards;
}
+ private List actionsToCards() {
+ List scripts = scriptsService.getAllActionScripts();
+ List cards = new ArrayList<>();
+ for( ActionScript b : scripts ) {
+ Card card = new Card();
+ card.setId(b.getId());
+ card.setTitle(textDataValService.getTextDataValById(b.getTextNameId()).getText());
+ card.setBody(Arrays.asList("Script body hidden."));
+ cards.add(card);
+ }
+ cards.sort(Comparator.comparing(Card::getId));
+ Collections.reverse(cards);
+ return cards;
+ }
+
@GetMapping("/panel")
public String panelPage(Model model, @RequestHeader("User-Agent") String uagent, @RequestHeader("Accept") String accepth, @RequestParam(value = "section", defaultValue = "diss") String section) {
model.addAttribute("is_mobile", new UAgentInfo(uagent, accepth).detectSmartphone());
@@ -160,6 +161,9 @@ public class PanelController {
case "stats":
// !
break;
+ case "actions":
+ model.addAttribute("cards", actionsToCards() );
+ break;
}
return "panel";
}
diff --git a/src/main/java/com/alterdekim/javabot/entities/ActionScript.java b/src/main/java/com/alterdekim/javabot/entities/ActionScript.java
new file mode 100644
index 0000000..0b59efd
--- /dev/null
+++ b/src/main/java/com/alterdekim/javabot/entities/ActionScript.java
@@ -0,0 +1,34 @@
+package com.alterdekim.javabot.entities;
+
+import jakarta.persistence.*;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Entity
+@Table(name = "action_scripts")
+public class ActionScript {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ @Column(nullable = false)
+ private Long textNameId;
+
+ @Column(nullable = false)
+ private Long textDescId;
+
+ @Column(nullable = false)
+ private String scriptBody;
+
+ public ActionScript(Long textNameId, Long textDescId, String scriptBody) {
+ this.textNameId = textNameId;
+ this.textDescId = textDescId;
+ this.scriptBody = scriptBody;
+ }
+}
diff --git a/src/main/java/com/alterdekim/javabot/repository/ActionScriptsRepository.java b/src/main/java/com/alterdekim/javabot/repository/ActionScriptsRepository.java
new file mode 100644
index 0000000..0002afc
--- /dev/null
+++ b/src/main/java/com/alterdekim/javabot/repository/ActionScriptsRepository.java
@@ -0,0 +1,13 @@
+package com.alterdekim.javabot.repository;
+
+import com.alterdekim.javabot.entities.ActionScript;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+import java.util.List;
+import java.util.Optional;
+
+public interface ActionScriptsRepository extends JpaRepository {
+ Optional findByScriptId(Long scriptId);
+
+ List findAll();
+}
diff --git a/src/main/java/com/alterdekim/javabot/repository/UserRepository.java b/src/main/java/com/alterdekim/javabot/repository/UserRepository.java
index ff69e29..3465f10 100644
--- a/src/main/java/com/alterdekim/javabot/repository/UserRepository.java
+++ b/src/main/java/com/alterdekim/javabot/repository/UserRepository.java
@@ -7,5 +7,4 @@ import org.springframework.stereotype.Repository;
@Repository
public interface UserRepository extends JpaRepository {
User findByUsername(String username);
-
}
diff --git a/src/main/java/com/alterdekim/javabot/service/ActionScriptsService.java b/src/main/java/com/alterdekim/javabot/service/ActionScriptsService.java
new file mode 100644
index 0000000..554df80
--- /dev/null
+++ b/src/main/java/com/alterdekim/javabot/service/ActionScriptsService.java
@@ -0,0 +1,13 @@
+package com.alterdekim.javabot.service;
+
+import com.alterdekim.javabot.entities.ActionScript;
+import com.alterdekim.javabot.entities.Luggage;
+
+import java.util.List;
+
+public interface ActionScriptsService {
+ List getAllActionScripts();
+ ActionScript getActionScriptById(long scriptId);
+ void removeById(long scriptId);
+ void saveScript(ActionScript script);
+}
diff --git a/src/main/java/com/alterdekim/javabot/service/ActionScriptsServiceImpl.java b/src/main/java/com/alterdekim/javabot/service/ActionScriptsServiceImpl.java
new file mode 100644
index 0000000..bc0f033
--- /dev/null
+++ b/src/main/java/com/alterdekim/javabot/service/ActionScriptsServiceImpl.java
@@ -0,0 +1,35 @@
+package com.alterdekim.javabot.service;
+
+import com.alterdekim.javabot.entities.ActionScript;
+import com.alterdekim.javabot.repository.ActionScriptsRepository;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+@AllArgsConstructor
+public class ActionScriptsServiceImpl implements ActionScriptsService {
+
+ private final ActionScriptsRepository actionScriptsRepository;
+
+ @Override
+ public List getAllActionScripts() {
+ return actionScriptsRepository.findAll();
+ }
+
+ @Override
+ public ActionScript getActionScriptById(long scriptId) {
+ return actionScriptsRepository.findByScriptId(scriptId).orElse(null);
+ }
+
+ @Override
+ public void removeById(long scriptId) {
+ actionScriptsRepository.deleteById(scriptId);
+ }
+
+ @Override
+ public void saveScript(ActionScript script) {
+ actionScriptsRepository.save(script);
+ }
+}
diff --git a/src/main/java/com/alterdekim/javabot/service/LuggageServiceImpl.java b/src/main/java/com/alterdekim/javabot/service/LuggageServiceImpl.java
index cf67719..0cefa66 100644
--- a/src/main/java/com/alterdekim/javabot/service/LuggageServiceImpl.java
+++ b/src/main/java/com/alterdekim/javabot/service/LuggageServiceImpl.java
@@ -3,19 +3,17 @@ package com.alterdekim.javabot.service;
import com.alterdekim.javabot.entities.Luggage;
import com.alterdekim.javabot.entities.Synergy;
import com.alterdekim.javabot.repository.LuggageRepository;
+import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
+@AllArgsConstructor
@Service
public class LuggageServiceImpl implements LuggageService {
private final LuggageRepository repository;
- public LuggageServiceImpl(LuggageRepository repository) {
- this.repository = repository;
- }
-
@Override
public List getAllLuggages() {
return repository.findAll();
diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties
index b3967c0..2eb8113 100644
--- a/src/main/resources/messages_en.properties
+++ b/src/main/resources/messages_en.properties
@@ -34,6 +34,7 @@ inlismal=Male?
inlisfem=Female?
inlgente=Gender label:
inlfood=Food
+inlaction=Action
inlheal=Asocial
inlpower=Power
inlviol=Violence
@@ -54,4 +55,5 @@ secentname=Second entity name
secenttype=Second entity type
probbval=Probability value
actionbtn=Action
-stats=Statistics
\ No newline at end of file
+stats=Statistics
+actions=Actions
\ No newline at end of file
diff --git a/src/main/resources/messages_ru.properties b/src/main/resources/messages_ru.properties
index f684eda..1aff612 100644
--- a/src/main/resources/messages_ru.properties
+++ b/src/main/resources/messages_ru.properties
@@ -34,6 +34,7 @@ inlismal=Мужчина?
inlisfem=Женщина?
inlgente=Гендер(текст):
inlfood=Еда
+inlaction=Действие
inlheal=Асоциальность
inlpower=Сила
inlviol=Насилие
@@ -54,4 +55,5 @@ secentname=Имя второй вещи
secenttype=Тип второй вещи
probbval=Вероятность(знач)
actionbtn=Действие
-stats=Статистика
\ No newline at end of file
+stats=Статистика
+actions=Действия
\ No newline at end of file
diff --git a/src/main/resources/static/javascript/panel-script.js b/src/main/resources/static/javascript/panel-script.js
index 6d13ef6..e57d27d 100644
--- a/src/main/resources/static/javascript/panel-script.js
+++ b/src/main/resources/static/javascript/panel-script.js
@@ -23,6 +23,12 @@ function grab_form() {
}
arr.push(query);
});
+ $("form#entryForm :textarea").each(function() {
+ var input = $(this);
+ var vv = str_toHex(input.val());
+ let query = input.attr('id') + "=" + vv;
+ arr.push(query);
+ });
arr.push("section=" + new URL(window.location.href).searchParams.get("section"));
return arr.join("&");
}
@@ -98,6 +104,16 @@ function form_disaster(jobj) {
});
}
+function form_actions(jobj) {
+ get_text_api(jobj.nameTextId, function(t) {
+ $("#action_name_text").val(t);
+ });
+ get_text_api(jobj.descTextId, function(t) {
+ $("#action_desc_text").val(t);
+ });
+ $("#action_body_text").val(jobj.scriptBody);
+}
+
function show_modal_edit(jobj, oid) {
var section = new URL(window.location.href).searchParams.get("section");
@@ -120,6 +136,9 @@ function show_modal_edit(jobj, oid) {
case "diss":
form_disaster(jobj);
break;
+ case "actions":
+ form_actions(jobj);
+ break;
default:
form_disaster(jobj);
break;
diff --git a/src/main/resources/templates/panel.html b/src/main/resources/templates/panel.html
index 1e0a1ea..262086b 100644
--- a/src/main/resources/templates/panel.html
+++ b/src/main/resources/templates/panel.html
@@ -41,6 +41,9 @@
+
+
+