Skip to content

Commit

Permalink
Golint
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Jun 2, 2021
1 parent ca28c42 commit 3d68163
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
16 changes: 7 additions & 9 deletions parser/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ import (
"github.com/fatih/color"
)

type Logger struct{}
// func (g RenpyGraph) log(a ...interface{}) {
// if g.Options.FullDebug {
// fmt.Println(a...)
// }
// }

func (g RenpyGraph) Log(a ...interface{}) {
if g.Options.FullDebug {
fmt.Println(a...)
}
}

func (g RenpyGraph) LogLineContext(line string, context, oldContext Context) {
func (g RenpyGraph) logLineContext(line string, context, oldContext Context) {
if g.Options.FullDebug {
fmt.Println(line)
if context.Diff(oldContext) {
if context.diff(oldContext) {
color.Set(color.Bold)
fmt.Println("↳", context.String())
color.Unset()
Expand Down
2 changes: 1 addition & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Graph(text []string, options RenpyGraphOptions) RenpyGraph {
oldContext := context
context.update(line, detectors)

g.LogLineContext(line, context, oldContext)
g.logLineContext(line, context, oldContext)

switch context.currentSituation {

Expand Down
25 changes: 13 additions & 12 deletions parser/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func (c *Context) String() string {
return str
}

func (c *Context) Diff(d Context) bool {
// diff is used mainly by the logger
func (c *Context) diff(d Context) bool {
return c.detectImplicitJump != d.detectImplicitJump ||
!reflect.DeepEqual(c.labelStack, d.labelStack) ||
c.currentSituation != d.currentSituation ||
Expand All @@ -70,28 +71,28 @@ func (c *Context) Diff(d Context) bool {
c.menuIndent != d.menuIndent
}

func (context *Context) cleanContextAccordingToIndent(line string) {
func (c *Context) cleanContextAccordingToIndent(line string) {
// After a menu (indentation before menu indentation) CANNOT NOT STACK for the moment
if -1 < context.indent && context.indent <= context.menuIndent {
context.menuIndent = 0
context.lastChoice = ""
if -1 < c.indent && c.indent <= c.menuIndent {
c.menuIndent = 0
c.lastChoice = ""
}

if len(strings.TrimLeft(line, " ")) >= 4 && strings.TrimLeft(line, " ")[:4] != "menu" { // exception...
// Updates label stack
if context.indent >= 0 {
for i, record := range context.labelStack {
if context.indent <= record.indent {
context.lastLabel = context.labelStack[i].labelName
context.labelStack = context.labelStack[:i]
if c.indent >= 0 {
for i, record := range c.labelStack {
if c.indent <= record.indent {
c.lastLabel = c.labelStack[i].labelName
c.labelStack = c.labelStack[:i]
break
}
}
}
}

// Updates screen situation
if context.indent == 0 {
context.currentScreen = ""
if c.indent == 0 {
c.currentScreen = ""
}
}

0 comments on commit 3d68163

Please sign in to comment.