feat: multi synced player scores
All checks were successful
Linux arm64 / Build (push) Successful in 31s
All checks were successful
Linux arm64 / Build (push) Successful in 31s
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import common.ConsumerSignal;
|
||||
import common.Signal;
|
||||
import gui.ColorGenerator.Color;
|
||||
import imgui.ImGui;
|
||||
@@ -33,6 +34,7 @@ public class SudokuRenderer {
|
||||
private final Set<Cell> diagonals = new HashSet<>();
|
||||
|
||||
public final Signal onResolve = new Signal();
|
||||
public final ConsumerSignal<Cell> onCellChange = new ConsumerSignal<>();
|
||||
|
||||
public SudokuRenderer(MultiDoku doku) {
|
||||
this.doku = RenderableMultidoku.fromMultidoku(doku);
|
||||
@@ -72,11 +74,13 @@ public class SudokuRenderer {
|
||||
if (currentCell.getSymbolIndex() == i) {
|
||||
if (ImGui.button("X", cellSize)) {
|
||||
currentCell.setSymbolIndex(Cell.NOSYMBOL);
|
||||
this.onCellChange.emit(currentCell);
|
||||
ImGui.closeCurrentPopup();
|
||||
}
|
||||
} else {
|
||||
if (ImGui.button(Options.Symboles.getSymbols().get(i), cellSize)) {
|
||||
currentCell.trySetValue(i);
|
||||
if (currentCell.trySetValue(i))
|
||||
this.onCellChange.emit(currentCell);
|
||||
if (this.doku.getDoku().isSolved())
|
||||
this.onResolve.emit();
|
||||
ImGui.closeCurrentPopup();
|
||||
|
||||
@@ -3,7 +3,7 @@ package gui;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import common.Signal;
|
||||
import common.ConsumerSignal;
|
||||
import imgui.ImGui;
|
||||
import imgui.extension.imguifiledialog.ImGuiFileDialog;
|
||||
import imgui.extension.imguifiledialog.flag.ImGuiFileDialogFlags;
|
||||
@@ -16,7 +16,7 @@ import sudoku.structure.SudokuFactory;
|
||||
|
||||
public class SudokuSelector {
|
||||
|
||||
public final Signal onSelect = new Signal();
|
||||
public final ConsumerSignal<MultiDoku> onSelect = new ConsumerSignal<>();
|
||||
private MultiDoku doku;
|
||||
|
||||
private final boolean canGenEmptyGrid;
|
||||
@@ -63,7 +63,7 @@ public class SudokuSelector {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
this.onSelect.emit();
|
||||
this.onSelect.emit(this.doku);
|
||||
}
|
||||
|
||||
public void renderFileDialog() {
|
||||
@@ -75,7 +75,7 @@ public class SudokuSelector {
|
||||
String filePath = entry.getValue();
|
||||
this.doku = SudokuFactory.fromfile(filePath);
|
||||
if (this.doku != null)
|
||||
this.onSelect.emit();
|
||||
this.onSelect.emit(this.doku);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -129,8 +129,4 @@ public class SudokuSelector {
|
||||
renderFileDialog();
|
||||
}
|
||||
|
||||
public MultiDoku getDoku() {
|
||||
return doku;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import gui.SudokuRenderer;
|
||||
import imgui.ImGui;
|
||||
import network.client.Client;
|
||||
import network.server.Server;
|
||||
import sudoku.structure.Cell;
|
||||
|
||||
public class MultiPlayerDokuView extends BaseView{
|
||||
|
||||
@@ -16,9 +17,14 @@ public class MultiPlayerDokuView extends BaseView{
|
||||
this.client = client;
|
||||
this.server = server;
|
||||
this.sudokuRenderer = new SudokuRenderer(this.client.getGame().getDoku());
|
||||
this.sudokuRenderer.onCellChange.connect(this::onCellChange);
|
||||
this.client.onDisconnect.connect(this::onDisconnect);
|
||||
}
|
||||
|
||||
private void onCellChange(Cell cell) {
|
||||
this.client.sendCellChange(cell);
|
||||
}
|
||||
|
||||
public void onDisconnect() {
|
||||
if (server == null) {
|
||||
closeMenu();
|
||||
|
||||
@@ -37,8 +37,8 @@ public class MultiPlayerView extends BaseView {
|
||||
this.stateMachine.popState();
|
||||
}
|
||||
|
||||
private void onSelected() {
|
||||
this.doku = this.selector.getDoku();
|
||||
private void onSelected(MultiDoku doku) {
|
||||
this.doku = doku;
|
||||
}
|
||||
|
||||
public void renderGameStatus() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package gui.menu;
|
||||
|
||||
import gui.SudokuSelector;
|
||||
import imgui.ImGui;
|
||||
import sudoku.structure.MultiDoku;
|
||||
|
||||
public class SoloMenu extends BaseView {
|
||||
|
||||
@@ -13,8 +14,8 @@ public class SoloMenu extends BaseView {
|
||||
this.sudokuSelector.onSelect.connect(this::pushSudokuState);
|
||||
}
|
||||
|
||||
private void pushSudokuState() {
|
||||
this.stateMachine.pushState(new SudokuView(stateMachine, this.sudokuSelector.getDoku()));
|
||||
private void pushSudokuState(MultiDoku doku) {
|
||||
this.stateMachine.pushState(new SudokuView(stateMachine, doku));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user