Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehjohn committed Mar 13, 2024
1 parent d60d8d2 commit fe0360c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
6 changes: 5 additions & 1 deletion src/Sudoku.Console/Supporting Files/Styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@

body {
background-color: #e0e0e0;
cursor: all-scroll;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
zoom: 50%;
}

pre {
font-family: 'Lucida Console', monospace;
}

.title {
Expand Down
24 changes: 2 additions & 22 deletions src/Sudoku.Console/Supporting Files/Template.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,12 @@
<script>
document.onreadystatechange = () => {
if (document.readyState === 'complete') {
var w = parseInt(window.getComputedStyle(document.getElementsByClassName('tree')[0]).width);
const w = parseInt(window.getComputedStyle(document.getElementsByClassName('tree')[0]).width);
if (w > window.innerWidth) {
window.scrollBy((w - window.innerWidth) / 2, 0);
};
};
};
var prevMouseX = 0;
var prevMouseY = 0;
var dragging = false;
document.onmousedown = (e) => {
prevMouseX = e.screenX;
prevMouseY = e.screenY;
dragging = true;
};
document.onmousemove = (e) => {
if (dragging) {
var dX = prevMouseX - e.screenX;
prevMouseX = e.screenX;
var dY = prevMouseY - e.screenY;
prevMouseY = e.screenY;
window.scrollBy(dX, dY);
}
}
};
document.onmouseup = () => {
dragging = false;
};
</script>
</head>
<body>
Expand Down
34 changes: 26 additions & 8 deletions src/Sudoku.Console/TreeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Sudoku.Console;

public class TreeGenerator
{
private const string NodeTemplate = "<li><a href='#'>{move}<pre>{puzzle}</pre></a>{children}</li>";
private const string NodeTemplate = "<li><a class='{class}' href='#'><pre>{puzzle}</pre></a>{children}</li>";

public void Generate(int[] puzzle, string filename)
{
Expand All @@ -26,15 +26,33 @@ public void Generate(int[] puzzle, string filename)

private static string ProcessNode(Node node)
{
var type = node.Move.Type switch
var content = NodeTemplate;

var puzzle = new StringBuilder();

for (var i = 0; i < 81; i++)
{
MoveType.HiddenSingle => "Hidden Single",
MoveType.LastPossibleNumber => "Last Possible",
_ => "Guess"
};
if (node[i] == 0)
{
puzzle.Append(' ');
}
else
{
puzzle.Append(node[i]);
}

if (i % 9 == 0)
{
puzzle.Append("<br/>");
}
else
{
puzzle.Append(' ');
}
}

content = content.Replace("{puzzle}", puzzle.ToString());

var content = NodeTemplate.Replace("{move}", type);

if (node.Children.Count == 0)
{
content = content.Replace("{children}", string.Empty);
Expand Down

0 comments on commit fe0360c

Please sign in to comment.