Skip to content

PGNDATABASE - An idea at a chess pgn database double-click to load games #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

relipse
Copy link

@relipse relipse commented Jun 12, 2023

Hi, I'm just showing you what I did in my spare time. I made a chess pgn database viewer for your program.

image

What do you think?

Copy link
Owner

@alex65536 alex65536 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feature looks useful, and the implementation looks good as a proof-of-concept. However, to merge this, some adjustments should be made.

Considering the code:

  • Please follow the code style and the naming conventions (for variable names, unit names, method names, etc.). Also, it's a good idea to reformat your code (Code > JEDI Code Format in Lazarus)
  • Also, see all the comments in the review
  • I didn't dive into the details on how the rendering part works, though

Considering the UI:

  • All the other UI things are integrated into the main window, see PseudoDockedForms. It would be good to integrate the PGN selection window also, but it's not a necessary part.
  • It crashes under Qt5 widgetset, though I didn't have time to investigate the exact reasons, unfortunately
  • It seems that resizing the window doesn't work properly, at least under GTK2 widgetset
  • On the grid itself, it would be good to indicate somehow, which game is currently loaded
  • The rendering is slow because the grid with the games contains too many information (all the moves, for example). Also, I don't think that the entire move sequence and the entire PGN tags must be shown in the grid (including line breaks).

protected
procedure AddWindow(AForm: TApplicationForm; APanel: TCustomPanel;
ASplitter: TSplitter; CanHide: boolean);
public
FGame: TChessGame;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a good idea to promote the field from private to public. Passing either a callback to change the current game or a reference to TChessGame into the new form is acceptable, though.

on E: Exception do
MessageDlg(E.Message, mtError, [mbOK], 0);
end;
SList.Free();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// create SList
try
  // do something
finally
  FreeAndNil(SList);
end;

RegexObj.Expression := '((((\[.*?\])\s*)+)(1\..+?(0-1|1-0|1/2-1/2)))';
if dlgOpenPGN.Execute() then
begin
frmPGNDatabase.Show();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using () after function names is not required in Pascal, and is never used in Chess256.

@@ -203,6 +208,77 @@ procedure TMainForm.AboutActionExecute(Sender: TObject);
AboutBox.ShowModal;
end;

procedure TMainForm.actLoadPGNFileExecute(Sender: TObject);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It is not a good idea to mix GUI creation and parsing in one function. Parsing should go to some other unit (like NotationLists.pas, ChessNotation.pas and the related things are done). GUI creation should go to the new form unit itself instead of creating everything in the main form.
  2. I don't think that splitting PGNs with regular expressions is reliable. While Chess256 parser currently assumes that there is only one PGN in the file, the splitter ideally should use this parser, without relying on regular expressions.

for i := 0 to SList.Count-1 do
begin
s2 := SList[i];
s += s2 + #13#10;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never use #13#10. There is a LineEnding constant AFAIR.

end;

try
CreateNewGame();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIR CreateNewGame will just create the new game with the current new game dialog settings. So, if you are not in the analysis mode now, then the following will happen:

  • the current game will be restarted (not in analysis mode)
  • in the game mode, all the attempts to replace the current notation will be disallowed

So, it's necessary to disallow using this in the analysis mode.

procedure TfrmPGNDatabase.gridPGNDatabaseDrawCell(Sender: TObject; aCol,
aRow: Integer; aRect: TRect; aState: TGridDrawState);
begin
If Sender is TStringGrid then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not Sender is TStringGrid then
  Exit;

And, can it happen that Sender is not TStringGrid and is not equal to gridPGNDatabase?

implementation

uses
MainUnit, GraphUtil, LCLIntf;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty line between uses and {$R *.lfm}

BoardForm.Caption := gridPGNDatabase.Rows[gridPGNDatabase.Row].Strings[1];
if (BoardForm.Caption = '') then
begin
BoardForm.Caption := 'Board';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure whether it's a good idea to change the board form caption. Also, i didn't notice whether these changes actually do anything.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No they don't actually do anything, I was trying to show some game info at the top.

var
P: TPoint;
c, r: LongInt;
obe: Boolean;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use full and descriptive variable names where possible. OldAllowOutBoundEvents, for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants