Improved usage of Time.now and pbGetTimeNow

This commit is contained in:
Maruno17
2023-05-17 19:24:38 +01:00
parent 28a2b7c9c1
commit 62e372f4d7
14 changed files with 49 additions and 52 deletions

View File

@@ -144,14 +144,14 @@ class File
# Copies the source file to the destination path.
def self.copy(source, destination)
data = ""
t = Time.now
t = System.uptime
File.open(source, "rb") do |f|
loop do
r = f.read(4096)
break if !r
if Time.now - t > 1
if System.uptime - t >= 5
t += 5
Graphics.update
t = Time.now
end
data += r
end

View File

@@ -7,12 +7,12 @@ module Translator
def gather_script_and_event_texts
Graphics.update
begin
t = Time.now.to_i
t = System.uptime
texts = []
# Get script texts from Scripts.rxdata
$RGSS_SCRIPTS.each do |script|
if Time.now.to_i - t >= 5
t = Time.now.to_i
if System.uptime - t >= 5
t += 5
Graphics.update
end
scr = Zlib::Inflate.inflate(script[2])
@@ -22,8 +22,8 @@ module Translator
# script texts from .rb files in Data/Scripts
if $RGSS_SCRIPTS.length == 1
Dir.all("Data/Scripts").each do |script_file|
if Time.now.to_i - t >= 5
t = Time.now.to_i
if System.uptime - t >= 5
t += 5
Graphics.update
end
File.open(script_file, "rb") do |f|
@@ -36,8 +36,8 @@ module Translator
plugin_scripts = load_data("Data/PluginScripts.rxdata")
plugin_scripts.each do |plugin|
plugin[2].each do |script|
if Time.now.to_i - t >= 5
t = Time.now.to_i
if System.uptime - t >= 5
t += 5
Graphics.update
end
scr = Zlib::Inflate.inflate(script[1]).force_encoding(Encoding::UTF_8)
@@ -51,8 +51,8 @@ module Translator
items = []
choices = []
commonevents.compact.each do |event|
if Time.now.to_i - t >= 5
t = Time.now.to_i
if System.uptime - t >= 5
t += 5
Graphics.update
end
begin
@@ -99,8 +99,8 @@ module Translator
end
end
end
if Time.now.to_i - t >= 5
t = Time.now.to_i
if System.uptime - t >= 5
t += 5
Graphics.update
end
items |= []
@@ -110,8 +110,8 @@ module Translator
# Find all text in map events and add them to messages
mapinfos = pbLoadMapInfos
mapinfos.each_key do |id|
if Time.now.to_i - t >= 5
t = Time.now.to_i
if System.uptime - t >= 5
t += 5
Graphics.update
end
filename = sprintf("Data/Map%03d.rxdata", id)
@@ -120,8 +120,8 @@ module Translator
items = []
choices = []
map.events.each_value do |event|
if Time.now.to_i - t >= 5
t = Time.now.to_i
if System.uptime - t >= 5
t += 5
Graphics.update
end
begin
@@ -170,16 +170,16 @@ module Translator
end
end
end
if Time.now.to_i - t >= 5
t = Time.now.to_i
if System.uptime - t >= 5
t += 5
Graphics.update
end
items |= []
choices |= []
items.concat(choices)
MessageTypes.setMapMessagesAsHash(id, items) if items.length > 0
if Time.now.to_i - t >= 5
t = Time.now.to_i
if System.uptime - t >= 5
t += 5
Graphics.update
end
end

View File

