Skip to content

Commit d6619c4

Browse files
committed
parse extra exp tags
1 parent 1ff37c4 commit d6619c4

File tree

6 files changed

+233
-31
lines changed

6 files changed

+233
-31
lines changed

app/src/Outlander/Experience/ExpPlugin.swift

Lines changed: 108 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,12 @@ class ExpPlugin: OPlugin {
7474
if inputCheck.hasPrefix("/tracker report") {
7575
let trimmed = inputCheck[15...]
7676
let sorting = trimmed.toOrderBy() ?? tracker.sortingBy
77+
let rexp = host?.get(variable: "rexp") ?? ""
78+
let favor = host?.get(variable: "favor") ?? ""
79+
let sleep = host?.get(variable: "sleep") ?? ""
80+
let tdps = host?.get(variable: "tdp") ?? ""
7781

78-
let report = tracker.buildReport(sorting: sorting, foreColor: foreColor, learnedColor: learnedColor)
82+
let report = tracker.buildReport(sorting: sorting, foreColor: foreColor, learnedColor: learnedColor, favors: favor, rexp: rexp, sleep: sleep, tdps: tdps)
7983

8084
for cmd in report {
8185
host?.send(text: cmd)
@@ -180,6 +184,11 @@ class ExpPlugin: OPlugin {
180184
// cleared
181185
// <component id='exp Sorcery'></component>
182186

187+
// <component id='exp rexp'>Rested EXP Stored: 5:59 hours Usable This Cycle: 5:53 hours Cycle Refreshes: 22:32 hours</component>
188+
// <component id='exp tdp'> TDPs: 926</component>
189+
// <component id='exp favor'> Favors: 12</component>
190+
// <component id='exp sleep'></component>
191+
183192
func parse(xml: String) -> String {
184193
if updateWindow, xml.contains("<prompt") {
185194
updateExpWindow()
@@ -215,16 +224,14 @@ class ExpPlugin: OPlugin {
215224
let start = trimmed.index(trimmed.startIndex, offsetBy: 24)
216225
if let favorsIdx = trimmed.index(of: "Favors") {
217226
let number = String(trimmed[start ..< favorsIdx]).trimmingCharacters(in: .whitespacesAndNewlines)
218-
tracker.tdps = Int(number) ?? 0
219-
host?.send(text: "#var tdp \(tracker.tdps)")
227+
host?.send(text: "#var tdp \(number)")
220228
}
221229
}
222230

223231
if trimmed.hasPrefix("TDPs :") {
224232
let start = trimmed.index(trimmed.startIndex, offsetBy: 6)
225233
let number = String(trimmed[start...]).trimmingCharacters(in: .whitespacesAndNewlines)
226-
tracker.tdps = Int(number) ?? 0
227-
host?.send(text: "#var tdp \(tracker.tdps)")
234+
host?.send(text: "#var tdp \(number)")
228235
}
229236

230237
if !parsing, trimmed.hasPrefix(ExpPlugin.start_check) {
@@ -276,17 +283,55 @@ class ExpPlugin: OPlugin {
276283

277284
updateWindow = true
278285
} else {
279-
// handle empty tag
286+
// handle additional tags
280287
let regex = RegexFactory.get("id='exp\\s([\\w\\s]+)'")
281288
if let match = regex?.firstMatch(&copy) {
282289
let name = match.valueAt(index: 1)?.replacingOccurrences(of: " ", with: "_") ?? ""
283-
let learningRate = LearningRate.clear
284-
285-
tracker.update(SkillExp(name: name, mindState: learningRate, ranks: 0, isNew: false), trackLearned: displayLearnedWithPrompt)
286290

287-
host?.set(variable: "\(name).Ranks", value: "0.0")
288-
host?.set(variable: "\(name).LearningRate", value: "\(learningRate.rawValue)")
289-
host?.set(variable: "\(name).LearningRateName", value: "\(learningRate.description)")
291+
switch name {
292+
case "favor":
293+
let valReg = RegexFactory.get(".+>\\s*(.+)<.*")
294+
if let match = valReg?.firstMatch(&copy) {
295+
let txt = match.valueAt(index: 1) ?? ""
296+
let value = Int(txt.replacingOccurrences(of: "Favors:", with: "").trimLeadingWhitespace()) ?? 0
297+
host?.set(variable: name, value: "\(value)")
298+
}
299+
break
300+
case "rexp":
301+
let valReg = RegexFactory.get(".+>\\s*(.+)<.*")
302+
if let match = valReg?.firstMatch(&copy) {
303+
let txt = match.valueAt(index: 1) ?? ""
304+
host?.set(variable: name, value: txt)
305+
} else {
306+
host?.set(variable: name, value: "")
307+
}
308+
break
309+
case "sleep":
310+
let valReg = RegexFactory.get(".+>\\s*(.+)<.*")
311+
if let match = valReg?.firstMatch(&copy) {
312+
let txt = (match.valueAt(index: 1) ?? "").replacingOccurrences(of: "</b>", with: "")
313+
host?.set(variable: name, value: txt)
314+
} else {
315+
host?.set(variable: name, value: "")
316+
}
317+
break
318+
case "tdp":
319+
let valReg = RegexFactory.get(".+>\\s*(.+)<.*")
320+
if let match = valReg?.firstMatch(&copy) {
321+
let txt = match.valueAt(index: 1) ?? ""
322+
let value = Int(txt.replacingOccurrences(of: "TDPs:", with: "").trimLeadingWhitespace()) ?? 0
323+
host?.set(variable: name, value: "\(value)")
324+
}
325+
break
326+
default:
327+
let learningRate = LearningRate.clear
328+
329+
tracker.update(SkillExp(name: name, mindState: learningRate, ranks: 0, isNew: false), trackLearned: displayLearnedWithPrompt)
330+
331+
host?.set(variable: "\(name).Ranks", value: "0.0")
332+
host?.set(variable: "\(name).LearningRate", value: "\(learningRate.rawValue)")
333+
host?.set(variable: "\(name).LearningRateName", value: "\(learningRate.description)")
334+
}
290335

291336
updateWindow = true
292337
}
@@ -313,17 +358,55 @@ class ExpPlugin: OPlugin {
313358

314359
updateWindow = true
315360
} else {
316-
// handle empty tag
361+
// handle additional tags
317362
let regex = RegexFactory.get("id='exp\\s([\\w\\s]+)'")
318363
if let match = regex?.firstMatch(&copy) {
319364
let name = match.valueAt(index: 1)?.replacingOccurrences(of: " ", with: "_") ?? ""
320-
let learningRate = LearningRate.clear
321-
322-
tracker.update(SkillExp(name: name, mindState: learningRate, ranks: 0, isNew: false), trackLearned: displayLearnedWithPrompt)
323-
324-
host?.set(variable: "\(name).Ranks", value: "0.0")
325-
host?.set(variable: "\(name).LearningRate", value: "\(learningRate.rawValue)")
326-
host?.set(variable: "\(name).LearningRateName", value: "\(learningRate.description)")
365+
366+
switch name {
367+
case "favor":
368+
let valReg = RegexFactory.get(".+>\\s*(.+)<.*")
369+
if let match = valReg?.firstMatch(&copy) {
370+
let txt = match.valueAt(index: 1) ?? ""
371+
let value = Int(txt.replacingOccurrences(of: "Favors:", with: "").trimLeadingWhitespace()) ?? 0
372+
host?.set(variable: name, value: "\(value)")
373+
}
374+
break
375+
case "rexp":
376+
let valReg = RegexFactory.get(".+>\\s*(.+)<.*")
377+
if let match = valReg?.firstMatch(&copy) {
378+
let txt = match.valueAt(index: 1) ?? ""
379+
host?.set(variable: name, value: txt)
380+
} else {
381+
host?.set(variable: name, value: "")
382+
}
383+
break
384+
case "sleep":
385+
let valReg = RegexFactory.get(".+>\\s*(.+)<.*")
386+
if let match = valReg?.firstMatch(&copy) {
387+
let txt = (match.valueAt(index: 1) ?? "").replacingOccurrences(of: "</b>", with: "")
388+
host?.set(variable: name, value: txt)
389+
} else {
390+
host?.set(variable: name, value: "")
391+
}
392+
break
393+
case "tdp":
394+
let valReg = RegexFactory.get(".+>\\s*(.+)<.*")
395+
if let match = valReg?.firstMatch(&copy) {
396+
let txt = match.valueAt(index: 1) ?? ""
397+
let value = Int(txt.replacingOccurrences(of: "TDPs:", with: "").trimLeadingWhitespace()) ?? 0
398+
host?.set(variable: name, value: "\(value)")
399+
}
400+
break
401+
default:
402+
let learningRate = LearningRate.clear
403+
404+
tracker.update(SkillExp(name: name, mindState: learningRate, ranks: 0, isNew: false), trackLearned: displayLearnedWithPrompt)
405+
406+
host?.set(variable: "\(name).Ranks", value: "0.0")
407+
host?.set(variable: "\(name).LearningRate", value: "\(learningRate.rawValue)")
408+
host?.set(variable: "\(name).LearningRateName", value: "\(learningRate.description)")
409+
}
327410

328411
updateWindow = true
329412
}
@@ -333,8 +416,12 @@ class ExpPlugin: OPlugin {
333416
private func updateExpWindow() {
334417
let foreColor = host?.get(preset: "exptracker:text") ?? ""
335418
let learnedColor = host?.get(preset: "exptracker:learned") ?? ""
419+
let rexp = host?.get(variable: "rexp") ?? ""
420+
let favor = host?.get(variable: "favor") ?? ""
421+
let sleep = host?.get(variable: "sleep") ?? ""
422+
let tdps = host?.get(variable: "tdp") ?? ""
336423

337-
let commands = tracker.buildDisplayCommands(foreColor: foreColor, learnedColor: learnedColor)
424+
let commands = tracker.buildDisplayCommands(foreColor: foreColor, learnedColor: learnedColor, favors: favor, rexp: rexp, sleep: sleep, tdps: tdps)
338425
for cmd in commands {
339426
host?.send(text: cmd)
340427
}

app/src/Outlander/Experience/ExpTracker.swift

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ class ExpTracker {
9898

9999
var skillSets: [String]
100100

101-
var tdps = 0
102-
103101
static var dateFormatter = DateFormatter()
104102

105103
enum OrderBy: CustomStringConvertible {
@@ -235,7 +233,7 @@ class ExpTracker {
235233
}
236234
}
237235

238-
func buildDisplayCommands(foreColor: String, learnedColor: String) -> [String] {
236+
func buildDisplayCommands(foreColor: String, learnedColor: String, favors: String, rexp: String, sleep: String, tdps: String) -> [String] {
239237
var tags: [String] = []
240238

241239
for skill in skillsWithMindstate() {
@@ -249,7 +247,17 @@ class ExpTracker {
249247
}
250248

251249
let diff = Date().timeIntervalSince(startOfTracking!)
250+
if !sleep.isEmpty {
251+
tags.append("\(foreColor) \n\(sleep)")
252+
}
253+
252254
tags.append("\(foreColor) \nTDPs: \(tdps)")
255+
tags.append("\(foreColor) Favors: \(favors)")
256+
257+
if !rexp.isEmpty {
258+
tags.append("\(foreColor) \(rexp)")
259+
}
260+
253261
tags.append("\(foreColor) Tracking for: \(diff.formatted)")
254262
tags.append("\(foreColor) Last updated: \(ExpTracker.dateFormatter.string(from: Date()))")
255263

@@ -258,7 +266,7 @@ class ExpTracker {
258266
} + ["#echo >experience @resume@"]
259267
}
260268

261-
func buildReport(sorting: OrderBy, foreColor: String, learnedColor: String) -> [String] {
269+
func buildReport(sorting: OrderBy, foreColor: String, learnedColor: String, favors: String, rexp: String, sleep: String, tdps: String) -> [String] {
262270
var tags: [String] = ["\(foreColor) \nExperience Tracker", "\(foreColor) Showing all skills with field experience or earned ranks.\n"]
263271

264272
for skill in skillsWithMindstateOrGain(sorting: sorting) {
@@ -272,7 +280,18 @@ class ExpTracker {
272280
}
273281

274282
let diff = Date().timeIntervalSince(startOfTracking!)
283+
284+
if !sleep.isEmpty {
285+
tags.append("\(foreColor) \n\(sleep)")
286+
}
287+
275288
tags.append("\(foreColor) \nTDPs: \(tdps)")
289+
tags.append("\(foreColor) Favors: \(favors)")
290+
291+
if !rexp.isEmpty {
292+
tags.append("\(foreColor) \(rexp)")
293+
}
294+
276295
tags.append("\(foreColor) Tracking for: \(diff.formatted)")
277296
tags.append("\(foreColor) Last updated: \(ExpTracker.dateFormatter.string(from: Date()))\n")
278297

app/src/Outlander/Handlers/CommandProcessor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class CommandProcesssor {
6363
handlers.append(MacroCommandHandler(files))
6464
handlers.append(LayoutCommandHandler(files))
6565
// for local testing only
66-
// handlers.append(EmulateTextCommandHandler(files))
66+
handlers.append(EmulateTextCommandHandler(files))
6767

6868
self.pluginManager = pluginManager
6969
}

app/src/Outlander/UI/OWindow.swift

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ class OWindow: NSWindow {
7676
return
7777
}
7878

79-
guard let titlebarContainer = self.standardWindowButton(.closeButton)?.superview else {
80-
return
81-
}
82-
8379
let titleView = findViewInSubview(contentSuperView.subviews, ignoreView: windowContentView, test: { view in
8480
view is NSTextField
8581
})
@@ -98,6 +94,28 @@ class OWindow: NSWindow {
9894

9995
titleText.attributedStringValue = NSAttributedString(string: title, attributes: attributes)
10096
titleText.sizeToFit()
97+
adjustTitlebar()
98+
}
99+
100+
func adjustTitlebar() {
101+
guard let windowContentView = contentView else {
102+
return
103+
}
104+
guard let contentSuperView = windowContentView.superview else {
105+
return
106+
}
107+
108+
guard let titlebarContainer = self.standardWindowButton(.closeButton)?.superview else {
109+
return
110+
}
111+
112+
let titleView = findViewInSubview(contentSuperView.subviews, ignoreView: windowContentView, test: { view in
113+
view is NSTextField
114+
})
115+
116+
guard let titleText = titleView as? NSTextField else {
117+
return
118+
}
101119

102120
// center
103121
// titleText.frame.origin.x = (titlebarContainer.bounds.width - titleText.frame.width) / 2
@@ -121,4 +139,22 @@ class OWindow: NSWindow {
121139
}
122140
return nil
123141
}
142+
143+
override func setFrame(_ frame: NSRect, display: Bool) {
144+
super.setFrame(frame, display: display)
145+
146+
adjustTitlebar()
147+
}
148+
149+
override func setFrame(_ frame: NSRect, display: Bool, animate: Bool) {
150+
super.setFrame(frame, display: display, animate: false)
151+
152+
adjustTitlebar()
153+
}
154+
155+
override func setFrameOrigin(_ newOrigin: NSPoint) {
156+
super.setFrameOrigin(newOrigin)
157+
158+
adjustTitlebar()
159+
}
124160
}

app/src/OutlanderTests/Experience/ExpPluginTests.swift

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,64 @@ class ExpPluginTests: XCTestCase {
201201
XCTAssertEqual(host.variables["Scholarship.LearningRate"], "3")
202202
XCTAssertEqual(host.variables["Scholarship.LearningRateName"], "learning")
203203
}
204+
205+
func test_rexp_parse() {
206+
let host = TestHost()
207+
let plugin = ExpPlugin()
208+
plugin.initialize(host: host)
209+
210+
_ = plugin.parse(xml: "<component id='exp rexp'>Rested EXP Stored: 5:59 hours Usable This Cycle: 5:53 hours Cycle Refreshes: 22:32 hours</component>")
211+
212+
XCTAssertEqual(host.variables["rexp"], "Rested EXP Stored: 5:59 hours Usable This Cycle: 5:53 hours Cycle Refreshes: 22:32 hours")
213+
}
214+
215+
func test_rexp_empty_parse() {
216+
let host = TestHost()
217+
let plugin = ExpPlugin()
218+
plugin.initialize(host: host)
219+
220+
_ = plugin.parse(xml: "<component id='exp rexp'></component>")
221+
222+
XCTAssertEqual(host.variables["rexp"], "")
223+
}
224+
225+
func test_sleep_parse() {
226+
let host = TestHost()
227+
let plugin = ExpPlugin()
228+
plugin.initialize(host: host)
229+
230+
_ = plugin.parse(xml: "<component id='exp sleep'><b>You are relaxed and your mind has entered a state of rest. To wake up and start learning again, type: AWAKEN</b></component>")
231+
232+
XCTAssertEqual(host.variables["sleep"], "You are relaxed and your mind has entered a state of rest. To wake up and start learning again, type: AWAKEN")
233+
}
234+
235+
func test_sleep_empty_parse() {
236+
let host = TestHost()
237+
let plugin = ExpPlugin()
238+
plugin.initialize(host: host)
239+
240+
_ = plugin.parse(xml: "<component id='exp sleep'></component>")
241+
242+
XCTAssertEqual(host.variables["sleep"], "")
243+
}
244+
245+
func test_tdp_parse() {
246+
let host = TestHost()
247+
let plugin = ExpPlugin()
248+
plugin.initialize(host: host)
249+
250+
_ = plugin.parse(xml: "<component id='exp tdp'> TDPs: 926</component>")
251+
252+
XCTAssertEqual(host.variables["tdp"], "926")
253+
}
254+
255+
func test_favor_parse() {
256+
let host = TestHost()
257+
let plugin = ExpPlugin()
258+
plugin.initialize(host: host)
259+
260+
_ = plugin.parse(xml: "<component id='exp favor'> Favors: 12</component>")
261+
262+
XCTAssertEqual(host.variables["favor"], "12")
263+
}
204264
}

app/src/OutlanderTests/GameStreamTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class GameStreamTests: XCTestCase {
271271
}
272272
}
273273

274-
func testCombinesThoughtStream() {
274+
func test_combines_concise_thoughts_stream() {
275275
let commands = streamCommands([
276276
"<pushStream id=\"thoughts\"/><preset id='thought'>[General][Someone] </preset>\"something to say\"\n",
277277
"<popStream/><prompt time=\"1638240815\">R&gt;</prompt>"

0 commit comments

Comments
 (0)