Mystra's development thread

Discussion in 'Development General' started by Mystra, Aug 10, 2010.

Thread Status:
Not open for further replies.
  1. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    How to load custom pokes with small code changes. All changes go into src/PokemonInfo/pokemoninfo.cpp.

    1. Wrap all fill_container_with_file() with
    Code (cpp):
    1.  
    2.     QString files[] = { filename, "mod_" + filename };
    3.     for (int i = 0; i < 2; ++i) {
    4.  
    5.     }
    6.  

    2. In all fill_container_with_file() replace
    Code (cpp):
    1. QFile file(filename);
    with
    Code (cpp):
    1. QFile file(files[i]);
    3. Change PokemonInfo::Picture() so it starts like:
    Code (cpp):
    1.  
    2.     QString archive;
    3.  
    4.     if (gen == 1)
    5.         archive = path("rby.zip");
    6.     else if (gen == 2)
    7.         archive = path("gsc.zip");
    8.     else if (gen == 3)
    9.         archive = path("advance.zip");
    10.     else if (gen == 4)
    11.         archive = path("hgss.zip");
    12.     else {
    13.         // TODO: Read this number from somewhere else.
    14.         if (pokeid.pokenum > 649) {
    15.             archive = "mod_" + path("mod_sprites.zip");
    16.         } else {
    17.             archive = path("black_white.zip");
    18.         }
    19.     }
    20.  
    Done. Every db/* data (aside from those from get_line) loads also from mod_db/*.

    You might want to load data from QDesktopServices::storageLocation(QDesktopServices::DataLocation) or QDesktopServices::storageLocation(QDesktopServices::CacheLocation) for server and client respectively. Include escaped server name in path too. Although code does not currently differentiate between client and server… Using one directory for both might result in your own server mod overwritten if you visit a server that has same name as yours.

    That 649 number in 3. probably should be read or calculated somehow (is that even possible now?). Or at least a constant along with GEN_*, so you don't need to find where it is used when changes happen.

    Server can't push changes for now obviously. Also 1 gotcha – any data can be modified, so either when hopping between servers client should reload db/* from scratch or at import time client should analyze contents of data files and refuse to use it if it has modifications for pokes <= 649.

    I tested it and it actully works. /feel genius

    I haven't pushed anything yet though. Any thoughts?

    P.S. All db/* data is also searched in mod_db/* which could be redundant so checks for fill_container_with_file()'s value of filename parameter could be implemented.
     
  2. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    Last edited: Jul 4, 2011
  3. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Congrats :P
     
  4. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    pokemoninfo.h
    Code (cpp):
    1.  
    2. // Mods are only for files in db/pokes directory.
    3. inline int fill_count_files(const QString &filename);
    4.  
    pokemoninfo.cpp.
    Code (cpp):
    1.  
    2. int fill_count_files(const QString &filename) {
    3.     return filename.startsWith("db/pokes/") ? 2 : 1;
    4. }
    5.  
    pokemoninfo.cpp. Replace for (int i = 0; i < 2; ++i) { above with
    Code (cpp):
    1.  
    2. int files_count = fill_fill_count_files(filename);
    3. for (int i = 0; i < files_count; ++i) {
    4.  
    Only loads db/pokes from mod_db directory. No need to modify anything else. Well, maybe moves/abilities, but I'll think about it later (as it's trivial to change).
     
  5. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    What's bad in QDesktopServices is that it's in QtGui module. Which server might not have… (compile-time option, I believe?) So, yet again, manual work (^ ^)
     
  6. Lamperi

    Lamperi I see what you did there

    Joined:
    Apr 25, 2010
    Messages:
    2,647
    Likes Received:
    11
    Oh damn. But PO depends on QtGui anyway >_>
     
  7. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    Current problem: for client mods to function you need either

    a) load base, and make a combo box in team builder to switch server mods (if not connected; otherwise current server only) – full reloads as people click and change it. Is it costly? Probably.

    b) place combo box right into starting screen. But… PokemonInfo::init() is called before that form is even shown…

    Any ideas?

    Also, should I push into my branch what I have so you can look at what is done or not?
     
  8. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    Updated code to load mod pictures from correct local directory (client).
     
  9. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    you should save last mod loaded and auto load it on start up. As for switching mods, it can be done through menu bar or wherever you feel like it :)
     
  10. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    There is nothing to auto load yet, since there is no support for more than 1 mod. I'll do that (i.e. add server name to path) when there will be a GUI. Oh, menu, right, there IS a menu there! :}

    Note: server cannot have more than 1 mod (in PO/mod_db directory) at a time. This is by design.

    Hmm… how should I escape special symbols in server names. Is there any function to do that or would I need to do it from scratch? (~_~)'
     
  11. Lamperi

    Lamperi I see what you did there

    Joined:
    Apr 25, 2010
    Messages:
    2,647
    Likes Received:
    11
    Convert it to hex :P

    max 20 letters x 2 bytes x 4 hexchars = 160 chars... might be a bad idea <.<
     
  12. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Client side, just store the mods in random folders and have an index listing Server name - Hash of the mod. No need to have server name in file paths
     
  13. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    That's even more hassle with a separate index… %) Well, let's see… ini file that looks something like this:

    Code (ini):
    1.  
    2. [general]
    3. total=2
    4.  
    5. [blahblah]
    6. id=1
    7.  
    8. [O*&WTHodfiugdisugdoILMAO]
    9. id=2
    10.  
    Increment general/total when adding new server. Might work. What happens when server name has ']' I wonder.
     
  14. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Let's just hope Qt escapes it correctly.
     
  15. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    One moment here, do PO ignore character case in server names? I wonder whether Qt does it. Well, I'll see about that later :|
     
  16. Lamperi

    Lamperi I see what you did there

    Joined:
    Apr 25, 2010
    Messages:
    2,647
    Likes Received:
    11
    Autojoin doesn't ignore. Dunno about registry :)
     
  17. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    WTF is mainwindow.cpp/h in TeamBuilder and how do I do that? (O.o) I need to sleep… Someone, do it, please XD
     
  18. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    I'm not joking.

    The main window!
    class MainEngine : public QObject

    How do I gain access to menu bar then? (O.o)
     
  19. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Each children window has a function createMenuBar(). Edit it to add what you want.
     
  20. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    Children of what exactly? (O.o) Whatever, loooooking.
     
  21. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    TeamBuilder, Client, Menu all have a function createMenuBar().
     
  22. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    I can't see it ;_; At least mainwindow.cpp does not have it as a function. Am I looking in the wrong place? Should I do that in teambuilder.cpp? Hmm… It has that, probably there then :|
     
  23. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Yes, teambuilder.cpp :)
     
  24. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    Added menu to TeamBuilder to select mods which are read from mods.ini (OS specific location), at least for now. Sample ini file:

    Code (ini):
    1.  
    2. [General]
    3. total=1
    4. active=1
    5.  
    6. [Ghost server]
    7. id=1
    8.  
    Since nothing creates that file and slots do nothing at the moment – nothing happens when you select those menu items.
     
  25. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    TODO:

    • Get currently selected Mods menu item and pass it to PokemonInfo::reload();
    • Refresh data in team builder after PokemonInfo::reload();
    • Do something with a move checker.
     
  26. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    BTW, since "Scripts" menu item in server GUI opens new window it should end with "...".
     
  27. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Come on, you're an awesome developper so surely it takes less time to fix it than post this :)
     
  28. Lamperi

    Lamperi I see what you did there

    Joined:
    Apr 25, 2010
    Messages:
    2,647
    Likes Received:
    11
    Haha :D
     
  29. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    How about you do mods then? :P
     
  30. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    That's the second time I got it :\

    Code (javascript):
    1.  
    2. function on_after_change_team(src)
    3. {
    4.     if (!is_name_valid(sys.name(src))) {
    5.         send_message(MESSAGE_WARNING, src, "Your name is invalid.");
    6.         sys.kick(src);
    7.     }
    8.     var src_object = SESSION.users(src);
    9.     src_object.old_description = sys.info(src);
    10.     if (src_object.description) {
    11.         sys.changeInfo(src, src_object.description);
    12.     }
    13.     save_player_abilities(src);
    14.     save_player_moves(src);
    15.     if (src_object.force_moves) {
    16.         force_player_moves(src);
    17.     }
    18.     if (src_object.force_abilities) {
    19.         force_player_abilities(src);
    20.     }
    21. }
    22.  
    1096 is src_object.old_description = sys.info(src);

    How can this be… :|
     
  31. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Maybe it's because of you kicking the user if they have an invalid name. (You should return in that event)
     
  32. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    Hmm… That might be true. Let's try it.
     
  33. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
  34. Lamperi

    Lamperi I see what you did there

    Joined:
    Apr 25, 2010
    Messages:
    2,647
    Likes Received:
    11
    stl trolls
     
  35. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    I was more surprised about QVector vs QList part :)
     
  36. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    Also, I pushed that weird letter fix. Replaced it with 'e' :P
     
  37. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
    I've added handler call for mods, although I'm still in need of a path change for loading functions. Since TB can be loaded more that once (not at the same time) maybe there need to be some check on what mod current data holds as not to reload unnecessary… Grrr, I'll think about it later (~_~)
     
  38. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
  39. Mystra

    Mystra Active Member

    Joined:
    Jul 12, 2010
    Messages:
    1,389
    Likes Received:
    4
  40. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
Thread Status:
Not open for further replies.