This change focuses on two main changes. Changes were made to allow the NPCManager changes to be saved in JSON using SaveManager. This ensures that the progress that the player makes regarding the NPC stays consistent. (i.e. no repeatable quests or dialogue). The second change is creating the Utils package that has shared functions between classes. This allows for reduced redundancy and a simpler time making changes to functions shared across multiple classes.
NPCManager: This class now has a function called save_and_empty(). This function saves the changes to the Dialogue attribute to the dictionary before emptying the current group of sprites.
SaveManager: This class now has a reference to the NPCManager class in the form of the npcManager attribute. The
strip_non_json_and_save() and load_data() functions received some changes to allow the saving and the loading of the NPCManager information.
strip_non_json_and_save(): When this function is called, the NPCManager object calls the save_and_empty() function to ensure all the changes made to the Dialogue list. It then calls get_NPCs() to reset the NPCs in the group, allowing them to be drawn once more. A new entry into the dictionary is the NPC dictionary in the NPCManager class. It is saved under the key, NPCDict. Since it is a dictionary, there's no special actions needed to save it to JSON.
load_data(): This function now sets the NPCDict attribute of the NPCManager class to the saved dictionary under the NPCDict key. It then calls NPCManager.get_NPCs() with the context from the screenManager class in order to reset the NPCs on the screen.
The Utils package was created with two python files, Getters.py and Algos.py.
Getters.py: This python file has simple retrieval methods for the JSON dictionaries. Functions such as get_item_json() can be found here. There is no need to test these functions as they are simple and easy to debug. Because all of these functions are now in one place, whenever a python file had to manually do one of these actions, they can just import Utils and used the defined functions in this class.
Algos.py: Algos is a python file that contains more complex algorithms that multiple classes need. For example, the get_max_animation_val() function is used by the Entity classes (Knight and Enemy) but is also used by the NPC class and maybe some future Sprite classes as well. Linking all of theses classes through inheritance so that they can get access to this function would be time consuming and inefficient so it was decided to simply place the function here.
The get_max_animation_val() function now takes in 3 values, the location of the sprites, the name and the animation status. Using this, it finds the highest value of the given animation using the special sort function defined alongside it. Now, these classes can import Utils and call the Utils.get_max_animation_val() function when trying to find their max animation value.
Unlike the functions in Getters.py, the functions in Algos.py do need tests.
Other Changes:
Added the Utils package to the run-tests function of the script bash file.
replaced the old methods of getting a specific dictionary with the Utils Getters.py functions
Some formatting changes
Updated save files
Renamed some variables
Updated NPC json
Added the testNPC folder with the animations for it
updated the NPCManager tests
PR checklist
[x] All Pytests pass
[x] All changes are documented somewhere in the commit
[x] Rpg2.py is tested and works even with the changes
Pygame-RPG 21.7 Housekeeping and bugfixing
This change focuses on two main changes. Changes were made to allow the
NPCManager
changes to be saved in JSON usingSaveManager
. This ensures that the progress that the player makes regarding the NPC stays consistent. (i.e. no repeatable quests or dialogue). The second change is creating the Utils package that has shared functions between classes. This allows for reduced redundancy and a simpler time making changes to functions shared across multiple classes.NPCManager
: This class now has a function calledsave_and_empty()
. This function saves the changes to theDialogue
attribute to the dictionary before emptying the current group of sprites.SaveManager
: This class now has a reference to theNPCManager
class in the form of thenpcManager
attribute. Thestrip_non_json_and_save()
andload_data()
functions received some changes to allow the saving and the loading of theNPCManager
information.strip_non_json_and_save()
: When this function is called, theNPCManager
object calls thesave_and_empty()
function to ensure all the changes made to theDialogue
list. It then callsget_NPCs()
to reset the NPCs in the group, allowing them to be drawn once more. A new entry into the dictionary is the NPC dictionary in theNPCManager
class. It is saved under the key,NPCDict
. Since it is a dictionary, there's no special actions needed to save it to JSON.load_data()
: This function now sets theNPCDict
attribute of theNPCManager
class to the saved dictionary under theNPCDict
key. It then callsNPCManager.get_NPCs()
with the context from thescreenManager
class in order to reset the NPCs on the screen.The
Utils
package was created with two python files,Getters.py
andAlgos.py
.Getters.py
: This python file has simple retrieval methods for the JSON dictionaries. Functions such asget_item_json()
can be found here. There is no need to test these functions as they are simple and easy to debug. Because all of these functions are now in one place, whenever a python file had to manually do one of these actions, they can just import Utils and used the defined functions in this class.Algos.py
: Algos is a python file that contains more complex algorithms that multiple classes need. For example, theget_max_animation_val()
function is used by theEntity
classes (Knight
andEnemy
) but is also used by theNPC
class and maybe some futureSprite
classes as well. Linking all of theses classes through inheritance so that they can get access to this function would be time consuming and inefficient so it was decided to simply place the function here.The
get_max_animation_val()
function now takes in 3 values, the location of the sprites, the name and the animation status. Using this, it finds the highest value of the given animation using the special sort function defined alongside it. Now, these classes can import Utils and call theUtils.get_max_animation_val()
function when trying to find their max animation value.Unlike the functions in
Getters.py
, the functions inAlgos.py
do need tests.Other Changes:
run-tests
function of the script bash file.Getters.py
functionsNPCManager
testsPR checklist