-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a village manager to ocontain villages
- Loading branch information
1 parent
a7982e8
commit 259464b
Showing
10 changed files
with
193 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#' @export | ||
#' @title Village Manager | ||
#' @docType class | ||
#' @description This object manages all of the villages. It acts as an interface to them | ||
#' @section Methods: | ||
#' \describe{ | ||
#' \item{\code{initialize()}}{Creates a new manager} | ||
#' \item{\code{get_villages()}}{Gets all of the villages that the manager has} | ||
#' \item{\code{get_village()}}{Retrieves a specific village from the manager, by name} | ||
#' \item{\code{add_village()}}{Adds a village to the manager} | ||
#' } | ||
village_manager <- R6::R6Class( | ||
"village_manager", | ||
public = list( | ||
#' @field villages A list of village objects | ||
villages = NULL, | ||
#' Creates a new, village manager | ||
#' @description Get a new instance of a village_manager | ||
initialize = function(villages) { | ||
self$villages <- villages | ||
}, | ||
|
||
#' Gets all of the managed villages | ||
#' | ||
#' @return A list of resources | ||
get_villages = function() { | ||
return(self$villages) | ||
}, | ||
|
||
#' Gets a village given a village name | ||
#' | ||
#' @param name The name of the requested village | ||
#' @return A village object | ||
get_village = function(name) { | ||
for (village in self$village) { | ||
if (village$name == name) { | ||
return(village) | ||
} | ||
} | ||
}, | ||
|
||
#' Adds a village to the manager. | ||
#' | ||
#' @param ... The villages to add | ||
#' @return None | ||
add_resource = function(...) { | ||
for (new_village in list(...)) { | ||
self$villages <- append(self$villages, new_village) | ||
} | ||
} | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.