@@ -4,7 +4,7 @@
# Pokérus check
EventHandlers.add(:on_frame_update, :pokerus_counter,
proc {
next if !$player
next if !$player&.party.any? { |pkmn| pkmn.pokerusStage == 1 }
last = $PokemonGlobal.pokerusTime
next if !last
now = pbGetTimeNow
@@ -48,7 +48,7 @@ EventHandlers.add(:on_frame_update, :low_battery_warning,
next if $game_temp.warned_low_battery || !pbBatteryLow?
next if $game_temp.in_menu || $game_temp.in_battle || $game_player.move_route_forcing ||
$game_temp.message_window_showing || pbMapInterpreterRunning?
next if pbGetTimeNow.sec != 0
next if Time.now.sec != 0
$game_temp.warned_low_battery = true
pbMessage(_INTL("The game has detected that the battery is low. You should save soon to avoid losing your progress."))
}

View File

@@ -1207,7 +1207,7 @@ class Pokemon
@obtain_text = nil
@obtain_level = level
@hatched_map = 0
@timeReceived = pbGetTimeNow.to_i
@timeReceived = Time.now.to_i
@timeEggHatched = nil
@fused = nil
@personalID = rand(2**16) | (rand(2**16) << 16)

View File

@@ -209,7 +209,7 @@ def pbHatch(pokemon)
pokemon.name = nil
pokemon.owner = Pokemon::Owner.new_from_trainer($player)
pokemon.happiness = 120
pokemon.timeEggHatched = pbGetTimeNow
pokemon.timeEggHatched = Time.now.to_i
pokemon.obtain_method = 1 # hatched from egg
pokemon.hatched_map = $game_map.map_id
pokemon.record_first_moves

View File

@@ -43,7 +43,7 @@ class PokemonTrainerCard_Scene
hour = totalsec / 60 / 60
min = totalsec / 60 % 60
time = (hour > 0) ? _INTL("{1}h {2}m", hour, min) : _INTL("{1}m", min)
$PokemonGlobal.startTime = pbGetTimeNow if !$PokemonGlobal.startTime
$PokemonGlobal.startTime = Time.now if !$PokemonGlobal.startTime
starttime = _INTL("{1} {2}, {3}",
pbGetAbbrevMonthName($PokemonGlobal.startTime.mon),
$PokemonGlobal.startTime.day,

View File

@@ -378,8 +378,7 @@ def pbReceiveMysteryGift(id)
if gift[1] == 0 # Pokémon
gift[2].personalID = rand(2**16) | (rand(2**16) << 16)
gift[2].calc_stats
time = pbGetTimeNow
gift[2].timeReceived = time.getgm.to_i
gift[2].timeReceived = Time.now.to_i
gift[2].obtain_method = 4 # Fateful encounter
gift[2].record_first_moves
gift[2].obtain_level = gift[2].level

View File

@@ -27,8 +27,7 @@ class BugContestState
# Returns whether the last contest ended less than 24 hours ago.
def pbContestHeld?
return false if !@lastContest
timenow = pbGetTimeNow
return timenow.to_i - @lastContest < 24 * 60 * 60 # 24 hours
return pbGetTimeNow.to_i - @lastContest < 24 * 60 * 60 # 24 hours
end
def expired?
@@ -222,8 +221,7 @@ class BugContestState
@otherparty = []
@contestMaps = []
@reception = []
timenow = pbGetTimeNow
@lastContest = timenow.to_i
@lastContest = pbGetTimeNow.to_i
$game_map.need_refresh = true
end
end

View File

@@ -320,16 +320,16 @@ def pbWriteCup(id, rules)
when 2 # Yes, use new
return if !pbConfirmMessage(_INTL("This may take a long time. Are you sure?"))
mw = pbCreateMessageWindow
t = Time.now
t = System.uptime
pbGenerateChallenge(rules, id) do |message|
if Time.now - t >= 5
if System.uptime - t >= 5
t += 5
Graphics.update
t = Time.now
end
if message
pbMessageDisplay(mw, message, false)
t = System.uptime
Graphics.update
t = Time.now
end
end
pbDisposeMessageWindow(mw)

View File

@@ -609,7 +609,7 @@ def pbChooseLanguage
end
def pbScreenCapture
t = pbGetTimeNow
t = Time.now
filestart = t.strftime("[%Y-%m-%d] %H_%M_%S.%L")
capturefile = RTP.getSaveFileName(sprintf("%s.png", filestart))
Graphics.screenshot(capturefile)

View File

@@ -12,10 +12,10 @@ def findBottom(bitmap)
end
def pbAutoPositionAll
t = Time.now.to_i
t = System.uptime
GameData::Species.each do |sp|
if Time.now.to_i - t >= 5
t = Time.now.to_i
if System.uptime - t >= 5
t += 5
Graphics.update
end
metrics = GameData::SpeciesMetrics.get_species_form(sp.species, sp.form)

View File

@@ -670,14 +670,14 @@ def pbDebugFixInvalidTiles
num_error_maps = 0
tilesets = $data_tilesets
mapData = Compiler::MapData.new
t = Time.now.to_i
t = System.uptime
Graphics.update
total_maps = mapData.mapinfos.keys.length
Console.echo_h1(_INTL("Checking {1} maps for invalid tiles", total_maps))
mapData.mapinfos.keys.sort.each do |id|
if Time.now.to_i - t >= 5
if System.uptime - t >= 5
t += 5
Graphics.update
t = Time.now.to_i
end
map_errors = 0
map = mapData.getMap(id)

View File

@@ -36,7 +36,7 @@ module FilenameUpdater
def update_berry_tree_event_charsets
ret = []
mapData = Compiler::MapData.new
t = Time.now.to_i
t = System.uptime
Graphics.update
Console.echo_li(_INTL("Checking {1} maps for used berry tree charsets...", mapData.mapinfos.keys.length))
idx = 0
@@ -48,9 +48,9 @@ module FilenameUpdater
next if !map || !mapData.mapinfos[id]
changed = false
map.events.each_key do |key|
if Time.now.to_i - t >= 5
if System.uptime - t >= 5
t += 5
Graphics.update
t = Time.now.to_i
end
map.events[key].pages.each do |page|
next if nil_or_empty?(page.graphic.character_name)

View File

@@ -1682,7 +1682,7 @@ module Compiler
#=============================================================================
def compile_trainer_events(_mustcompile)
mapData = MapData.new
t = Time.now.to_i
t = System.uptime
Graphics.update
trainerChecker = TrainerChecker.new
change_record = []
@@ -1696,9 +1696,9 @@ module Compiler
map = mapData.getMap(id)
next if !map || !mapData.mapinfos[id]
map.events.each_key do |key|
if Time.now.to_i - t >= 5
if System.uptime - t >= 5
t += 5
Graphics.update
t = Time.now.to_i
end
newevent = convert_to_trainer_event(map.events[key], trainerChecker)
if newevent
@@ -1718,9 +1718,9 @@ module Compiler
changed = true
end
end
if Time.now.to_i - t >= 5
if System.uptime - t >= 5
t += 5
Graphics.update
t = Time.now.to_i
end
changed = true if check_counters(map, id, mapData)
if changed