ActionScripts added
This commit is contained in:
parent
14ed47583c
commit
63b58d0ea0
5
pom.xml
5
pom.xml
@ -85,6 +85,11 @@
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
<version>6.7.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.luaj</groupId>
|
||||
<artifactId>luaj-jse</artifactId>
|
||||
<version>3.0.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -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
|
||||
|
@ -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<String, String> 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<String, String> 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<String, String> 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));
|
||||
}
|
||||
|
@ -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<Card> dissToCards() {
|
||||
List<Disaster> bios = disasterService.getAllDisasters();
|
||||
@ -134,6 +120,21 @@ public class PanelController {
|
||||
return cards;
|
||||
}
|
||||
|
||||
private List<Card> actionsToCards() {
|
||||
List<ActionScript> scripts = scriptsService.getAllActionScripts();
|
||||
List<Card> 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";
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<ActionScript, Long> {
|
||||
Optional<ActionScript> findByScriptId(Long scriptId);
|
||||
|
||||
List<ActionScript> findAll();
|
||||
}
|
@ -7,5 +7,4 @@ import org.springframework.stereotype.Repository;
|
||||
@Repository
|
||||
public interface UserRepository extends JpaRepository<User, Integer> {
|
||||
User findByUsername(String username);
|
||||
|
||||
}
|
||||
|
@ -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<ActionScript> getAllActionScripts();
|
||||
ActionScript getActionScriptById(long scriptId);
|
||||
void removeById(long scriptId);
|
||||
void saveScript(ActionScript script);
|
||||
}
|
@ -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<ActionScript> 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);
|
||||
}
|
||||
}
|
@ -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<Luggage> getAllLuggages() {
|
||||
return repository.findAll();
|
||||
|
@ -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
|
||||
stats=Statistics
|
||||
actions=Actions
|
@ -34,6 +34,7 @@ inlismal=Мужчина?
|
||||
inlisfem=Женщина?
|
||||
inlgente=Гендер(текст):
|
||||
inlfood=Еда
|
||||
inlaction=Действие
|
||||
inlheal=Асоциальность
|
||||
inlpower=Сила
|
||||
inlviol=Насилие
|
||||
@ -54,4 +55,5 @@ secentname=Имя второй вещи
|
||||
secenttype=Тип второй вещи
|
||||
probbval=Вероятность(знач)
|
||||
actionbtn=Действие
|
||||
stats=Статистика
|
||||
stats=Статистика
|
||||
actions=Действия
|
@ -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;
|
||||
|
@ -41,6 +41,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/panel?section=stats" th:text="#{stats}"></a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/panel?section=actions" th:text="#{actions}"></a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
|
||||
<li class="nav-item dropdown">
|
||||
@ -281,6 +284,20 @@
|
||||
<input type="text" class="form-control" id="work_desc_text" name="work_desc_text">
|
||||
</div>
|
||||
</th:block>
|
||||
<th:block th:case="actions">
|
||||
<div class="mb-3">
|
||||
<label for="action_body_text" class="form-label" th:text="#{inlaction}"></label>
|
||||
<textarea class="form-control" id="action_body_text" name="action_body_text" rows="3"></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="action_name_text" class="col-form-label" th:text="#{inlaname}"></label>
|
||||
<input type="text" class="form-control" id="action_name_text" name="action_name_text">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="action_desc_text" class="col-form-label" th:text="#{inladesc}"></label>
|
||||
<input type="text" class="form-control" id="action_desc_text" name="action_desc_text">
|
||||
</div>
|
||||
</th:block>
|
||||
<th:block th:case="diss">
|
||||
<div class="mb-3">
|
||||
<label for="diss_name_text" class="col-form-label" th:text="#{inlaname}"></label>
|
||||
|
Loading…
x
Reference in New Issue
Block a user