-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
power info, calendar/datetime.reset, CLI fix, docs
* Registers the system_power_info function with documentation. * The calendar and datetime classes now have a reset method, which is the same as assigning the calendar or datetime to a fresh instnace of it's type. * Document array.find. * Fix broken pack test case which used the now deprecated file_contents.nvgt include. * fix is_console_available again.
- Loading branch information
Showing
7 changed files
with
94 additions
and
10 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
doc/src/references/builtin/!Containers/array/Methods/find.nvgt
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,22 @@ | ||
/** | ||
Search for an item in an array. | ||
1. int find(const T&in value); | ||
2. int find(uint start_at, const T&in value); | ||
## Arguments: | ||
* uint start_at: An optional index to begin searching from. | ||
* const T&in value: The value to search for. | ||
## Returns: | ||
int: The index of the located item, or -1 if not found. | ||
## Remarks: | ||
Be ware that this method will start getting slower the larger your array is, this is because this find method must search through every item in the array until it finds an item that equals what you are looking for. | ||
Be sure to never write code like `string value = array[array.find("testing")];` or anything else where you call array.find() directly within the array's indexing operator. This is because array.find() could return -1, meaning that an index out of bounds exception will be thrown if you use the value returned by this function without verifying it first. | ||
*/ | ||
|
||
// Example: | ||
void main() { | ||
string text = "this is a sentence made up of many words, sort of?"; | ||
string[]@ elements = text.split(" ,?.", false); | ||
int word = elements.find("sort"); | ||
if (word < 0) alert("Oh no not found", "Someone should probably report this if they ever see it while running an unmodified version of this example..."); | ||
else alert("found", "The word sort is at index " + word); | ||
} |
15 changes: 15 additions & 0 deletions
15
doc/src/references/builtin/Date and Time/Classes/datetime/Methods/reset.nvgt
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,15 @@ | ||
/** | ||
Resets this datetime object to the current date and time. | ||
void reset(); | ||
## Remarks: | ||
The expression d.reset() is equivalent to the expression d = datetime(); this is only a convenience function. | ||
*/ | ||
|
||
// Example: | ||
void main() { | ||
datetime d; | ||
d.set(2024, 3, 9, 1, 24, 49); | ||
alert("The datetime object is currently set to", d.year + "/" + d.month + "/" + d.day + ", " + d.hour + ":" + d.minute + ":" + d.second); | ||
d.reset(); | ||
alert("The datetime object is now set to", d.year + "/" + d.month + "/" + d.day + ", " + d.hour + ":" + d.minute + ":" + d.second); | ||
} |
41 changes: 41 additions & 0 deletions
41
doc/src/references/builtin/Environment/Functions/system_power_info.nvgt
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,41 @@ | ||
/** | ||
Determine the state of the system's battery. | ||
system_power_state system_power_info(int&out seconds = void, int&out percent = void); | ||
## Arguments: | ||
* int&out seconds = void: Where to store the number of remaining charge time in seconds. | ||
* int&out percent = void: Where to store the percentage of battery charge remaining. | ||
## Returns: | ||
system_power_state: One of POWER_STATE_ERROR, POWER_STATE_UNKNOWN, POWER_STATE_ON_BATTERY, POWER_STATE_NO_BATTERY, POWER_STATE_CHARGING or POWER_STATE_CHARGED. | ||
## Remarks: | ||
This could be useful for various reasons, such as backing up game data on low battery or showing extra mercy to online game players who run out of battery power who you might otherwise punish/tag for unlawful disconnection. | ||
If the battery percentage or time remaining cannot be determined, that value will be set to -1. | ||
Whether a time or percentage is available is up to the underlying operating system. | ||
*/ | ||
|
||
// Example: | ||
// Utility function to convert a system_power_state to a string. | ||
string describe_power_state(system_power_state st) { | ||
switch (st) { | ||
case POWER_STATE_ERROR: return "error"; | ||
case POWER_STATE_ON_BATTERY: return "on battery"; | ||
case POWER_STATE_NO_BATTERY: return "no battery"; | ||
case POWER_STATE_CHARGING: return "charging"; | ||
case POWER_STATE_CHARGED: return "charged"; | ||
default: return "unknown"; | ||
} | ||
} | ||
void main() { | ||
system_power_state old_state = system_power_info(); | ||
show_window(describe_power_state(old_state)); | ||
while (!key_pressed(KEY_ESCAPE) and !key_pressed(KEY_AC_BACK)) { | ||
wait(5); | ||
int seconds, percent; | ||
system_power_state st = system_power_info(seconds, percent); | ||
if (st != old_state) show_window(describe_power_state(st)); | ||
old_state = st; | ||
if (key_pressed(KEY_SPACE)) { | ||
string time_str = seconds > -1? " (" + timespan(seconds, 0).format() + ")" : ""; | ||
screen_reader_speak(percent > -1? percent + "%" + time_str : "unable to determine battery percent"); | ||
} | ||
} | ||
} |
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