-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
2,797 additions
and
107 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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,77 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Ink.Runtime | ||
{ | ||
internal class ListDefinition | ||
{ | ||
public string name { get { return _name; } } | ||
|
||
public Dictionary<RawListItem, int> items { | ||
get { | ||
if (_items == null) { | ||
_items = new Dictionary<RawListItem, int> (); | ||
foreach (var itemNameAndValue in _itemNameToValues) { | ||
var item = new RawListItem (name, itemNameAndValue.Key); | ||
_items [item] = itemNameAndValue.Value; | ||
} | ||
} | ||
return _items; | ||
} | ||
} | ||
Dictionary<RawListItem, int> _items; | ||
|
||
public int ValueForItem (RawListItem item) | ||
{ | ||
int intVal; | ||
if (_itemNameToValues.TryGetValue (item.itemName, out intVal)) | ||
return intVal; | ||
else | ||
return 0; | ||
} | ||
|
||
public bool ContainsItem (RawListItem item) | ||
{ | ||
if (item.originName != name) return false; | ||
|
||
return _itemNameToValues.ContainsKey (item.itemName); | ||
} | ||
|
||
public bool TryGetItemWithValue (int val, out RawListItem item) | ||
{ | ||
foreach (var namedItem in _itemNameToValues) { | ||
if (namedItem.Value == val) { | ||
item = new RawListItem (name, namedItem.Key); | ||
return true; | ||
} | ||
} | ||
|
||
item = RawListItem.Null; | ||
return false; | ||
} | ||
|
||
public ListValue ListRange (int min, int max) | ||
{ | ||
var rawList = new RawList (); | ||
foreach (var nameAndValue in _itemNameToValues) { | ||
if (nameAndValue.Value >= min && nameAndValue.Value <= max) { | ||
var item = new RawListItem (name, nameAndValue.Key); | ||
rawList [item] = nameAndValue.Value; | ||
} | ||
} | ||
return new ListValue(rawList); | ||
} | ||
|
||
public ListDefinition (string name, Dictionary<string, int> items) | ||
{ | ||
_name = name; | ||
_itemNameToValues = items; | ||
} | ||
|
||
string _name; | ||
|
||
// The main representation should be simple item names rather than a RawListItem, | ||
// since we mainly want to access items based on their simple name, since that's | ||
// how they'll be most commonly requested from ink. | ||
Dictionary<string, int> _itemNameToValues; | ||
} | ||
} |
This file contains 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,62 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Ink.Runtime | ||
{ | ||
internal class ListDefinitionsOrigin | ||
{ | ||
public List<Runtime.ListDefinition> lists { | ||
get { | ||
var listOfLists = new List<Runtime.ListDefinition> (); | ||
foreach (var namedList in _lists) { | ||
listOfLists.Add (namedList.Value); | ||
} | ||
return listOfLists; | ||
} | ||
} | ||
|
||
public ListDefinitionsOrigin (List<Runtime.ListDefinition> lists) | ||
{ | ||
_lists = new Dictionary<string, ListDefinition> (); | ||
foreach (var list in lists) { | ||
_lists [list.name] = list; | ||
} | ||
} | ||
|
||
public bool TryGetDefinition (string name, out ListDefinition def) | ||
{ | ||
return _lists.TryGetValue (name, out def); | ||
} | ||
|
||
public ListValue FindSingleItemListWithName (string name) | ||
{ | ||
RawListItem item = RawListItem.Null; | ||
ListDefinition list = null; | ||
|
||
// Name could be in the form itemName or listName.itemName | ||
var nameParts = name.Split ('.'); | ||
if (nameParts.Length == 2) { | ||
item = new RawListItem (nameParts [0], nameParts [1]); | ||
TryGetDefinition (item.originName, out list); | ||
} else { | ||
foreach (var namedList in _lists) { | ||
var listWithItem = namedList.Value; | ||
item = new RawListItem (namedList.Key, name); | ||
if (listWithItem.ContainsItem (item)) { | ||
list = listWithItem; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// Manager to get the list that contains the given item? | ||
if (list != null) { | ||
int itemValue = list.ValueForItem (item); | ||
return new ListValue (item, itemValue); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
Dictionary<string, Runtime.ListDefinition> _lists; | ||
} | ||
} |
Oops, something went wrong.