Skip to content

5. Work in Progress

Alexandra Seelig edited this page May 8, 2024 · 5 revisions

NPC System

The NPC system is used to store and modify all the information on the NPCs within the game. It also connects to other systems in the game in order to become interactive.

NPC.gd

This is a class for the NPC object. It has an ID, name, type, two file paths to its respective dialogue JSON files, and a dialogueSystem object. This information is stored for each NPC.

NPCOrganizer.gd

This is where all the NPC objects are stored. It stores a Dictionary that maps unique IDs to NPC objects. This way every NPC can be quickly accessed using its ID without directly manipulating the object. The _ready() function initializes all the NPCs using the addNPC function. There are also functions for getting the number of NPCs, printing the names of all NPCs, deleting, and setting names. Finally, the function dialogueTrigger() passes in an NPC ID and triggers its dialogue sequence.

NpcObserver.gd

This observer will be notified by an event given by the NPC name. This will trigger the corresponding dialogue sequence.

Dialogue System

The dialogue system is used to access the dialogues between an NPC and the player. It selects an NPC sequence based on the player’s choice.

Elements

NPC_CONV and PLAYER_CONV

Dictionaries that contain the NPC dialogue sequence and the player dialogue sequence respectively. They are created through json files that contain two properties: dialogue and next dialogue. The dialogue is in the form of a string and it is the possible sentence that a NPC/player can say. The next dialogue is of type int and it points to the index of the dialogue that follows the current dialogue.

Functions

_init()

Initializes the dialogue system for a certain NPC-player combination and parses the json files into NPC_CONV and PLAYER_CONV.

get_next_dialogue()

Determines the current dialogue that needs to be displayed, either from the NPC or the player.

nextNPCLine(d)

Given a dialogue string, it determines if the player has chosen a dialogue sequence and it gets the next NPC dialogue.

dialogueSequence(n)

Given a number, it picks the next dialogue sequence to be displayed.

Sensor Shop

Shop.gd

Main scene for the sensor shop store. It lays out sensors, with a maximum of three on each row. Each sensor has a "buy" option and a "more information" option. The buy option will store the sensor in the inventory, if the player is able to buy it. Buying a sensor for the first time will unlock the next sensor, if it exists. Buying prices go up for every new sensor of the same kind. The more information option gives a more detailed description of the sensor.

Sensor.gd

Class to store sensor-specific information. It stores:

  • sensor_name - the sensor's name
  • sensor_info - the sensor's information
  • sensor_ext_info - the sensor's extended information for the "more information" option
  • sensor_status - if the sensor is locked or unlocked.
  • sensor_amount - the amount of sensors of this kind
  • sensor_req - the requirements to unlock this sensor, if locked
  • buy_bttn - if the buy option for this sensor was selected or not
  • info_bttn - if the more information option for this sensor was selected or not
  • price - the current price of the sensor

SensorDisplay.gd

Helper scene for Shop.gd, which creates the sensor element layout for any available sensors in the inventory.

Inventory.gd

A singleton to be used by the shop. Stores the amount of each building element in an enum called items. It also stores the different sensors in a sensors list, so that they can be accessed and changed from anywhere in the code.

Save and Load

When players save the game, they will be prompted with a window that leads to a directory folder on the player’s local machine. Here the player can choose to click on a previous save file to overwrite the save data or create a new save file by typing in a name for the file. NOTE: All save files are JSON files as stored on the player’s device. Upon the player starting the game or in the middle of the game, the player has the option to load a save file to play on that save file. NOTE: If the player chooses a non-save file, then the game will prompt the user with a warning about loading a non-save file and will not load any random JSON file.

Each save file stores the game’s data in a key-value format and this is required and checked for when loading the save file for proper game setup.

Dashboard

The Dashboard gives users an overview of city information. It is split into a small panel with quick stats on the left hand side and a larger menu on the right with popups for 3 game features: badges, field professional information, and sensor stats. The dashboard does not pause the game for the player and will continue to update the city stats in real time while the player is in dashboard.

Dashboard.gd

This is the main scene for the dashboard. It updates the city stats in the ready function and every frame. It also edits tax values when a user adjusts the tax sliders. The nodes are sectioned into the "Dashboard/ColorRect2/CityStatsBar" vBoxContainer and "Dashboard/BadgesSensorStats" control node. A scroll container works when enough popups on the right are expanded to exceed the y width of the vBoxContainer ("MenuContainer") within it.

MenuContainer.gd

The MenuContainer vBoxContainer has an attached script to control the dynamic functionality of the menu item popups. By default all popups are closed.

Each popup as a button on the right to control its state. Each button has its own pressed, mouse_entered, and mouse_exited functions to control the expansion and minimization of the panels. Expanding the panels on hover or press triggers the internal scenes to display (UnlockedBadges, DisplayCharacterCards). There are also expand all/collapse all button nodes for controlling the popups which are connected to pressed functions.

CityStatsBar.gd

This script mainly controls functionality of info buttons next to each city stat. Each button has an entered and exited function to expand and hide the information blurb.

Badges

Badges are awarded to user for answering questions correctly. There are 3 tiers of badges that are awarded based on the number of correct responses.

Badge.gd

Badge.gd is the class for badges. A badge stores its name, a description, a tier, and an icon. Name and description are strings, the tier is a number representing the level of achievement (0 is bronze, 1 is silver and 2 is gold) and the icon is a PNG that represents the badge.

BadgeObserver.gd

BadgeObserver.gd is where the badges are stored and how they’re awarded. It has a list of badges that store all the user’s badges. Badges can be awarded to the user from anywhere in the script using the announcer. A line like:

Announcer.notify(Event.new("Unlocked Badge", "Badge Category 1", 0))

would award a bronze badge in ‘Badge Category 1’ to the user.

Badge View

Badges can be seen from the dashboard. There is a scene called UnlockedBadges.tscn that is stored in ui/Badges. It can be added to any scene but will right now be part of a dashboard. Once you set the length, the object will fill up with badge displays until it hits that length and then starts a new row.