-
Notifications
You must be signed in to change notification settings - Fork 2k
add WarframeAPI #541
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
Merged
Merged
add WarframeAPI #541
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
4b2fa9e
add WarframeAPI
83b3825
WarframeAPI lint fix
68c5ace
WarframeAPI lint fix
5578a20
WarframeAPI lint fix
6015526
Add WarframeAPI
0d4d43a
Merge branch 'FloatTech:master' into master
34674d2
wfapi问题修复
00e8a8e
Merge branch 'FloatTech:master' into master
777d26f
wfapi 部分错误修复
b9b3ed0
wfapi 修复
aa5df78
wfapi 修复
e7d9dfc
wfapi 修复
4f55aab
wfapi 修复
aebb222
wfapi 移除日志打印
0a2985d
wfapi 代码优化,goto替换为递归
bf016d0
wfapi 增加注释,优化代码结构
67552a1
wfapi lint修正
2cda792
Merge branch 'master' into master
663349d
Merge branch 'master' into master
d7c423d
Merge branch 'FloatTech:master' into master
GenesisAN 05d25b2
wfapi 修复
5dc3f92
wfapi 修复
8a520d7
wfapi 修复
670c9df
wfapi 修复
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,78 @@ | ||
package warframeapi | ||
|
||
import ( | ||
"github.com/davidscholberg/go-durationfmt" | ||
"sync" | ||
"time" | ||
) | ||
|
||
// 游戏时间模拟 | ||
type gameTime struct { | ||
rwm sync.RWMutex | ||
Name string `json:"name"` //时间名称 | ||
NextTime time.Time `json:"time"` //下次更新时间 | ||
Status bool `json:"status"` //状态 | ||
StatusTrueDes string `json:"true_des"` //状态说明 | ||
StatusFalseDes string `json:"false_des"` //状态说明 | ||
DayTime int `json:"day"` //白天时长 | ||
NightTime int `json:"night"` //夜间时长 | ||
} | ||
|
||
var ( | ||
gameTimes [3]*gameTime | ||
) | ||
|
||
// TimeString 根据传入的世界编号,获取对应的游戏时间文本 | ||
func (t *gameTime) String() string { | ||
return "平原时间:" + t.daynight() + "\n" + | ||
"下次更新:" + t.remaintime() | ||
} | ||
|
||
// 获取当前游戏时间状态(白天/夜晚) | ||
func (t *gameTime) daynight() string { | ||
t.rwm.RLock() | ||
defer t.rwm.RUnlock() | ||
if t.Status { | ||
return t.StatusTrueDes | ||
} | ||
return t.StatusFalseDes | ||
} | ||
|
||
// 获取下一次时间状态更新的剩余游戏时间(x分x秒) | ||
func (t *gameTime) remaintime() string { | ||
t.rwm.RLock() | ||
d := time.Until(t.NextTime) | ||
t.rwm.RUnlock() | ||
durStr, _ := durationfmt.Format(d, "%m分%s秒后") | ||
return durStr | ||
} | ||
|
||
// 根据API返回内容修正游戏时间 | ||
func loadTime(api wfAPI) { | ||
gameTimes = [3]*gameTime{ | ||
{Name: "地球平原", NextTime: api.CetusCycle.Expiry.Local(), Status: api.CetusCycle.IsDay, StatusTrueDes: "白天", StatusFalseDes: "夜晚", DayTime: 100 * 60, NightTime: 50 * 60}, | ||
{Name: "金星平原", NextTime: api.VallisCycle.Expiry.Local(), Status: api.VallisCycle.IsWarm, StatusTrueDes: "温暖", StatusFalseDes: "寒冷", DayTime: 400, NightTime: 20 * 60}, | ||
{Name: "火卫二平原", NextTime: api.CambionCycle.Expiry.Local(), Status: api.CambionCycle.Active == "fass", StatusTrueDes: "fass", StatusFalseDes: "vome", DayTime: 100 * 60, NightTime: 50 * 60}, | ||
} | ||
} | ||
|
||
// timeDet游戏时间更新 | ||
func timeDet() { | ||
for _, v := range gameTimes { | ||
//当前时间对比下一次游戏状态更新时间,看看还剩多少秒 | ||
nt := time.Until(v.NextTime).Seconds() | ||
//已经过了游戏时间状态更新时间 | ||
if nt < 0 { | ||
v.rwm.Lock() | ||
//更新游戏状态,如果是白天就切换到晚上,反之亦然 | ||
if v.Status { | ||
//计算下次的晚上更新时间 | ||
v.NextTime = v.NextTime.Add(time.Duration(v.NightTime) * time.Second) | ||
} else { | ||
//计算下次的白天更新时间 | ||
v.NextTime = v.NextTime.Add(time.Duration(v.DayTime) * time.Second) | ||
} | ||
v.rwm.Unlock() | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.