override public void SetPlayed(core.Puzzle puzzle) { var dbPuzzle = GetPuzzle(puzzle); dbPuzzle.LastPlayed = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; connection.Update(dbPuzzle); }
private static Puzzle CoreToDBPuzzle(core.Puzzle puzzle, int solvedState) { return(new Puzzle { Type = puzzle.level.type.ToString(), SolvedConfig = puzzle.level.solved.ToCompactString(), InitialConfig = puzzle.initial.ToCompactString(), SolvedState = solvedState }); }
/// <summary> /// if the puzzle is not present in the db, it's because it was never played, /// and therefore it's unsolved /// </summary> /// <param name="puzzle"></param> /// <returns></returns> override public PuzzleSolvedState GetPuzzleState(core.Puzzle puzzle) { Puzzle dbPuzzle = GetPuzzle(puzzle); if (dbPuzzle == null) { return(PuzzleSolvedState.Unsolved); } return(GetState(dbPuzzle.SolvedState)); }
private Puzzle GetPuzzle(core.Puzzle puzzle) { var config = puzzle.initial.ToCompactString(); var typeStr = puzzle.level.type.ToString(); var solvedStr = puzzle.level.solved.ToCompactString(); var result = connection.Query <Puzzle>("SELECT * FROM Puzzle WHERE InitialConfig = ? AND type = ? AND SolvedConfig = ? LIMIT 1", config, typeStr, solvedStr); return(result.Count() == 0 ? null : result.First()); }
/// <summary> /// Updates the solved state of the puzzle in the db /// </summary> /// <param name="puzzle"></param> /// <param name="state"></param> override public void SetPuzzleState(core.Puzzle puzzle, PuzzleSolvedState state) { try { Puzzle dbPuzzle = GetPuzzle(puzzle); var storedState = GetStoredState(state); if (dbPuzzle != null) { dbPuzzle.SolvedState = storedState; connection.Update(dbPuzzle); } else { dbPuzzle = CoreToDBPuzzle(puzzle, storedState); connection.Insert(dbPuzzle); } } catch (Exception e) { Debug.LogError("Could not set puzzle state in DB: " + e.Message); } }
abstract public void SetPlayed(core.Puzzle puzzle);
abstract public PuzzleSolvedState GetPuzzleState(core.Puzzle puzzle);
abstract public void SetPuzzleState(core.Puzzle puzzle, PuzzleSolvedState state);
/// <summary> /// Updates the solved state of the puzzle in the db /// </summary> /// <param name="puzzle"></param> /// <param name="state"></param> override public void SetPuzzleState(core.Puzzle puzzle, PuzzleSolvedState state) { solvedState[puzzle] = state; }
override public void SetPlayed(core.Puzzle puzzle) { played.Add(puzzle); }
/// <summary> /// if the puzzle is not present in the db, it's because it was never played, /// and therefore it's unsolved /// </summary> /// <param name="puzzle"></param> /// <returns></returns> override public PuzzleSolvedState GetPuzzleState(core.Puzzle puzzle) { return(solvedState[puzzle]); }