Skip to content
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

FEATURE: Custom Utilities Creation #30

Merged
merged 5 commits into from
Jan 21, 2024
Merged

Conversation

OcelotWalrus
Copy link
Member

@OcelotWalrus OcelotWalrus commented Jan 21, 2024

FEATURE

This PR adds to the game engine a way to create custom python scripts for utilities items and make them run when the key defined in the item definition is used in the game loop. You'll also have the ability to tell the game which arguments you want to get from the script. Only the game data (yaml files variable) and the player' save variable can be asked. Note that to make that work for both vanilla and plugins, a new folder called 'scripts' has been created.

This PR also optimize some things for the github workflows.

Summary

Here's how utilities items will now be defined:

Map:
  type: Utility
  key: "M"
  script name: "map_item.py"
  arguments:
  - player
  - map
  - zone
  description: "It's a map of the world! [Press 'M' to activate.]"

Usage examples

Useful to create custom utilities items for plugins, and also vanilla. For example, a plugin creator could easily create an item that teleports the player:

The item definition:

Teleportation Rock:
  type: Utility
  key: "T"
  script name: "teleportation_rock.py"
  arguments:
  - player
  - map
  description: "It's a mysterious that asks you where you want to go..."

The script, located at <game_folder>/plugins/<plugin_name>/scripts/teleportation_rock.py:

def teleportation_action(player, map):
  print(" ")
  which_coordinates_x = int(input("Where would you like to be at x?\n"))
  which_coordinates_y = int(input("Where would you like to be at y?\n"))
  # Here we consider that the player will enter a correct input`, because this is an example

  # Check if a map point exists at player wish coordinates
  point_exists = False
  for i in list(map):
    if map[i]["x"] == which_coordinates_x and map[i]["y"] == which_coordinates_y:
      point_exists = True

  # Run the teleportation action
  if point_exists:
    print("Teleporting...")
    player["x"], player["y"] = which_coordinates_x, which_coordinates_y
  else:
    print(f"Where you want to go does not exists...")

# Actually run the action, and tells the game which arguments to use
teleportation_action(player, map)

Testing Done

Everything tested by now; tested the example and it works fine.

Performance Impact

Some minor, because of the scripts/ directory being downloaded at the game start.

@OcelotWalrus OcelotWalrus added the enhancement New feature or request label Jan 21, 2024
@OcelotWalrus OcelotWalrus self-assigned this Jan 21, 2024
@OcelotWalrus
Copy link
Member Author

I'll be updated the game docs and then merge this.

@OcelotWalrus OcelotWalrus marked this pull request as ready for review January 21, 2024 08:43
@OcelotWalrus
Copy link
Member Author

Hey @lumbar527 , just asking a review from you, to see if you can get ideas to enhance the utilities items.

Thanks.

@OcelotWalrus OcelotWalrus merged commit 068b724 into master Jan 21, 2024
11 checks passed
@OcelotWalrus OcelotWalrus deleted the utilities-enhancement branch January 21, 2024 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant