301 Days

A year of gamedev experiments.

Day 27 - Miscellany

| Comments

Misc.


Line numbers

Until recently, the line numbers on all of the code snippets started with one, which is annoying if you’re trying to match it up with the linked file in GitLab. So I took a few minutes to fix it in a way that’s retroactive to the beginning of the blog.

When I first started with Octopress it appeared I could do what I wanted with a start tag, but it doesn’t work and I guess it’s not going to be fixed. I stopped trying to use the tag, but luckily the line being referred to is embedded in the URL (for either GitLab or GitHub, and maybe others).

plugins/code_block.rblink
63
64
65
66
67
68
69
  if markup =~ CaptionUrlTitle
    @file = $1
    code_url = $2
    @caption = "<figcaption><span>#{$1}</span><a href='#{$2}'>#{$3 || 'link'}</a></figcaption>"
    if code_url =~ /\S+#L(\d+)/
      @starting_line = $1.to_i
    end
plugins/code_block.rblink
85
86
87
  if @filetype
    source += "#{HighlightCode::highlight(code, @filetype, @starting_line)}</figure>"
  else
plugins/pygments_code.rblink
9
10
11
12
13
14
15
16
  def self.highlight(str, lang, starting_line = 1)
    lang = 'ruby' if lang == 'ru'
    lang = 'objc' if lang == 'm'
    lang = 'perl' if lang == 'pl'
    lang = 'yaml' if lang == 'yml'
    str = pygments(str, lang).match(/<pre>(.+)<\/pre>/m)[1].to_s.gsub(/ *$/, '') #strip out divs <div class="highlight">
    tableize_code(str, lang, starting_line)
  end
plugins/pygments_code.rblink
36
37
38
39
40
41
42
  def self.tableize_code (str, lang = '', starting_line = 1)
    table = '<div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers">'
    code = ''
    str.lines.each_with_index do |line,index|
      table += "<span class='line-number'>#{index+starting_line}</span>\n"
      code  += "<span class='line'>#{line}</span>"
    end

It’s a little hacky, but it works for me for now.


Recovering from SQL hiccoughs

Occasionally getting stuff like this in the console logs:

SQL Server does not exist or access denied.

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 64)

at System.Data.SqlClient.SqlConnection.Open () [0x00000] in :0

at (wrapper remoting-invoke-with-check) System.Data.SqlClient.SqlConnection:Open ()

at DragonsSpine.DAL.DataAccess.GetSQLConnection () [0x00014] in K:\301days\Code\ste-reez-muvi\Assets\DragonsSpine\DAL\DataAccess.cs:29

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 64)

And, with the way it’s currently written, the system in question (either cells or NPCs) will never update again.

Let’s keep the exceptions from ending the update so messily with a try-catch block:

Assets/Managers/MapManager.cslink
292
293
294
295
296
297
298
int result;
try {
    result = DragonsSpine.DAL.DBWorld.UpdateCellDict(param, 0);
} catch (Exception e) {
    Utils.Log("Exception updating Cells:" + e.Message, Utils.LogType.Exception);
    result = 0;
}
Assets/Managers/NpcManager.cslink
103
104
105
106
107
108
109
List<NPCLite> result = new List<NPCLite>(500);
try {
    result = DragonsSpine.DAL.DBNPC.GetAllNpcs();
} catch (Exception e) {
    Utils.Log("Exception updating NPCs:" + e.Message, Utils.LogType.Exception);
    result = null;
}

Also a little hacky, but also works for now.


Misc misc

  • Made the changed cell effect a little more subtle (0.9 scale returning to 1.0 over the course of a second).
  • Added materials for various burnt tree display strings (after experimenting with spawning fire breathing critters on the surface).
  • Removed counting of open doors.
  • NPCs recover from being presumed dead temporarily.

Day 27 code - octopress Day 27 code - visualizer

Comments